Esempio n. 1
0
        void initModbusClient()
        {
            wsmbtControl = new WSMBTControl();

            wsmbtControl.Mode            = Mode.TCP_IP;
            wsmbtControl.ResponseTimeout = 1000;
            wsmbtControl.ConnectTimeout  = 1000;
            Result result = wsmbtControl.Connect(_registerGroup.IpAddress, _registerGroup.Port);

            if (result != Result.SUCCESS)
            {
                _comStatusError = "Not able to connect to Device:" + _registerGroup.IpAddress;
            }
            else if (result == Result.SUCCESS)
            {
                _comStatusError = "Connected to Device:" + _registerGroup.IpAddress;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 端口连接函数
        /// </summary>
        /// <param name="sName"></param>
        /// <param name="nPort"></param>
        /// <returns></returns>
        public bool MB_Connect(string sName, int nPort)
        {
            if (m_nProcotol == 2)
            {
                tcp_svr = new WSMBTControl();
                tcp_svr.LicenseKey("2222222222222222222222222AAF2");
                return(WSMBT.Result.SUCCESS == tcp_svr.Connect(sName, nPort));
            }

            ser_svr = new WSMBSControl();
            ser_svr.LicenseKey("2222222222222222222222222F3AA");
            ser_svr.PortName = sName;
            ser_svr.Parity   = Parity.None;
            ser_svr.DataBits = 8;
            ser_svr.StopBits = 1;
            ser_svr.BaudRate = nPort;
            bTaskStatus      = false;
            return(WSMBS.Result.SUCCESS == ser_svr.Open());
        }