| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2574 人关注过本帖
标题:VB.net 如何与modbus TCP server设备进行通讯
只看楼主 加入收藏
wengcxs
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2021-5-15
收藏
 问题点数:0 回复次数:2 
VB.net 如何与modbus TCP server设备进行通讯
请教 熟悉 sockets编程的大侠:
我有一个modbus TCP SERVER模块,输出开关量、输入模拟量信号
地址是192.168.1.232,端口10000

通过测试软件输出控制信号如下,测试没问题
打开通道1
发送:FE 05 00 00 FF 00 98 35
接收:FE 05 00 00 FF 00 98 35

打开通道2
发送:FE 05 00 01 FF 00 C9 F5
接收:FE 05 00 01 FF 00 C9 F5

全部关闭/全部打开
发送:FE 0F 00 00 00 02 01 00 91 93
接收:FE 0F 00 00 00 02 C0 05
发送:FE 0F 00 00 00 02 01 FF D1 D3
接收:FE 0F 00 00 00 02 C0 05

但是在用 2010进行编程时,碰到困难:
1、服务器模块的声明和连接,网上找到的代码都是根据hostname进行连接,通过ip地址连接的代码搞不懂。
2、发送上面的指令代码,并接收返回值,该怎么声明和操作?

搞了几天都没进展,谢谢
搜索更多相关主题的帖子: TCP 发送 VB.net 接收 FF 
2021-05-15 13:20
microcwj
Rank: 1
等 级:新手上路
威 望:1
帖 子:3
专家分:0
注 册:2006-12-15
收藏
得分:0 
成熟的方案有libModBUS,自己了解一下,底层封装已经全部做好。
2021-09-25 02:30
microcwj
Rank: 1
等 级:新手上路
威 望:1
帖 子:3
专家分:0
注 册:2006-12-15
收藏
得分:0 
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
2021-09-25 02:38
快速回复:VB.net 如何与modbus TCP server设备进行通讯
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013810 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved