Author: Admin 06/01/2021
Language:
C#
Tags:
Read multiple registers using the FieldTalk Modbus Master Library.
private int Poll_Result;
private void ReadInputs()
{
OpenConnection();
try
{
lblResult.Text = "";
float[] W_G_Vals = new float[Convert.ToInt16(tbNumOfRegisters.Text)];
Poll_Result = myProtocol.readMultipleRegisters(1, 1, W_G_Vals, 10);
if (Poll_Result == BusProtocolErrors.FTALK_SUCCESS)
{
for (int i = 0; i < W_G_Vals.Length; i++)
{
lblResult.Text += "Value: " + Convert.ToString(W_G_Vals[i].ToString("###.00")) + Environment.NewLine;
}
}
else
{
lblResult.Text = "Error was: " + BusProtocolErrors.getBusProtocolErrorText(Poll_Result);
}
W_G_Vals = null;
//Close connection
if (myProtocol.isOpen())
myProtocol.closeProtocol();
myProtocol = null;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
Read More: https://www.modbusdriver.com/doc/mbusmaster.net/index.htm