laitimes

Communication gateway software 012 - using X2Mbt to implement Modbus TCP access to Mysql server

author:A sleeve wipe Jiangnan

This topic describes how to use CommGate X2Mbt to implement Modbus TCP access to Mysql databases. CommGate X2MBT is a gateway software developed by Ningbo Kean Network Information Technology, which can be downloaded from the wangxinzhihui.com of Network Information Technology.

【Example】As shown in the figure below, the host computer obtains the data of the Mysql database through Modbus TCP.

Communication gateway software 012 - using X2Mbt to implement Modbus TCP access to Mysql server

【Solution】Set up the gateway machine, use Ethernet communication with Mysql, Ethernet communication with Modbus TCP Master host computer, and install CommGate X2MBT software.

  1. MYSQL TABLE STRUCTURE REQUIREMENTS:
Communication gateway software 012 - using X2Mbt to implement Modbus TCP access to Mysql server
  1. At least two fields: name and value.
  • name: the name of the tag and the type of characters
  • value: A numeric value, which can be a character type or a floating-point type
  • state: not required, integer type, 1 for good and 0 for bad
  • time: Not required, can be datetime or bigint
  • If the above field names are not name, value, state, or time, you need to configure the field names in the following configuration file:
  1. MySQL communication debugging: Run the MySQL debugging tool on the gateway machine to communicate with the MySQL server for debugging. After the communication is normal, make a note of the communication parameters.
  2. Configure X2MBT egress parameters: Edit X2MBT .ini in the X2MBT installation directory Ini to modify the egress parameters.
[OUT]
;通讯类型Modbus TCP,不做修改
Type=MODBUS_TCP
;modbus tcp server ip
Host=127.0.0.1
;modbus tcp server 端口
Port=502
;从设备地址
DeviceID=1
;通讯超时,单位ms
Timeout=300
;读寄存器间隔时间,单位ms,一般不做修改
ReadDevTime=50
;浮点/双精度字节顺序类型 0:ABCD/ABCDEFGH 1:CDAB/GHEFCDAB 2:DCBA/HGFEDCBA 3:BADC/BADCFEHG
SwapFloat=2
;整型/长整型字节顺序类型 0:ABCD/ABCDEFGH 1:CDAB/GHEFCDAB 2:DCBA/HGFEDCBA 3:BADC/BADCFEHG
SwapInt=1
[IN]
;输入端配置文件名,不含后缀
INI = Mysql
Type =           
  1. Configure X2MBT entry parameters: Edit Mysql.ini in the X2MBT installation directory Ini and modify the entry parameters according to the communication parameters just noted.
[IN]
;输入源类型:MYSQL Server,不做修改
Type=MYSQL
;MYSQL Server IP
ServerIP=127.0.0.1
;MYSQL Server用户
UserName=root
;用户密码
Pwd=123456
;数据库名称
DB=test
;Port 0表示采用默认端口
port = 0
;读取数据的SQL语句,如果不设置的话,将由以下字段名自动构造
;表中至少包含name,value字段
;state字段不是必须的,没有state字段时,必须构造1个虚拟state字段,如select name, value, 1 as state
from snapshot
;State值 = 1 好值 =0 坏值
ReadSQL=select name, value, state, time from snapshot
;定义Name字段名,默认为name
NameField = name
;定义Value字段名,默认为value
ValueField = value
;定义State字段名,默认为state
StateField = state
;定义Time字段名,可以不定义,默认为空,表示没有Time字段
TimeField = time           
  1. Tag configuration: Edit the X2MBT .xls in the X2MBT installation directory and configure the tag.
Communication gateway software 012 - using X2Mbt to implement Modbus TCP access to Mysql server
  1. Run X2MBT .exe to start the gateway.
  2. modbus communication debugging: Run modscan on the host computer to debug modbus TCP communication with the gateway machine.
  3. For detailed configuration instructions, see X2MBT V4 User Manual.

For more communication resources, please visit wangxinzhihui.com.

Read on