Write and read to Serial port at the same time

#1

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

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.

#2

Also, I tried this code and … nothing happened.
https://processing.org/reference/libraries/serial/Serial_readBytesUntil_.html

#3

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 )

#4

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).

#5

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??

#6

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.

#7

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