COM streams

43 views
Skip to first unread message

David Meyer

unread,
Mar 9, 2012, 6:29:01 PM3/9/12
to js...@googlegroups.com
Hi,

I'm trying to interface with a COM port, and have thus opened a stream to a COM port using:

S = new Stream('com1://115200');

At this point, I can do S.write, and I can sometimes S.readln(), but not always, so I have a few questions

1) Is there any way to detect whether or not a COM port is available?
2) I read in the documentation that COM streams are not buffered... but how does the system handle a constant stream of data if I'm not reading it?

Also, I always get that S.eof is true, and S.canRead is false.  If someone could clear up what's happening, that would be great.

Thanks!

Shanti Rao

unread,
Mar 9, 2012, 10:57:59 PM3/9/12
to js...@googlegroups.com
Hi David,

Buffering is done by the UART chip and the operating system. JSDB does not do any additional buffering. How the buffer state gets reported to JSDB therefore varies and I'm sorry for the trouble, but I and many others have gotten serial io to work, so don't give up.

If you call s.read(1), you are supposed to get an empty string if there is no input queued. ( note convention: variables start with lower case letters) so you should be able to call s.read(1) until you either read a newline or decide to give up.

Some serial equipment still perversely thinks \r or \0 is a line terminator. JSDB only looks for \n. try s.readInt8() to debug.

eof() is meaningless for a serial port of course, but canRead() used to work on windows and Linux, so feel free to take a look at the source file (rs/io_comm.cpp) and let me know if you see anything suspicious.

Shanti

Dorijan Jelincic

unread,
Apr 13, 2012, 5:45:14 AM4/13/12
to JSDB
Hi to all..
I am also having trouble with canRead, maybe I am doing something
wrong?
here is my code:

var S=new Stream('com1://9600');
this.running = true
while (this.running)
{
//system.gc()
sleep(10);
if (S.canRead) {
inByte=S.readByte();
writeln(inByte.toString(16));
} else{
write (".");

}

}

thank you...
I am using this on windows 7, 64 bit, but planning to use it on linux
to..
Reply all
Reply to author
Forward
0 new messages