本应用系统的测试成功,充分证明了在VB开发环境下基于RS485的4-20mA电流采集是可行的,上位机软件制作的界面使测量的操作简单,数据清晰,便于用户对工业自动化系统的数据进行实时的监控,满足行业对数据的需求。
1. 《VB语言程序设计》
2. 《C程序设计语言》
相关资源下载1、Visual Studio 2015下载地址:
https://www.visualstudio.com/downloads/download-visual-studio-vs
2、GM1008 简易手册:
https://files.cnblogs.com/files/xiaomagee/GM1008%E7%AE%80%E6%98%93%E6%89%8B%E5%86%8CV1.0.pdf
3、GM1008 用户手册:
https://files.cnblogs.com/files/xiaomagee/GM1008%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8CV1.0.pdf
4、GM1008 购买地址:
https://item.taobao.com/item.htm?spm=a1z10.3c.w4002251610686.9.zoJaPi&id=522203245449
附录1:CRC校验代码
121 \'CRC校验
122 Function crc(data() As Byte, length As Integer, ByRef ReturnDatalo As Byte, ByRef ReturnDatahi As Byte) As String
123 Dim CRC16Hi As Byte
124 Dim CRC16Lo As Byte
125 CRC16Hi = &HFF
126 CRC16Lo = &HFF
127 Dim i As Integer
128 Dim iIndex As Long
129
130 For i = 0 To length - 1
131 iIndex = CRC16Hi Xor data(i)
132 CRC16Hi = CRC16Lo Xor GetCRCHi(iIndex) \'低位处理
133 CRC16Lo = GetCRCLo(iIndex) \'高位处理
134 Next i
135 ReturnDatahi = CRC16Hi \'CRC高位
136 ReturnDatalo = CRC16Lo \'CRC低位
137
138 Return 1
139 End Function
205 \'数据处理
206 Private Function modbus_fun3(start_address As Integer, read_number As Integer) As Integer
207 Dim sendbyte = New Byte() {0, 0, 0, 0, 0, 0, 0, 0}
208 Dim recvbyte(256) As Byte
209 Dim length As Int32
210 Dim data(24) As Int16
211 Dim crc_value As Int16
212 Dim i As Int16
213 Dim text As String
214 sendbyte(0) = 1 ‘单位标识符
215 sendbyte(1) = 3 ‘功能码
216 sendbyte(2) = start_address >> 8 ‘读寄存器起始地址
217 sendbyte(3) = start_address
218 sendbyte(4) = read_number >> 8 ‘读寄存器数量
219 sendbyte(5) = read_number
220
221 crc_value = crc(sendbyte, 6,sendbyte(7),sendbyte(6))
222 Try
223 text = ""
224 \'发送命令
225 SerialPort1.Write(sendbyte, 0, 8)
226 \'接收数据
227 length = SerialPort1.BytesToRead()
228 While (length < 53)
229 length = SerialPort1.BytesToRead()
230 End While
231 i = SerialPort1.Read(recvbyte, 0, length)
232 For k = 0 To 23
233 data(k) = (recvbyte(k * 2 + 3) * 256) + recvbyte(k * 2 + 4)
234 Next k
235 \'数值转换
236 For i = 0 To 7
237 display_value(i) = (data(i * 3 + 2) / 100.0)
238 Next i
附录2:显示通道数据程序
239 Catch ex As Exception