领胜LDS 键盘AOI检测项目
xcd
2020-06-24 d6c577e17ee7bb5331dd51d803f9b42441b0f0e5
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Bro.Device.DAMModule
{
    public static class CModbusDll
    {
        public static byte[] WriteDO(int addr, int io, bool openclose)
        {
            byte[] src = new byte[8];
            src[0] = (byte)addr;
            src[1] = 0x05;
            src[2] = 0x00;
            src[3] = (byte)io;
            src[4] = (byte)((openclose) ? 0xff : 0x00);
            src[5] = 0x00;
            ushort crc = CMBRTU.CalculateCrc(src, 6);
            src[6] = (byte)(crc & 0xff);
            src[7] = (byte)(crc >> 8);
            return src;
        }
        public static byte[] WriteAllDO(int addr, int ionum, bool openclose)
        {
            byte[] src = new byte[10 + (ionum - 1) / 8];
            int index = 0;
            src[index++] = (byte)addr;
            src[index++] = 0x0f;
            src[index++] = 0x00;
            src[index++] = 0x00;
            src[index++] = 0x00;
            src[index++] = (byte)ionum;
            src[index++] = (byte)((ionum + 7) / 8);
            src[index++] = (byte)((openclose) ? 0xff : 0x00);
            if (ionum > 8) src[index++] = (byte)((openclose) ? 0xff : 0x00);
            if (ionum > 16) src[index++] = (byte)((openclose) ? 0xff : 0x00);
            if (ionum > 24) src[index++] = (byte)((openclose) ? 0xff : 0x00);
            ushort crc = CMBRTU.CalculateCrc(src, index);
            src[index++] = (byte)(crc & 0xff);
            src[index++] = (byte)(crc >> 8);
            return src;
        }
 
        public static byte[] ReadDO(int addr, int donum)
        {
            byte[] src = new byte[8];
            src[0] = (byte)addr;
            src[1] = 0x01;
            src[2] = 0x00;
            src[3] = 0x00;
            src[4] = 0x00;
            src[5] = (byte)donum;
            ushort crc = CMBRTU.CalculateCrc(src, 6);
            src[6] = (byte)(crc & 0xff);
            src[7] = (byte)(crc >> 8);
            return src;
        }
 
        public static byte[] ReadDI(int addr, int dinum)
        {
            byte[] src = new byte[8];
            src[0] = (byte)addr;
            src[1] = 0x02;
            src[2] = 0x00;
            src[3] = 0x00;
            src[4] = 0x00;
            src[5] = (byte)dinum;
            ushort crc = CMBRTU.CalculateCrc(src, 6);
            src[6] = (byte)(crc & 0xff);
            src[7] = (byte)(crc >> 8);
            return src;
        }
 
        public static byte[] ReadAIInfo(int addr, int regstart, int regnum)
        {
            byte[] src = new byte[8];
            src[0] = (byte)addr;
            src[1] = 0x04;
            src[2] = (byte)(regstart >> 8);
            src[3] = (byte)(regstart & 0xff);
            src[4] = (byte)(regnum >> 8);
            src[5] = (byte)(regnum & 0xff);
            ushort crc = CMBRTU.CalculateCrc(src, 6);
            src[6] = (byte)(crc & 0xff);
            src[7] = (byte)(crc >> 8);
            return src;
        }
    }
}