Exemplo n.º 1
0
 public bool Open()
 {
     try
     {
         //	this._SerialPort.Handshake = Handshake.RequestToSend;
         this._SerialPort.Open();
         this._SerialPort.ReadTimeout  = 300;
         this._SerialPort.WriteTimeout = 300;
         this._SerialPort.DiscardInBuffer();
         this._SerialPort.DiscardOutBuffer();
         this._SerialPort.DataReceived += new SerialDataReceivedEventHandler(_SerialPort_DataReceived);
         this._SerialPort.PinChanged   += new SerialPinChangedEventHandler(_SerialPort_PinChanged);
         //			this._SerialPort.ReadChar();
     }
     catch (Exception ex)
     {
         this.MessageString = ex.Message;
         return(false);
     }
     using (RS232EventArgs evt = new RS232EventArgs(this._SerialPort))
     {
         evt.Event       = CommunicationEvents.ConnectedAsClient;
         evt.Description = "Connected...";
         FireStatusMessage(evt);
     }
     return(true);
 }
Exemplo n.º 2
0
 public bool Close()
 {
     if (this._ConnectMethod == ConnectMethods.Listener)
     {
     }
     this._SerialPort.Close();
     using (RS232EventArgs evt = new RS232EventArgs(this._SerialPort))
     {
         evt.Event = CommunicationEvents.Disconnected;
         FireStatusMessage(evt);
     }
     return(true);
 }
Exemplo n.º 3
0
 protected void FireStatusMessage(RS232EventArgs channelArgs)
 {
     channelArgs.iType = this.iType;
     if (this._SuspendDelegateNotifications == false)
     {
         this.FireCommunicationEvent(channelArgs);
     }
     if (this.InLoopBackMode == true)
     {
         if (this.SelfTestEvent != null)
         {
             this.SelfTestEvent(this, channelArgs);
         }
     }
 }
Exemplo n.º 4
0
        void _SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            using (RS232EventArgs evt = new RS232EventArgs(this._SerialPort))
            {
                evt.Description = this._SerialPort.ReadExisting();
                evt.data        = Encoding.ASCII.GetBytes(evt.Description);

                //if (evt.data[evt.data.Length - 1] == '\r')
                if (evt.Description.IndexOf('>') > -1)
                {
                    evt.Event = CommunicationEvents.ReceiveEnd;
                }
                else
                {
                    evt.Event = CommunicationEvents.Receive;
                }
                FireStatusMessage(evt);
            }
        }