using HMI.Util.Base; using ModBusTcp; using System; using System.Text; namespace ConsoleTest { class Program { static void Main(string[] args) { string msg; ModBusTcpController controller = new ModBusTcpController("127.0.0.1", 502); if (controller.Start(out msg)) { bool res; int? target; controller.WriteBool("1", true, out msg); controller.ReadDOBool("1", out res, out msg); Console.WriteLine(res); controller.ReadDOInt("1", out target, out msg); Console.WriteLine(target); controller.WriteInt("1", 1, out msg); controller.ReadDOInt("1", out target, out msg); Console.WriteLine(target); } controller.Close(); //AlarmUtil.GetProcessIdByName("TestPlatform"); /// 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; } } }