alielie
2025-10-13 e3868d4d61ded0e76fc8fe3fdacdd9e6d9113cf1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
        }
    }
}