Beispiel #1
0
 private void ScanArduino_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     try
     {
         ArduinoMessage += ArduinoSerialPort.ReadExisting();
         ArduinoReadText.Invoke(new MethodInvoker(delegate
         {
             ArduinoReadText.Text += ArduinoMessage;
         }));
         if (ArduinoMessage.Contains("\n"))
         {
             measurementData.Add(Convert.ToInt32(ArduinoMessage));
             ArduinoMessage = "";
             ScanProgress.Invoke(new MethodInvoker(delegate
             {
                 ScanProgress.Value = 1 / scanLength;
             }));
             if (measurementData.Count < scanLength)
             {
                 SDMC1SerialPort.Write("+1\r");
             }
             else
             {
                 SDMC1SerialPort.DataReceived   -= ScanSDMC1_DataReceived;
                 SDMC1SerialPort.DataReceived   += SDMC1SerialPort_DataReceived;
                 ArduinoSerialPort.DataReceived -= ScanArduino_DataReceived;
                 ArduinoSerialPort.DataReceived += ArduinoSerialPort_DataReceived;
                 SDMC1SerialPort.Write("R" + scanStartPosition + "\r");
                 HomeButton.Invoke(new MethodInvoker(delegate
                 {
                     HomeButton.Enabled = true;
                 }));
                 ScanButton.Invoke(new MethodInvoker(delegate
                 {
                     ScanButton.Enabled = true;
                 }));
             }
             moves++;
         }
     }
     catch (Exception error)
     {
         MessageText.Invoke(new MethodInvoker(delegate
         {
             MessageText.Text = error.Message;
         }));
         ArduinoMessage = "";
     }
 }
Beispiel #2
0
 private void ArduinoSerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     try
     {
         String reply = ArduinoSerialPort.ReadExisting();
         ArduinoReadText.Invoke(new MethodInvoker(delegate
         {
             ArduinoReadText.Text = ArduinoReadText.Text + reply;
         }));
     }
     catch (Exception error)
     {
         MessageText.Invoke(new MethodInvoker(delegate
         {
             MessageText.Text = error.Message;
         }));
     }
 }