Check whether Arduino is connected via Serial( USB) with the Help of the Serial library
in
Core Library Questions
•
7 months ago
HI,
I have programmed a gui and I want to realize a button that checked, if the arduino is connected to the pc via USB(serial) and I used the Serial library.
When the Arduino is connected so it will pop up a window with the message OK, if the arduino isn't connected so it will pop up a window with "failed".
But I have a problem to realize this, because I don't know, if there are a function to check all the ports whether the arduino is connected.
I programmed this with the available() but this doesn't work see here:
- import processing.serial.*;
Serial myPort;
void check_connection_click() // This is the event when i press the button Check connection
{
myPort= new Serial(this, Serial.list()[0], 9600);
if (myPort.available()==4)
{
connection_ok.setVisible(true);
}
else {
connection_failed.setVisible(true);
}
So but this is not what I want, I would like to recognize whether my arduino is connected via usb( don't care which port), to my pc, is it possible?
Thanks a lot .
1