-Begin-
Introduction
Recently, students studying motion control asked whether it is possible to read data from the motion control card using the Modbus protocol.
After testing, it is indeed feasible. The ECI1408 board from Zhengyundong is used here; other brands may not support it, so please consult your supplier for specifics.
Modbus Protocol
The Zhengyundong controller supports two storage areas, namely area 0 and area 4.
- Area 0 starts from address 10000 corresponding to the input IN port.
- Area 0 starts from address 20000 corresponding to the output OUT port.
- Area 4 starts from address 10000 corresponding to the axis DPOS range.
- Area 4 starts from address 11000 corresponding to the axis MPOS range.
- Area 4 starts from address 12000 corresponding to the axis VP_SPEED range.
- Area 4 starts from address 13000 corresponding to the analog output DA range.
- Area 4 starts from address 14000 corresponding to the analog input AD range.
- For other parameters, the custom storage area 0-7999 can be used.


Code Testing

Here we test by reading the position of the XYZ three axes.
- Establishing connection
//Modbus communication object
private ModbusTcp modbusTcp = new ModbusTcp();
//Cancel thread source
private CancellationTokenSource cts;
private void btn_Connect_Click(object sender, EventArgs e)
{
if (modbusTcp.Connect(this.txt_IPAddress.Text, Convert.ToInt32(this.txt_Port.Text)))
{
//If connected successfully, start thread to read
cts = new CancellationTokenSource();
Task.Run(() =>
{
GetMotionData();
}, cts.Token);
}
else
{
MessageBox.Show("Motion control card connection failed", "Establish Connection");
}
}
- Disconnecting
private void btn_DisConn_Click(object sender, EventArgs e)
{
cts?.Cancel();
modbusTcp.DisConnect();
}
- Multi-threaded reading and parsing
private void GetMotionData()
{
while (!cts.IsCancellationRequested)
{
byte[] res = modbusTcp.ReadKeepReg(1, 10000, 6);
this.Invoke(new Action(() =>
{
if (res != null && res.Length == 12)
{
float[] values = FloatLib.GetFloatArrayFromByteArray(res, DataFormat.CDAB);
this.lbl_XAxis.Text = values[0].ToString();
this.lbl_YAxis.Text = values[1].ToString();
this.lbl_ZAxis.Text = values[2].ToString();
}
}));
}
}
- Test results are as follows:
The upper computer software displays real-time data:

Test software results show:

Overall Summary
This case mainly tested reading parameters from the motion control card based on the Modbus protocol. This situation is primarily used when third-party software needs relevant data from the motion control system. Additionally, if future motion control projects require data to be provided to other software, the motion control card can be set up as a ready-made free ModbusTCP server, which can not only transmit motion control parameters but also other parameters.
-END-
Many people ask me why, even after following, they still miss our lottery, new book launches, and other information. In fact, the recent updates to the public account’s push mechanism have changed. If you want to receive our article pushes immediately, I suggest you star the public account. Here’s how to star it, just a little action from you, and you won’t get lost in the future.