Ejemplo n.º 1
0
        protected virtual bool Send(string str)
        {
            bool ret = false;

            str = _4FEString + str;//根据645协议,加4个FE通讯会好很多
            try
            {
                SerialPortCom _sp = new SerialPortCom(_portName, _baudRate);
                _sp.ReceiveFinishEven += ReceiveFinishJudge;

                ret = _sp.Send(str);
                if (MsgEvent != null)
                {
                    MsgEvent(true, str);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ret);
        }
Ejemplo n.º 2
0
        protected virtual string SendAndRec(string str)
        {
            string ret = string.Empty;

            str = _4FEString + str;//根据645协议,加4个FE通讯会好很多
            try
            {
                SerialPortCom _sp = new SerialPortCom(_portName, _baudRate);
                _sp.ReceiveFinishEven += ReceiveFinishJudge;
                ret = _sp.SendAndReceive(str);
                if (MsgEvent != null)
                {
                    MsgEvent(true, str);
                    MsgEvent(false, ret);
                }
                AnayzeFrm(ret);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(ret);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 构造函数
 /// 初始化串口号,波特率,判断读完事件
 /// </summary>
 public IProtocol()
 {
     _sp = new SerialPortCom(_portName, _baudRate);
     _sp.ReceiveFinishEven += ReceiveFinishJudge;
 }