private void InputData(byte[] datagram) { try { string hex; string datag; var drf = new ReceiveFrameFormat(datagram); if (drf.CRCValido) { if (BitConverter.IsLittleEndian) { Array.Reverse(drf.DataArea); } switch (setRegisterAddress) { case DDSRegisterAddress.TotalkWh: break; case DDSRegisterAddress.ExportkWh: _exportkWh = (double)BitConverter.ToInt32(drf.DataArea, 0) / 100; break; case DDSRegisterAddress.ImportkWh: _importkWh = (double)BitConverter.ToInt32(drf.DataArea, 0) / 100; break; case DDSRegisterAddress.Voltage: _voltage = (double)BitConverter.ToUInt16(drf.DataArea, 0) / 10; break; case DDSRegisterAddress.Current: _current = (double)BitConverter.ToUInt16(drf.DataArea, 0) / 100; break; case DDSRegisterAddress.ActivePower: _activePower = BitConverter.ToInt16(drf.DataArea, 0); break; case DDSRegisterAddress.PowerFactor: break; case DDSRegisterAddress.Frequency: break; case DDSRegisterAddress.ID_BaudRate: break; default: break; } } } catch (Exception ex) { Console.WriteLine(ex); } _listoParaSolicitud = true; }
public static void TestConver(byte[] input) { var x = new ReceiveFrameFormat(input); if (BitConverter.IsLittleEndian) { Array.Reverse(input); } double ep = (double)BitConverter.ToInt32(input, 0) / 10; Console.WriteLine(ep); }
private void InputData(byte[] datagram) { try { _drf = new ReceiveFrameFormat(datagram); if (_muestraDatosConsola) { Console.WriteLine("ReceivedData"); datagram.ToList().ForEach(item => Console.Write(string.Format("{0:X} ", item))); Console.WriteLine(); } if (_drf.CRCValido) { if (BitConverter.IsLittleEndian) { Array.Reverse(_drf.DataArea); } switch (_registerAddress) { case DDSRegisterAddress.TotalkWh: break; case DDSRegisterAddress.ExportkWh: _exportkWh = (double)BitConverter.ToInt32(_drf.DataArea, 0) / 100; break; case DDSRegisterAddress.ImportkWh: _importkWh = (double)BitConverter.ToInt32(_drf.DataArea, 0) / 100; break; case DDSRegisterAddress.Voltage: _voltage = (double)BitConverter.ToUInt16(_drf.DataArea, 0) / 10; break; case DDSRegisterAddress.Current: _current = (double)BitConverter.ToUInt16(_drf.DataArea, 0) / 100; break; case DDSRegisterAddress.ActivePower: _activePower = BitConverter.ToInt16(_drf.DataArea, 0); break; case DDSRegisterAddress.PowerFactor: break; case DDSRegisterAddress.Frequency: break; case DDSRegisterAddress.ID_BaudRate: break; default: break; } _dataRecived = true; } } catch (Exception ex) { Console.WriteLine(ex); } }