Beispiel #1
0
 private bool m_bRTUSync           = false; //用于同步收发消息
 #endregion
 #region TCP
 #region Construction
 public Modbus(IPAddress _ip, int port)
 {
     m_nRunMode = emCommMode.TCP;
     m_IP       = _ip;
     m_nPort    = port;
     if (!TCPconnect(_ip, m_nPort))
     {
         throw new Exception("网络连接失败!");
     }
     m_thd_SendMsg = new Thread(new ThreadStart(ThdProcSendMessage));
 }
Beispiel #2
0
 public Modbus(string strPortName, int nBaudRate, int nDatabits, Parity parity, StopBits stopBits)
 {
     if (m_SerialPort != null)
     {
         m_SerialPort.Dispose();
         m_SerialPort = null;
     }
     m_SerialPort = new SerialPort(strPortName, nBaudRate, parity, nDatabits, stopBits);
     m_nRunMode   = emCommMode.RTU;
     try
     {
         if (!SPconnect())
         {
             throw new Exception("串口打开失败!");
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
     m_thd_SendMsg = new Thread(new ThreadStart(ThdProcSendMessage));
 }