protected virtual void stopwatch_Elapsed(object sender, ElapsedEventArgs e) { stopwatch.Stop(); if (DataIn != null) { SerialMessage sm = new SerialMessage(dataReceive, dataLengthReceive); DataIn(this, sm); dataLengthReceive = 0; } //throw new NotImplementedException(); }
static void serialManage_DataIn(object sender, SerialMessage e) { if (e.Data[0] == '>' && e.Length != 0) { #region Comment //dataValue.Volt = (ushort)(e.Data[1] << 8); //dataValue.Volt |= (ushort)e.Data[2]; //Console.WriteLine("\tVolt : {0} mV", dataValue.Volt.ToString()); //dataValue.Amp = (uint)e.Data[4] << 8; //dataValue.Amp |= (uint)e.Data[5]; //Console.WriteLine("\tAmp : {0} mA", dataValue.Amp.ToString()); //dataValue.Power = (uint)e.Data[7] << 24; //dataValue.Power |= (uint)e.Data[8] << 16; //dataValue.Power |= (uint)e.Data[9] << 8; //dataValue.Power |= (uint)e.Data[10]; //Console.WriteLine("\tPower : {0} W", dataValue.Power.ToString()); //dataValue.Energy = (uint)e.Data[12] << 24; //dataValue.Energy |= (uint)e.Data[13] << 16; //dataValue.Energy |= (uint)e.Data[14] << 8; //dataValue.Energy |= (uint)e.Data[15]; //Console.WriteLine("\tEnergy : {0} Wh", dataValue.Energy.ToString()); //dataValue.PF = (uint)e.Data[17]; //Console.WriteLine("\tPower Factor : 0.{0} ", dataValue.PF.ToString()); //dataValue.Fequency = (uint)e.Data[19] << 8; //dataValue.Fequency |= (uint)e.Data[20]; //Console.WriteLine("\tFrequency : {0} Hz", (dataValue.Fequency / 10).ToString()); #endregion dataValue.LightLV = (uint)e.Data[1] << 24; dataValue.LightLV |= (uint)e.Data[2] << 16; dataValue.LightLV |= (uint)e.Data[3] << 8; dataValue.LightLV |= (uint)e.Data[4]; //Console.WriteLine("\tLight Level : {0} ", dataValue.LightLV.ToString()); dataValue.LightStatus = (uint)e.Data[6]; dataValue.LightID = (dataValue.LightLV & 0xFFF0) >> 4; } //throw new NotImplementedException(); }
static void modbusSerial_DataIn(object sender, SerialMessage e) { Console.WriteLine("\n Data Incomming :" + ByteToHex(e.Data, 0, e.Length)); if (isWrite) { isWrite = false; } else { modbus.ReadValue(e.Data); if (modbus.LastRead == ReadInputRegister_typedef.VOLT) { dataValue.Volt = (ushort)modbus.Volt; Console.WriteLine("\n V : {0} V", (modbus.Volt * 0.01).ToString()); mpkg = modbus.GenPkg(MOBUSFnCode_typedef.ReadInputRegister, (ushort)ReadInputRegister_typedef.AMP, 2); modbusSerial.Write(mpkg, 0, 8); Console.WriteLine("\n Mode Bus Sending : " + ByteToHex(mpkg, 0, 8)); } else if (modbus.LastRead == ReadInputRegister_typedef.AMP) { dataValue.Amp = (uint)modbus.Amp; Console.WriteLine("\n I : {0} A", (modbus.Amp * 0.001).ToString()); mpkg = modbus.GenPkg(MOBUSFnCode_typedef.ReadInputRegister, (ushort)ReadInputRegister_typedef.POWER, 2); modbusSerial.Write(mpkg, 0, 8); Console.WriteLine("\n Mode Bus Sending : " + ByteToHex(mpkg, 0, 8)); } else if (modbus.LastRead == ReadInputRegister_typedef.POWER) { dataValue.Power = (uint)modbus.Power; Console.WriteLine("\n Power : {0} W", modbus.Power.ToString()); mpkg = modbus.GenPkg(MOBUSFnCode_typedef.ReadInputRegister, (ushort)ReadInputRegister_typedef.POWER_FACTOR, 2); modbusSerial.Write(mpkg, 0, 8); Console.WriteLine("\n Mode Bus Sending : " + ByteToHex(mpkg, 0, 8)); } else if (modbus.LastRead == ReadInputRegister_typedef.ENERGY) { dataValue.Energy = (uint)modbus.Energy; Console.WriteLine("\n Energy : {0} KWh", (modbus.Energy * 0.1).ToString()); modbus.LastRead = ReadInputRegister_typedef.STOP; Console.WriteLine("\n Meter Read Success"); ReadyPushData(); } else if (modbus.LastRead == ReadInputRegister_typedef.FREQUENCY) { dataValue.Fequency = (uint)modbus.Frequency; Console.WriteLine("\n Frequency : {0} Hz", (modbus.Frequency * 0.1).ToString()); mpkg = modbus.GenPkg(MOBUSFnCode_typedef.ReadInputRegister, (ushort)ReadInputRegister_typedef.ENERGY, 2); modbusSerial.Write(mpkg, 0, 8); Console.WriteLine("\n Mode Bus Sending : " + ByteToHex(mpkg, 0, 8)); } else if (modbus.LastRead == ReadInputRegister_typedef.POWER_FACTOR) { dataValue.PF = (uint)modbus.PowerFactor; Console.WriteLine("\n PowerFactor : {0}", (modbus.PowerFactor * 0.01).ToString()); mpkg = modbus.GenPkg(MOBUSFnCode_typedef.ReadInputRegister, (ushort)ReadInputRegister_typedef.FREQUENCY, 2); modbusSerial.Write(mpkg, 0, 8); Console.WriteLine("\n Mode Bus Sending : " + ByteToHex(mpkg, 0, 8)); } } //throw new NotImplementedException(); }