コード例 #1
0
		public void FillTestLocalhost()
		{
			int[] fields = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 };
			SolarChargerData data = new SolarChargerData(1)
			{
				Fields = fields
			};

			using (ModbusTcpAdapter adapter = new ModbusTcpAdapter())
			{
				string returnValue = adapter.Connect("localhost", 502);
				Assert.IsTrue(string.IsNullOrEmpty(returnValue), "returnValue");

				int count = adapter.Write(data);
				Assert.AreEqual(0, count, "count");

				count = adapter.Fill(data);
				Assert.AreEqual(0, count, "count");
			}
			Assert.IsNotNull(data.Fields, "data.Fields");
			Assert.AreEqual(data.Quantity, data.Fields.Length, "data.Fields.Length");

			for (int i = 0; i < fields.Length; i++)
			{
				Assert.AreEqual(fields[i], data.Fields[i], "data.Fields[" + i + "]");
			}
		}
コード例 #2
0
		public void FillTestVenus()
		{
			SolarChargerData data = new SolarChargerData(239);

			using (ModbusTcpAdapter adapter = new ModbusTcpAdapter())
			{
				string returnValue = adapter.Connect("venus", 502);
				Assert.IsTrue(string.IsNullOrEmpty(returnValue), "returnValue");

				int count = adapter.Fill(data);
				Assert.AreEqual(0, count, "count");
			}
			Assert.IsNotNull(data.Fields, "data.Fields");
			Assert.AreEqual(data.Quantity, data.Fields.Length, "data.Fields.Length");
		}
コード例 #3
0
		public void ChargerOnOffTestVenus()
		{
			Console.WriteLine("Console-ChargerOnOffTestVenus");
			Trace.WriteLine("Trace-ChargerOnOffTestVenus");

			SolarChargerData scData = new SolarChargerData(239);
			ChargerOnOffData coData = new ChargerOnOffData(239);

			using (ModbusTcpAdapter adapter = new ModbusTcpAdapter())
			{
				string returnValue = adapter.Connect("venus", 502);
				Assert.IsTrue(string.IsNullOrEmpty(returnValue), "returnValue");

				int count = adapter.Fill(scData);
				Assert.AreEqual(0, count, "count-1");
				Trace.Write("PV: " + scData.PvVoltage + "V, " + scData.PvCurrent + "A, " + scData.PvPower + "W - ");
				Trace.WriteLine("Charger: " + scData.ChargerOnOff + ", " + scData.ChargeState + ", " + scData.MppOperationMode);

				coData.Fields = new int[1];
				coData.ChargerOnOff = ChargerOnOffCode.Off;  // Off
				count = adapter.Write(coData);
				Assert.AreEqual(0, count, "count-2");

				Thread.Sleep(1000);
				Trace.WriteLine("***");

				count = adapter.Fill(scData);
				Assert.AreEqual(0, count, "count-3");
				Trace.Write("PV: " + scData.PvVoltage + "V, " + scData.PvCurrent + "A, " + scData.PvPower + "W - ");
				Trace.WriteLine("Charger: " + scData.ChargerOnOff + ", " + scData.ChargeState + ", " + scData.MppOperationMode);

				Thread.Sleep(1000);
				Trace.WriteLine("***");

				count = adapter.Fill(scData);
				Assert.AreEqual(0, count, "count-4");
				Trace.Write("PV: " + scData.PvVoltage + "V, " + scData.PvCurrent + "A, " + scData.PvPower + "W - ");
				Trace.WriteLine("Charger: " + scData.ChargerOnOff + ", " + scData.ChargeState + ", " + scData.MppOperationMode);

				coData.ChargerOnOff = ChargerOnOffCode.On;  // On
				count = adapter.Write(coData);
				Assert.AreEqual(0, count, "count-5");

				Thread.Sleep(1000);
				Trace.WriteLine("***");

				count = adapter.Fill(scData);
				Assert.AreEqual(0, count, "count-6");
				Trace.Write("PV: " + scData.PvVoltage + "V, " + scData.PvCurrent + "A, " + scData.PvPower + "W - ");
				Trace.WriteLine("Charger: " + scData.ChargerOnOff + ", " + scData.ChargeState + ", " + scData.MppOperationMode);

				Thread.Sleep(1000);
				Trace.WriteLine("***");

				count = adapter.Fill(scData);
				Assert.AreEqual(0, count, "count-7");
				Trace.Write("PV: " + scData.PvVoltage + "V, " + scData.PvCurrent + "A, " + scData.PvPower + "W - ");
				Trace.WriteLine("Charger: " + scData.ChargerOnOff + ", " + scData.ChargeState + ", " + scData.MppOperationMode);

				Thread.Sleep(1000);
				Trace.WriteLine("***");

				count = adapter.Fill(scData);
				Assert.AreEqual(0, count, "count-8");
				Trace.Write("PV: " + scData.PvVoltage + "V, " + scData.PvCurrent + "A, " + scData.PvPower + "W - ");
				Trace.WriteLine("Charger: " + scData.ChargerOnOff + ", " + scData.ChargeState + ", " + scData.MppOperationMode);
			}
		}
コード例 #4
0
        private void Timer2_Tick()
        {
            SolarChargerData scData = new SolarChargerData(239);
            ChargerOnOffData coData = new ChargerOnOffData(239);

            using (ModbusTcpAdapter adapter = new ModbusTcpAdapter())
            {
                string returnValue = adapter.Connect(Settings.Default.ModbusIpAddress, 502);
                if (!string.IsNullOrEmpty(returnValue))
                {
                    this.timer2.Stop();
                    Logging.Log("FormMonitor.Timer2_Tick-Error", returnValue);
                    this.step = 0;
                    return;
                }

                int    count   = adapter.Fill(scData);
                string message = null;
                message += "step: " + this.step + ", count: " + count + ", dailyInit: " + this.dailyInit + " - ";
                message += "PV: " + scData.PvVoltage + "V, " + scData.PvCurrent + "A, " + scData.PvPower + "W - ";
                message += "Charger: " + scData.ChargerOnOff + ", " + scData.ChargeState + ", " + scData.MppOperationMode;
                Trace.WriteLine(message);
                Logging.Log("FormMonitor.Timer2_Tick-Fill", message);

                // 1. Charger is On and working
                if (this.step == 1 && scData.ChargerOnOff == ChargerOnOffCode.On)
                {
                    if (scData.ChargeState != ChargeStateCode.Off && (scData.PvCurrent < 0.1 || scData.PvPower < 0.1 || this.dailyInit))
                    {
                        this.dailyInit = false;

                        // Switch Off
                        coData.ChargerOnOff = ChargerOnOffCode.Off;
                        count = adapter.Write(coData);
                        Logging.Log("FormMonitor.Timer2_Tick-Write", "Switch Off: " + count);
                        this.step = 2;
                    }
                    else
                    {
                        // stop timer 2
                        this.timer2.Stop();
                        Logging.Log("FormMonitor.Timer2_Tick", "Stop1");
                        this.step = 0;
                    }
                }

                // 2. Charger is Off /* and not working */
                if (this.step != 3 && scData.ChargerOnOff == ChargerOnOffCode.Off /* && scData.ChargeState == ChargeStateCode.Off */)
                {
                    // Switch On
                    coData.ChargerOnOff = ChargerOnOffCode.On;
                    count = adapter.Write(coData);
                    Logging.Log("FormMonitor.Timer2_Tick-Write", "Switch On: " + count);
                    this.step = 3;
                }

                // 3. Charger is On. working isn't necessary
                if (this.step == 3 && scData.ChargerOnOff == ChargerOnOffCode.On)
                {
                    // stop timer 2
                    this.timer2.Stop();
                    Logging.Log("FormMonitor.Timer2_Tick", "Stop2");
                    this.step = 0;
                }
            }
        }