how to read from a serial port?

Blitz3D Forums/Blitz3D Programming/how to read from a serial port?

pimpom(Posted 2010) [#1]
Hello, I'm trying to find a way to read from serial ports, so far found some dead links and also some information on writing to a specific port.

Is there a library used or no one is interested now in reading ports?

I want to read input from external device (arduino).


Warner(Posted 2010) [#2]
Just do a search on "serial port blitzbasic" from Google. This post came up:
http://www.blitzbasic.com/Community/posts.php?topic=50302


jfk EO-11110(Posted 2010) [#3]
Additionally you may be able to use the old MS-DOS Stream handles, as far as I recall it was something like

r=readfile("COM1")
repeat
print readbyte(r)
until EOF(r)
closefile r

So you see, a simple filehandle can be used to read from to serialport (and also from parallelport, for example).

There may be some examples around, eg. here one in qbasic:
http://www.pacifier.com/~mcginty/qbstamp.htm

Something like

re=readfile("com1:9600,n,8,1,CD0,CS0,DS0,RS")

may be used to use a certain setting, where:
' OPEN "com1:9600,n,8,1=9600 b/s, no parity, 8 data bits, 1 stop bit.
' ,CD0 = zero milliseconds timeout on the data carrier detect line (DCD)
' ,CS0 = zero milliseconds timeout on the clear to send line (CTS)
' ,DS0 = zero milliseconds timeout on the data set ready line (DS)
' ,RS" = suppress detection of request to send (RTS)

Details are part of any good MS-DOS documentation.
Have to say: I don't know how long this Dinosour is going to be supported anymore.


pimpom(Posted 2010) [#4]
Thank you very much.

Now I can read my potentiometer, what I did noticed is that it doesn't reads as fast as in the arduino ide, but doing some checks in arduino (if values had changed send data, else don't) now it's more usable.

Just for the record, this is the solution I ended up using:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1383

Thanks again.


Charrua(Posted 2010) [#5]
Have in mind that if you are working in blitz at 60 fps, and call to read form the serial port in each loop, you are reading 60 times a second the port and your board may send more than that. You have to have a way to read as much that has been received in between each frame.

Also have in mind the time out, say, the time the function wait for some data before give up. This should stop your program if no data is available.

Juan