Pharo: reading a byte from an Arduino serial port

I have an Arduino hanging / dev / ttyUSB 1 communicating in 115kbaud. The instructions below are great for the next method call where Pharo hangs. Arduino responds to the "99" command by sending one $ 1 character back to the computer. If I pull out the cable, the program will continue, and s will contain the character $ 1, as it should, but until I pull out the cable. Therefore, it seems to me that next 'does not return after it reads only one byte (well, of course, there is nothing that says that it should return after reading one byte). How can I read one byte from a stream in Pharo? Or how to open a stream of read / write bytes? I did not find anything in the source classes that seem to do this. I tried setting the stream to ascii, to binary, to text, and it does not change the behavior.

s := FileStream oldFileNamed: '/dev/ttyUSB1'.
s readWrite.
s nextPutAll: '99'. "'99' is successfully received by Arduino"
s next.             "hangs here"
s close.

Thanks for your help.

+4
source share
2 answers

Take a look at the side of the FileStream class. There you will notice that you get a MultiByteStream (specific stream) when you request a Filestream for oldFileNamed :. A TextConverter or buffer may be involved. open: forWrite: from MultiByteStream is called, and it calls super. StandardFileStream> open: forWrite: calls enableReadBuffering.

You probably want to call disableReadBuffering in your thread.

+1
source

There is an Arduino package in which all these problems are resolved, look at this repo:

http://ss3.gemstone.com/ss/Arduino.html

+1
source

All Articles