# Using a Serial port. Can processing boot even if the port is un available

**URL:** <https://discourse.processing.org/t/using-a-serial-port-can-processing-boot-even-if-the-port-is-un-available/23041>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [August 4, 2020, 9:30pm UTC](https://discourse.processing.org/t/using-a-serial-port-can-processing-boot-even-if-the-port-is-un-available/23041 "2020-08-04T21:30:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [August 4, 2020, 9:30pm UTC](https://discourse.processing.org/t/using-a-serial-port-can-processing-boot-even-if-the-port-is-un-available/23041/1 "2020-08-04T21:30:00Z")

</div>

I would want to be able to boot the sketch even if the USB cord is unplugged to my arduino.  
Eventually I would write a message “COM Not Available” and maybe make a button to re-connect.

But Processing will stop in the setup.

So I tried:

```auto
 void setup(){
  size(400, 300, JAVA2D);

  
  //myPort0 = new Serial(this, "COM4", 9600);
  printArray(Serial.list());
  
  if (Serial.list().length > 0)
  {
  myPort = new Serial(this,Serial.list()[0], 9600);
  myPort.bufferUntil(lf); 
  //myPort = new Serial (this, "/dev/tty.wchusbserial5d10", 115200);
   myPort.clear();
  }
  else
  {myPort.stop();
  }
  
 
  f = createFont("Arial",46,true);
  
 
}

```

But no boot.  
Please help,  
Thanks

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 4, 2020, 10:06pm UTC](https://discourse.processing.org/t/using-a-serial-port-can-processing-boot-even-if-the-port-is-un-available/23041/2 "2020-08-04T22:06:40Z")

</div>

Try and catch this:

> [@Problem with the use of several sensors, Arduino / Processing](https://discourse.processing.org/t/problem-with-the-use-of-several-sensors-arduino-processing/18118/5):
>
> Hello, Some code I wrote to explore Arduino transmitting data to Processing. It runs fine at a BAUD rate of 1000000. slight_smile I use an Arduino MEGA 2560 R3. 
> 
> > **Arduino Code**
> >
> > // Serial Incoming Test (Arduino Tx) // v1.0.0 // GLV 2020-02-29 long count; void setup() { //Serial.begin(9600); Serial.begin(1000000); delay(1000); Serial.print('\n'); //same as Serial.println() Serial.print("incoming"); Serial.print('\n'); //same as Serial.println() } void loop() …

`:)`

---

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [August 5, 2020, 12:48am UTC](https://discourse.processing.org/t/using-a-serial-port-can-processing-boot-even-if-the-port-is-un-available/23041/3 "2020-08-05T00:48:10Z")

</div>

Thanks a lot, that was clever, making a bool and conditioning everything on that.

I wrote something like,

```auto
if (Serial.list().length > 0)
  {
    serialConnect =true;
    myPort = new Serial(this, Serial.list()[0], 9600);
    myPort.bufferUntil(lf); 
    //myPort = new Serial (this, "/dev/tty.wchusbserial5d10", 115200);
    myPort.clear();
  } else
  {
    serialConnect =false;
  }

```

And then only listen to the serial port if the Serialconnect boolean is true.

Thanks a lot, Learned something new.
