using DIOController; using System; using System.Text; namespace ConsoleTest { class Program { static void Main(string[] args) { /// ModbusTcp //IDIOController controller = DIOControllerCreator // .CreateController("C:\\Workspace\\VisualStudio\\WPFProject\\SimpleUtil\\DIOController\\bin\\Release\\modbus.ini"); //bool s; //controller.Start(out string msg); //controller.ReadDIBool("0", out bool res, out msg); //controller.ReadDOBool("0", out res, out msg); //controller.WriteBool("0", true, out msg); //s = controller.WriteBool("100", new bool[] { false, false }, out msg); //s = controller.ReadDOBool("100", 2, out bool[] ress, out msg); //controller.Dispose(); ///// 7432 //controller = controller = DIOControllerCreator // .CreateController("C:\\Workspace\\VisualStudio\\WPFProject\\SimpleUtil\\DIOController\\bin\\Release\\7432.ini"); //controller.Start(out msg); //controller.ReadDIBool("0", out res, out msg); //controller.ReadDOBool("0", out res, out msg); //controller.WriteBool("0", true, out msg); //controller.Dispose(); string recvstr = "62 FD 82 39 39 39 37 32 32 36 36 30 38 34 33 39 35 33 38 53 38 44 41 30 30 32 32"; string recvData; if (recvstr.Contains("FF")) { recvData = recvstr.Replace(" ", "").Substring(6); } else { byte[] bus = HexToByteArray(recvstr.Replace(" ", "").Substring(6)); recvData = Encoding.Default.GetString(bus); } } public static byte[] HexToByteArray(string hexString) { hexString = hexString.Replace(" ", ""); byte[] buffer = new byte[hexString.Length / 2]; for (int i = 0; i < buffer.Length; i++) { buffer[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16); } return buffer; } } }