private void PrintControlWord(Socket s) { ControlWord cw = new ControlWord(); cw.Read(s); var bitArray19 = new BitArray(new bool[8] { cw.Bit00, cw.Bit01, cw.Bit02, cw.Bit03, cw.Bit04, cw.Bit05, cw.Bit06, cw.Bit07 }); var bitArray20 = new BitArray(new bool[8] { cw.Bit08, cw.Bit09, cw.Bit10, cw.Bit11, cw.Bit12, cw.Bit13, cw.Bit14, cw.Bit15 }); byte[] byte19 = new byte[1]; bitArray19.CopyTo(byte19, 0); byte[] byte20 = new byte[1]; bitArray20.CopyTo(byte20, 0); Debug.WriteLine(""); Debug.WriteLine("ControlWord"); Debug.WriteLine($"Byte 19: {byte19[0]}"); Debug.WriteLine($"0: {cw.Bit00}, 1: {cw.Bit01}, 2: {cw.Bit02}, 3: {cw.Bit03}, 4: {cw.Bit04}, 5: {cw.Bit05}, 6: {cw.Bit06}, 7: {cw.Bit07}"); Debug.WriteLine($"Byte 20: {byte20[0]}"); Debug.WriteLine($"8: {cw.Bit08}, 9: {cw.Bit09}, 10: {cw.Bit10}, 11: {cw.Bit11}, 12: {cw.Bit12}, 13: {cw.Bit13}, 14: {cw.Bit14}, 15: {cw.Bit15}"); Debug.WriteLine(""); }
public ControlWord GetControlWord(string hostIp, int port) { Socket s = ModbusSocket.GetConnection(hostIp, port); ControlWord controlWord = new ControlWord(); controlWord.Read(s); return(controlWord); }