# Write and read to Serial port at the same time

**URL:** https://discourse.processing.org/t/write-and-read-to-serial-port-at-the-same-time/11056
**Category:** Electronics (Arduino, etc.)
**Created:** [May 9, 2019, 8:19am UTC](https://discourse.processing.org/t/write-and-read-to-serial-port-at-the-same-time/11056 "2019-05-09T08:19:50Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![anikolenko](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@anikolenko](https://discourse.processing.org/u/anikolenko)
#### Post date: [May 9, 2019, 8:19am UTC](https://discourse.processing.org/t/write-and-read-to-serial-port-at-the-same-time/11056/1 "2019-05-09T08:19:50Z")

</div>

Hi guys,  
I’m trying to understand how the Serial port works. Can anyone answer me why the following code does not work?

```auto
import processing.serial.*;
Serial port;

void setup()
{
   port = new Serial(this, "COM1", 9600);
   port.write(65);
}

void draw()
{
  if (port.available() > 0) {
         
    int inByte = port.read();
    println(inByte);
  }

```

I have nothing in my console. It looks like port.available() always returns 0.Why?  
Thanks.

---

<div class="post-metadata">

### Author: ![anikolenko](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@anikolenko](https://discourse.processing.org/u/anikolenko)
#### Post date: [May 9, 2019, 8:36am UTC](https://discourse.processing.org/t/write-and-read-to-serial-port-at-the-same-time/11056/2 "2019-05-09T08:36:21Z")

</div>

Also, I tried this code and … nothing happened.  
[https://processing.org/reference/libraries/serial/Serial\_readBytesUntil\_.html](https://processing.org/reference/libraries/serial/Serial_readBytesUntil_.html)

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [May 9, 2019, 8:45am UTC](https://discourse.processing.org/t/write-and-read-to-serial-port-at-the-same-time/11056/3 "2019-05-09T08:45:03Z")

</div>

hi,  
first point is:

- what is connected to the serial port COM1 and
- is it sending text and
- is it sending with com speed 9600Bd?

if you programmed like a arduino device  
please also show that code FORMATTED using `</>`  
also prior to test processing serial start in arduino IDE the MONITOR  
and copy the incoming string to here ( also formatted as code )

---

<div class="post-metadata">

### Author: ![anikolenko](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@anikolenko](https://discourse.processing.org/u/anikolenko)
#### Post date: [May 9, 2019, 8:58am UTC](https://discourse.processing.org/t/write-and-read-to-serial-port-at-the-same-time/11056/4 "2019-05-09T08:58:45Z")

</div>

I thought COM1 is a virtual port. When I get info about COM1 throught cmd I see this port is available (when this processing app is not running).

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [May 9, 2019, 9:15am UTC](https://discourse.processing.org/t/write-and-read-to-serial-port-at-the-same-time/11056/5 "2019-05-09T09:15:30Z")

</div>

and even if it would be a virtual port, what would be the use? you expect in your code incoming string on that port with that speed,

can you give some more words what you are about to do??

---

<div class="post-metadata">

### Author: ![anikolenko](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@anikolenko](https://discourse.processing.org/u/anikolenko)
#### Post date: [May 9, 2019, 9:56am UTC](https://discourse.processing.org/t/write-and-read-to-serial-port-at-the-same-time/11056/6 "2019-05-09T09:56:42Z")

</div>

I have code for sending data to Arduino through COM. But I want to see somehow what I have at this time in the serial port after sending data.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [May 9, 2019, 10:05am UTC](https://discourse.processing.org/t/write-and-read-to-serial-port-at-the-same-time/11056/7 "2019-05-09T10:05:53Z")

</div>

if you work with arduino i not think your emulation with virtual ports is needed.

you make a arduino code what ECHO the received string.

-a- and that you can test in the arduino IDE Monitor: type some text, press enter and arduino should send it back. after that test  
-b- try same from processing with a  
[https://processing.org/reference/libraries/serial/serialEvent\_.html](https://processing.org/reference/libraries/serial/serialEvent_.html)
