Beispiel #1
0
 // ------------------------------------------------------------------------
 /// <summary>Disconnect from the Modbus slave</summary>
 public void disconnect()
 {
     connected = false;
     if (modbusTCP != null)
     {
         modbusTCP.disconnect();
         modbusTCP = null;
     }
 }
Beispiel #2
0
 // ------------------------------------------------------------------------
 /// <summary>Connects to the Modbus slave</summary>
 public void connect(string ip, ushort port)
 {
     try
     {
         modbusTCP = new ModbusTCP(ip, port, report);
         modbusTCP.OnResponseDataTCP += new ModbusTCP.ResponseDataTCP(ModbusTCP_OnResponseData);
         modbusTCP.OnExceptionTCP    += new ModbusTCP.ExceptionDataTCP(ModbusTCP_OnException);
         modbusTCP.OnOutgoingDataTCP += new ModbusTCP.OutgoingDataTCP(ModbusTCP_OnOutgoingData);
         connected = true;
     }
     catch (Exception ex)
     {
         connected = false;
         disconnect();
         if (OnError != null)
         {
             OnError(ex);
         }
     }
 }