Esempio n. 1
0
 void _serialPort_DataReceived(object sender, SerialComPort.Events.DataEventArgs e)
 {
     //Only Receive incoming Messages
     //All other messages are received in MessageReceived()-Event
     _dataReceived += String.IsNullOrEmpty(_dataReceived) ? e.Data : " " + e.Data;
     var result = Emulator.HandleRequest(_dataReceived);
     switch (result.Type)
     {
         case Emulator.ResponseType.Empty:
         case Emulator.ResponseType.Incomplete:
             //Nothing
             break;
         case Emulator.ResponseType.ChecksumNotOk:
         case Emulator.ResponseType.Error:
         case Emulator.ResponseType.RegisterUnknown:
             //Respond Error
         case Emulator.ResponseType.Ok:
             _serialPort.Send(result.Value);
             _dataReceived = string.Empty;
             break;
         case Emulator.ResponseType.NoCommonStartChar:
         //Delete Overhead Data from Buffer, when containing no Start-char
         case Emulator.ResponseType.WrongReceiver:
             //Ignore
             _dataReceived = string.Empty;
             break;
     }
 }
 // Called when the Disconnect button is clicked. Disconnects the serial connection with the desired COM port.
 private void OnDisconnectButtonClick(object sender, EventArgs e)
 {
     if (SerialComPort.IsOpen)
     {
         SerialComPort.Close();
         COMPortConnectButton.Enabled    = true;
         COMPortDisconnectButton.Enabled = false;
         COMPortRefreshButton.Enabled    = true;
         COMPortSelectionBox.Enabled     = true;
         COMPortStatusTextBox.Text       = "Disconnected";
     }
 }
Esempio n. 3
0
 void _serialPort_InfoReceived(object sender, SerialComPort.Events.InfoEventArgs e)
 {
     switch (e.MessageType)
     {
         case Serial.MessageTypes.Incoming:
             break;
         case Serial.MessageTypes.Normal:
             break;
         case Serial.MessageTypes.Outgoing:
             break;
         case Serial.MessageTypes.Warning:
             break;
         case Serial.MessageTypes.Error:
             break;
     }
 }
Esempio n. 4
0
File: Form.cs Progetto: Yorati/KRST
 public Form()
 {
     InitializeComponent();
     //Disconnection.Enabled = false;
     SendFile.Enabled = false;
     file             = null;
     serialcomport    = new SerialComPort();
     serialcomport.RegisterReceiveCallback(ReceiveDataHandler);
     receivedDataTimer          = new Timer();
     receivedDataTimer.Interval = 25;   // 25 ms
     receivedDataTimer.Tick    += new EventHandler(ReceivedDataTimerTick);
     receivedDataTimer.Start();
     replayFileTimer          = new Timer();
     replayFileTimer.Interval = 1000;   // 1000 ms
     replayFileTimer.Tick    += new EventHandler(ReplayFileTimerTick);
     replayFileTimer.Start();
 }
Esempio n. 5
0
        public Main()
        {
            InitializeComponent();
            file       = null;
            serialPort = new SerialComPort();
            serialPort.RegisterReceiveCallback(ReceiveDataHandler);
            receivedDataTimer          = new Timer();
            receivedDataTimer.Interval = 25; // 25 ms
            receivedDataTimer.Tick    += new EventHandler(ReceivedDataTimerTick);
            receivedDataTimer.Start();
            replayLogTimer          = new Timer();
            replayLogTimer.Interval = 1000; // 1000 ms
            replayLogTimer.Tick    += new EventHandler(ReplayLogTimerTick);
            replayLogTimer.Start();
            Version version = Assembly.GetEntryAssembly().GetName().Version;

            this.Text = "TERMINAL - Serial Data Terminal v" + version;
        }
        /*==================================================== FORM OPEN/CLOSE ====================================================*/

        // Called when the form is closed, aborts the testDataThread to prevent it from continuing
        private void OnFormClosed(object sender, FormClosedEventArgs e)
        {
            commsThread.Abort();

            // Close any still-open subforms
            if (deadbandSettings != null || deadbandSettingsOpen)
            {
                deadbandSettings.Close();
            }
            if (graphs != null || graphingOpen)
            {
                graphs.Close();
            }

            if (SerialComPort.IsOpen)
            {
                SerialComPort.Close();
            }
        }
Esempio n. 7
0
 void serial_DataReceived(object sender, SerialComPort.Events.DataEventArgs e)
 {
     _response += String.IsNullOrEmpty(_response) ? e.Data : " " + e.Data;
     //Assert.AreEqual(e.Data, "81 11 F1 81 04");
     Console.WriteLine("{0}:\t{1}", "Incoming", e.Data);
 }