public void EnhancedSerialConnection_OpenAndDoubleClose() { var connection = new SerialConnection(); connection.Open(); connection.Close(); connection.Close(); }
public void SerialConnection_OpenAndClose() { var connection = new SerialConnection(); connection.Open(); connection.Close(); connection.Open(); connection.Close(); }
public void TearDown() { if (_serialConnection.IsOpen) { _serialConnection.Close(); } Thread.Sleep(200); }
public void SerialConnection_OpenAndDoubleClose() { if (!AreSerialPortsAvailable()) { return; } var connection = new SerialConnection(); connection.Open(); connection.Close(); connection.Close(); }
static void Main(string[] args) { try { var connection = new SerialConnection("COM5", SerialBaudRate.Bps_57600); var session = new ArduinoSession(connection, timeOut: 250); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; running = false; }; IFirmataProtocol firmata = (IFirmataProtocol)session; int led1 = 12; int led2 = 11; int led3 = 10; firmata.SetDigitalPinMode(led1, PinMode.DigitalOutput); firmata.SetDigitalPinMode(led2, PinMode.DigitalOutput); firmata.SetDigitalPinMode(led3, PinMode.DigitalOutput); while (running) { // led 1 Console.WriteLine("Turn on LED 1"); firmata.SetDigitalPin(led1, true); firmata.SetDigitalPin(led2, false); firmata.SetDigitalPin(led3, false); Thread.Sleep(1000); // sleep // led 2 Console.WriteLine("Turn on LED 2"); firmata.SetDigitalPin(led1, false); firmata.SetDigitalPin(led2, true); firmata.SetDigitalPin(led3, false); Thread.Sleep(1000); // led 3 Console.WriteLine("Turn on LED 3"); firmata.SetDigitalPin(led1, false); firmata.SetDigitalPin(led2, false); firmata.SetDigitalPin(led3, true); Thread.Sleep(1000); } // turn off LEDs firmata.SetDigitalPin(led1, false); firmata.SetDigitalPin(led2, false); firmata.SetDigitalPin(led3, false); connection.Close(); } catch (Exception err) { Console.WriteLine(err); } Console.WriteLine("Program exit. Press ENTER to close."); Console.ReadLine(); }
private void btnExecute_Click(object sender, EventArgs e) { try { var connection = new SerialConnection("COM5", SerialBaudRate.Bps_57600); var session = new ArduinoSession(connection, timeOut: 250); IFirmataProtocol firmata = (IFirmataProtocol)session; int redPin = 9; int greenPin = 10; int bluePin = 11; firmata.SetDigitalPinMode(redPin, PinMode.PwmOutput); firmata.SetDigitalPinMode(greenPin, PinMode.PwmOutput); firmata.SetDigitalPinMode(bluePin, PinMode.PwmOutput); firmata.SetDigitalPin(redPin, redVal); firmata.SetDigitalPin(greenPin, greenVal); firmata.SetDigitalPin(bluePin, blueVal); connection.Close(); } catch (Exception err) { MessageBox.Show(err.Message); } }
// Connect to the serial port private void btn_Connect_Click(object sender, EventArgs e) { if (port == null) { // Port is closed int baudrate = -1; try { baudrate = int.Parse(cmb_baudRate.Text); } catch { } if (baudrate < 0) { btn_Connect.BackColor = colorClosed; Program.errors.Add("Faulty baud rate."); } else { btn_Connect.BackColor = colorOpen; port = new SerialConnection(cmb_port.Text, baudrate, this); port.Open(); timerbuffer.Start(); } } else { // Port is open btn_Connect.BackColor = colorClosed; if (port.IsOpen()) { port.Close(); } timerbuffer.Stop(); } }
private void CloseConnection() { if (connection_ != null) { connection_.Close(); connection_.Dispose(); connection_ = null; } }
public void CloseConnections() { if (wsManager != null && wsManager.IsConnected) { wsManager.Close(); } if (spManager != null && spManager.IsConnected) { spManager.Close(); } }
private void trackBar1_Scroll(object sender, EventArgs e) { redVal = trackRed.Value; lbRed.Text = redVal.ToString(); UpdateColorPanel(); var connection = new SerialConnection("COM7", SerialBaudRate.Bps_57600); var session = new ArduinoSession(connection, timeOut: 250); IFirmataProtocol firmata = (IFirmataProtocol)session; int redPin = 10; firmata.SetDigitalPinMode(redPin, PinMode.PwmOutput); firmata.SetDigitalPin(redPin, redVal); connection.Close(); }
//////////////////////////////////////////////////////////////////////////////////// private void CloseConnection(SerialConnection connection) { if (connection != null) { if (connection == connection_) { connection_.Close(); connection_ = null; buttonConnect.Text = "Connect"; } } started_ = false; UpdateUI(); prevAltPos_.Clear(); prevTs_.Clear(); }
private void Form1_Load(object sender, EventArgs e) { try { var connection = new SerialConnection("COM7", SerialBaudRate.Bps_57600); var session = new ArduinoSession(connection, timeOut: 250); IFirmataProtocol firmata = (IFirmataProtocol)session; int redPin = 10; firmata.SetDigitalPinMode(redPin, PinMode.PwmOutput); firmata.SetDigitalPin(redPin, redVal); connection.Close(); } catch (Exception err) { MessageBox.Show(err.Message); } }
private void checkBox1_CheckedChanged_1(object sender, EventArgs e) { if (DigiP10.Checked) { DigiP10.Text = "On"; var connection = new SerialConnection("COM7", SerialBaudRate.Bps_57600); var session = new ArduinoSession(connection, timeOut: 250); IFirmataProtocol firmata = (IFirmataProtocol)session; firmata.SetDigitalPinMode(13, PinMode.DigitalOutput); firmata.SetDigitalPin(13, true); connection.Close(); } else { DigiP10.Text = "Off"; var connection = new SerialConnection("COM7", SerialBaudRate.Bps_57600); var session = new ArduinoSession(connection, timeOut: 250); IFirmataProtocol firmata = (IFirmataProtocol)session; firmata.SetDigitalPinMode(13, PinMode.DigitalOutput); firmata.SetDigitalPin(13, false); connection.Close(); } }
private void CloseConnection(SerialConnection connection) { if (connection == null) { return; } if (connectionAltAzm_ != null && connectionAltAzm_.connection_ == connection) { connectionAltAzm_ = null; ConnectionChangedAltAzm(); } if (connectionEqu_ != null && connectionEqu_.connection_ == connection) { connectionEqu_ = null; ConnectionChangedEqu(); } if (connectionGPS_ != null && connectionGPS_.connection_ == connection) { connectionGPS_ = null; ConnectionChangedGPS(); } // find and close old for (int i = 0; i < connectionList_.Count; ++i) { if (connectionList_[i].connection_ == connection) { connection.Close(); connectionList_.RemoveAt(i); break; } } }