private void ReleasePort() { m_port.ArduinoPinsAvailable -= OnArduinoPinsAvailable; panelForControls.Controls.Clear(); m_port.Dispose(); m_port = null; }
private void Window_Closed(object sender, EventArgs e) { if (ArduinoPort.IsOpen) { ArduinoPort.Write("1000"); } }
public MsgLogForm(ArduinoPort port) { arduinoport = port; InitializeComponent(); arduinoport.MessageSent += Arduinoport_MessageSent; arduinoport.MessageReceived += Arduinoport_MessageReceived; }
private void DisconnectArduino() { ArduinoPort.Close(); connected = false; ConnectBtn.BackColor = defaultButtonColor; ConnectBtn.Text = "CONNECT"; StateLabel.Text = "DISCONNECTED"; StateLabel.ForeColor = Color.Crimson; }
public MonitorForm(ArduinoPort port) { arduinoport = port; InitializeComponent(); arduinoport.MessageReceived += Arduinoport_MessageReceived; pannelControlList = new List <Tuple <ChannelId, Control> >(); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.MonitorField_1, label1)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.MonitorField_2, label2)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.MonitorField_3, label3)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.MonitorField_4, label4)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.MonitorField_5, label5)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.MonitorField_6, label6)); }
private async void BtnSendData_Click(object sender, RoutedEventArgs e) { TlbExperiment.IsEnabled = false; SpItems.IsEnabled = false; ArduinoPort.DiscardOutBuffer(); ArduinoPort.DiscardInBuffer(); TxtStatusBrush.Color = Colors.Black; ArduinoPort.Write("1001"); TxtStatus.Text = "Sending data..."; await Task.Delay(1500); byte[] IntToBytes = BitConverter.GetBytes(ExpProgram.CycleNumber); //sending number of cycles ArduinoPort.Write(IntToBytes, 0, 2); IntToBytes = BitConverter.GetBytes(Convert.ToInt16(ExpProgram.CycleItems.Count)); //sending number of cycleitems ArduinoPort.Write(IntToBytes, 0, 2); foreach (var item in ExpProgram.CycleItems) //sending all cycle parameters { IntToBytes = BitConverter.GetBytes(item.CycleDuration); ArduinoPort.Write(IntToBytes, 0, 2); IntToBytes = BitConverter.GetBytes(item.OnTime); ArduinoPort.Write(IntToBytes, 0, 2); IntToBytes = BitConverter.GetBytes(item.OffTime); ArduinoPort.Write(IntToBytes, 0, 2); } Boolean DataWereSent = false; Int16 GetCode; while (!DataWereSent) { if (ArduinoPort.BytesToRead > 0) { Int16.TryParse(ArduinoPort.ReadLine(), out GetCode); if (GetCode == 1604) { DataWereSent = true; } // DataWereSent = true; // TxtStatus.Text = ArduinoPort.ReadLine(); } } TlbExperiment.IsEnabled = true; SpItems.IsEnabled = true; BtnStart.IsEnabled = true; DataWereSentGlobal = true; TxtStatus.Text = "Data were succesfully sent, press start to continue..."; }
public GraphForm(ArduinoPort port) { arduinoport = port; InitializeComponent(); DrawX = new Range(0, GraphPictureBox1.Width); DrawY = new Range(0, GraphPictureBox1.Height); GraphPlot_1 = new Graph(50, GraphType.Rolling, GraphPictureBox1.ClientRectangle, new Range(0, 255)); GraphPlot_2 = new Graph(50, GraphType.Rolling, GraphPictureBox1.ClientRectangle, new Range(0, 255)); GraphPlot_3 = new Graph(50, GraphType.Rolling, GraphPictureBox1.ClientRectangle, new Range(0, 255)); GraphPlot_4 = new Graph(50, GraphType.Rolling, GraphPictureBox1.ClientRectangle, new Range(0, 255)); GraphPlot_5 = new Graph(50, GraphType.Rolling, GraphPictureBox1.ClientRectangle, new Range(0, 255)); GraphPlot_1.Color = Color.White; GraphPlot_2.Color = Color.Yellow; GraphPlot_3.Color = Color.Orange; GraphPlot_4.Color = Color.Red; GraphPlot_5.Color = Color.DodgerBlue; pannelControlList = new List <Tuple <ChannelId, Control> >(); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.GraphButton_1, graphButton1)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.GraphButton_2, graphButton2)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.GraphButton_3, graphButton3)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.GraphButton_4, graphButton4)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.GraphLabel_1, graphLabel1)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.GraphLabel_2, graphLabel2)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.GraphLabel_3, graphLabel3)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.GraphLabel_4, graphLabel4)); pannelControlList.Add(new Tuple <ChannelId, Control>(ChannelId.GraphLabel_5, graphLabel5)); arduinoport.MessageReceived += Arduinoport_MessageReceived; //GraphPanelClear(); foreach (var tuple in pannelControlList) { tuple.Item2.Visible = false; } PenColor1.Visible = false; PenColor2.Visible = false; PenColor3.Visible = false; PenColor4.Visible = false; PenColor5.Visible = false; }
private void ConnectArduino() { try { string Port = comPortList.GetItemText(comPortList.SelectedItem); ArduinoPort.PortName = Port; ArduinoPort.Open(); connected = true; ConnectBtn.BackColor = Color.Crimson; ConnectBtn.Text = "DISCONNECT"; StateLabel.Text = "CONNECTED"; StateLabel.ForeColor = Color.LimeGreen; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void comboBoxCOM_SelectedIndexChanged(object sender, EventArgs e) { var portName = ((PortDescription)comboBoxCOM.SelectedItem).Name; if (m_port != null) { if (m_port.PortName.Equals(portName)) { return; } ReleasePort(); } if (!portName.Equals(NO_CONNECT)) { m_port = new ArduinoPort(portName, BaudRate); m_port.ArduinoPinsAvailable += OnArduinoPinsAvailable; } }
static bool check_connection() { if (!ArduinoPort.IsOpen) { try { ArduinoPort.Open(); ArduinoPort.WriteLine("T"); ArduinoPort.Close(); } catch { MessageBox.Show("There was an error. Please make sure that the correct port was selected, and that the device is plugged in."); return(false); } return(true); } else { return(true); } }
public Motor this[Arduino arduino, ArduinoPort port] { get { return(motors[((int)arduino - 1) * 2 + (int)port]); } internal set { motors[((int)arduino - 1) * 2 + (int)port] = value; } }
public InfoForm(ArduinoPort port) { arduinoport = port; InitializeComponent(); arduinoport.MessageReceived += Arduinoport_MessageReceived; }
public void digitalWrite(ArduinoPort port, VoltageLevel level) { }
public RawSensor this[Arduino arduino, ArduinoPort port] { get { return(sensors[((int)arduino - 1) * 2 + (int)port]); } internal set { sensors[((int)arduino - 1) * 2 + (int)port] = value; } }
public static MotorPort MotorPort(this Arduino arduino, ArduinoPort port) { return((MotorPort)(((int)arduino - 1) * 2 + (int)port)); }
public static SensorPort SensorPort(this Arduino arduino, ArduinoPort port) { return((SensorPort)(((int)arduino - 1) * 2 + (int)port)); }
private async void BtnStart_Click(object sender, RoutedEventArgs e) { if (ExpStarted == false) { if (ArduinoPort.IsOpen) { ExpStarted = true; ArduinoPort.Write("1234"); BtnStart.IsEnabled = false; await Task.Delay(1500); BtnStart.Content = "Cancel"; BtnStart.IsEnabled = true; TxtStatusBrush.Color = Colors.Black; int Sum = 0; foreach (var item in ExpProgram.CycleItems) { Sum += item.CycleDuration; } TxtStatus.Text = $"Program has started... Total program time is {Sum} s"; BtnConnect.IsEnabled = false; BtnOpen.IsEnabled = false; BtnSendData.IsEnabled = false; MainMenu.IsEnabled = false; SpItems.IsEnabled = false; Boolean AnswerRecieved = false; Int16 GetCode = 0; await Task.Run(() => { while (!AnswerRecieved) { Task.Delay(100); if (ArduinoPort.BytesToRead > 3) { Int16.TryParse(ArduinoPort.ReadLine(), out GetCode); if (GetCode == 1604) { AnswerRecieved = true; } } } }); TxtStatus.Text = $"Program has been finished"; BtnStart.Content = "Start"; ExpStarted = false; TxtStatusBrush.Color = Colors.Black; BtnConnect.IsEnabled = true; BtnOpen.IsEnabled = true; BtnSendData.IsEnabled = true; MainMenu.IsEnabled = true; SpItems.IsEnabled = true; } } else { ArduinoPort.Write("1000"); BtnStart.IsEnabled = false; await Task.Delay(1500); BtnStart.IsEnabled = true; BtnStart.Content = "Start"; ExpStarted = false; TxtStatusBrush.Color = Colors.Black; TxtStatus.Text = "Experiment was terminated..."; BtnConnect.IsEnabled = true; BtnOpen.IsEnabled = true; BtnSendData.IsEnabled = true; MainMenu.IsEnabled = true; SpItems.IsEnabled = true; } }
public void pinMode(ArduinoPort port, PortDirection direction) { }
public ArduinoForm() { InitializeComponent(); ArduinoPort.Open(); }
public Arduino(string portName) { port = new ArduinoPort(portName); }
public void analogWrite(ArduinoPort port, byte voltage) { }
private void ArduinoPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { serialtxt = ArduinoPort.ReadLine(); //uitlezen serialport this.Invoke(new EventHandler(ShowData)); //doorzetten data uit serialport }
// Evento que toma los datos del puerto serie private void ReadPort(object sender, SerialDataReceivedEventArgs e) { string Data = ArduinoPort.ReadLine(); SetData(Data); }