Exemplo n.º 1
0
 // Static Methods
 private static string GetMessage(SerialError serialError)
 {
     return(serialError switch
     {
         SerialError.Frame => "The hardware detected a framing error.",
         SerialError.Overrun => "A character-buffer overrun has occurred. The next character is lost.",
         SerialError.RXOver => "An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.",
         SerialError.RXParity => "The hardware detected a parity error.",
         SerialError.TXFull => "The application tried to transmit a character, but the output buffer was full.",
         _ => throw new ArgumentOutOfRangeException(nameof(serialError), serialError, $"Unexpected serial error encountered: {serialError}"),
     });
Exemplo n.º 2
0
    void OnSerialError(SerialError serialError)
    {
        DisplayText("Error:" + serialError.error.ToString());

        //attempt to auto reconnect if the USB was unplugged
        if (serialError.error == ANT_Device.serialErrorCode.DeviceConnectionLost)
        {
            foreach (AntChannel channel in AntManager.Instance.channelList)
            {
                channel.PauseChannel();
            }

            StartCoroutine("Reconnect", serialError.sender.getSerialNumber());
        }
    }
Exemplo n.º 3
0
        //Since we can not garantee the order or the exact time that the event handler is called
        //We wil look for an event that was firered that matches the type and that bytesToRead
        //is greater then the parameter
        public bool Validate(SerialError eventType, int bytesToRead)
        {
            bool retValue = false;

            lock (this)
            {
                for (int i = 0; i < EventType.Count; i++)
                {
                    if (eventType == (SerialError)EventType[i] && bytesToRead <= (int)BytesToRead[i] && (SerialPort)Source[i] == _com)
                    {
                        EventType.RemoveAt(i);
                        BytesToRead.RemoveAt(i);
                        Source.RemoveAt(i);
                        NumEventsHandled--;
                        retValue = true;
                        break;
                    }
                }
            }

            return(retValue);
        }
Exemplo n.º 4
0
 internal SerialErrorReceivedEventArgs(SerialError eventCode) {
     errorType = eventCode;
 }
Exemplo n.º 5
0
 /// <summary> Default Constructor. </summary>
 /// <param name="eventType"> The type of the event. </param>
 public DataErrorEventArgs(SerialError eventType) {
     EventType = eventType;
 }
Exemplo n.º 6
0
		internal SerialErrorReceivedEventArgs(SerialError eventType)
		{
			this.eventType = eventType;
		}
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eventType">Event that occurred</param>
 public SerialErrorReceivedEventArgs(SerialError eventType)
 {
     m_EventType = eventType;
 }
Exemplo n.º 8
0
 internal SerialErrorReceivedEventArgs(SerialError error)
 {
     m_error = error;
 }
Exemplo n.º 9
0
 //Serial Port Error Event Handler
 static private void sp_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
 {
     _spErr = e.EventType;
 }
Exemplo n.º 10
0
 //Serial Port Error Event Handler
 private void sp_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
 {
     _spErr = e.EventType;
 }
 public static void LogSerialError(this ILogger logger, String portName, SerialError error)
 {
     sSerialError(logger, portName, error, null);
 }
 /// <summary>
 /// Event Handler called when an error is received at the COM port
 /// </summary>
 private void SystemPort_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
 {
     SerialError err = e.EventType;
 }
Exemplo n.º 13
0
 private void logErrors(SerialError e)
 {
     System.Diagnostics.Debug.WriteLine(String.Format("SerialPort Error: {0}", e));
 }
Exemplo n.º 14
-1
        public MFTestResults ErrorRcvdEvent()
        {
            if (!IsLoopback || IsEmulator)
                return MFTestResults.Skip;

            result = MFTestResults.Pass;
            try
            {
                eventCount = 0;
                // create a buffer several bytes bigger then internal buffers
                byte[] buffer = Encoding.UTF8.GetBytes(new string('a', 512+40));
                eventSerialPort = new SerialPort(Serial.COM1);
                eventSerialPort.WriteTimeout = 1000;
                eventSerialPort.Handshake = Handshake.None;

                // register events
                eventSerialPort.ErrorReceived += new SerialErrorReceivedEventHandler(eventSerialPort_ErrorReceived_BeforeOpen);
                eventSerialPort.Open();
                eventSerialPort.ErrorReceived += new SerialErrorReceivedEventHandler(eventSerialPort_ErrorReceived_AfterOpen);

                // Test RX overflow (no flow control)
                expectedError = SerialError.RXOver;
                eventSerialPort.Write(buffer, 0, buffer.Length / 2);
                Thread.Sleep(100);
                eventSerialPort.Write(buffer, 0, buffer.Length / 2);
                eventSerialPort.Close();

                Thread.Sleep(500);

                if (eventCount == 0)
                {
                    // BUGBUG: 21222
                    Log.Exception("Expected RXOver events fired, saw " + eventCount + " fired.");
                    result = MFTestResults.Fail;
                }
                eventCount = 0;

                // Test TX overflow (flow control - HW)
                expectedError = SerialError.TXFull;
                eventSerialPort.Open();
                for (int i = 0; i < 2; i++)
                {
                    eventSerialPort.Write(buffer, 0, buffer.Length);
                }
                eventSerialPort.Close();

                Thread.Sleep(500);

                if (eventCount == 0)
                {
                    // BUGBUG: 21222
                    Log.Exception("Expected TXFull events fired, saw " + eventCount + " fired.");
                    result = MFTestResults.Fail;
                }

                // TODO: Need to add PC based tests that allow testing Parity, Overrun, and Frame errors.  This is done manually now.
            }
            catch (Exception ex)
            {
                result = MFTestResults.Fail;
                Log.Exception(ex.Message);
            }
            finally
            {
                eventSerialPort.Dispose();
            }
            return result;
        }