libModbus源码是VC++的,编译之后,引用就行了。
Module libmodbus
Public Declare Auto Function modbus_new_rtu Lib "modbus.dll" (ByVal device As Byte(), ByVal baud As Integer, ByVal parity As Byte, ByVal data_bit As Integer, ByVal stop_bit As Integer) As IntPtr
Public Declare Auto Function modbus_set_slave Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal slave As Integer) As IntPtr
Public Declare Auto Function modbus_connect Lib "modbus.dll" (ByVal ctx As IntPtr) As Integer
'
Public Declare Auto Function modbus_get_response_timeout Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal sec As Integer, ByVal usec As Integer) As Integer
Public Declare Auto Function modbus_set_response_timeout Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal sec As Integer, ByVal usec As Integer) As Integer
Public Declare Auto Function modbus_close Lib "modbus.dll" (ByVal ctx As IntPtr) As Integer
Public Declare Auto Function modbus_free Lib "modbus.dll" (ByVal ctx As IntPtr) As Integer
Public Declare Auto Function modbus_read_bits Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal addr As Integer, ByVal nb As Integer, ByVal data() As Byte) As Integer '01读取线圈
Public Declare Auto Function modbus_read_input_bits Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal addr As Integer, ByVal nb As Integer, ByVal data() As Byte) As Integer '02读取离散输入
Public Declare Auto Function modbus_read_registers Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal addr As Integer, ByVal nb As Integer, ByVal data() As UInt16) As Integer '03读取保持寄存器
Public Declare Auto Function modbus_read_input_registers Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal addr As Integer, ByVal nb As Integer, ByVal dest() As UInt16) As Integer '04读取输入寄存器
Public Declare Auto Function modbus_write_bit Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal coil_addr As Integer, ByVal status As Integer) As Integer '05写单个线圈
Public Declare Auto Function modbus_write_register Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal reg_addr As Integer, ByVal value As Integer) As Integer '06写单个保持寄存器
Public Declare Auto Function modbus_write_bits Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal coil_addr As Integer, ByVal nb As Integer, ByVal data() As Byte) As Integer '0x0F写多个线圈
Public Declare Auto Function modbus_write_registers Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal addr As Integer, ByVal nb As Integer, ByVal data() As UInt16) As Integer
Public Declare Auto Function modbus_write_and_read_registers Lib "modbus.dll" _
(ByVal ctx As IntPtr, ByVal write_addr As Integer, ByVal write_nb As Integer, ByVal src() As UInt16, _
ByVal read_addr As Integer, ByVal read_nb As Integer, ByVal dest() As UInt16) As Integer
Public Declare Auto Function modbus_strerror Lib "modbus.dll" ()
Public Declare Auto Function modbus_set_error_recovery Lib "modbus.dll" (ByVal ctx As IntPtr, ByVal ha As Byte)
End Module