Back
Write Coils Using Modbus

Author: Admin 06/12/2021
Language: C#


Description:

Write coils using the FieldTalk Modbus Master Library.

Article:

private void WriteCoil()
        {
            OpenConnection();

            try
            {
                bool CoilTrueFalse = Convert.ToBoolean(1);
                Poll_Result = myProtocol.writeCoil(1, 1, CoilTrueFalse);

                if (Poll_Result == BusProtocolErrors.FTALK_SUCCESS)
                {
                    lblResult.Text = "Completed OK";
                }
                else
                {
                    lblResult.Text = "Error was: " + BusProtocolErrors.getBusProtocolErrorText(Poll_Result);
                }

                GetCounters();

                //Close connection
                if (myProtocol.isOpen())
                    myProtocol.closeProtocol();
                myProtocol = null;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }


Back
Comments
Add Comment
There are no comments yet.