皇楚帝123
級別: *
|
這是找到的宏指令模板 // Read Holding Registers macro_command main() char command[32], response[32] short address, checksum short read_no, return_value, read_data[2], i FILL(command[0], 0, 32)// initialize command[0]~command[31] to 0 FILL(response[0], 0, 32) command[0] = 0x1// station number command[1] = 0x3// read holding registers (function code is 0x3) address = 0// starting address (4x_1) is 0 HIBYTE(address, command[2]) LOBYTE(address, command[3]) read_no = 2// the total words of reading is 2 words HIBYTE(read_no, command[4]) LOBYTE(read_no, command[5]) CRC(command[0], checksum, 6)// calculate 16-bit CRC LOBYTE(checksum, command[6]) HIBYTE(checksum, command[7]) OUTPORT(command[0], "MODBUS RTU Device",8)// send request INPORT(response[0], "MODBUS RTU Device",9,return_value)// read response if (return_value > 0 and response[1] == 0x4) then read_data[0] = response[4] + (response[3] << 8)// 4x_1 read_data[1] = response[6] + (response[5] << 8)// 4x_2 SetData(read_data[0], "Local HMI", LW, 0, 2) end if end macro_command 通過485連電腦,用串口助手讀到的數據卻是 7F DF EB FF FB 5D 6D 00 不知道是什么原因? 剛接觸這個東西,望大神指教! |
---|---|
|
tyw123456
級別: 家園常客
|
你485的A B線是不是反了 |
|
---|---|---|
本帖最近評分記錄:
|