serialControlString
Dar Scott
dsc at swcp.com
Mon Nov 24 16:44:03 EST 2003
On Monday, November 24, 2003, at 09:30 AM, Thomas J McGrath III wrote:
> below is the response from the creator of the MacBrick:
> I don't know how to send a hex number or how to receive a dot.
>
> When sending a <V000(version number) to the device I do see the green
> light on the device blink and the driver does show up in the menu in
> SerialTest.
...
>> It is best if you precede each command with an escape char (hex 27).
>> This will draw MacIO's attention. MacIO will respond with a . (dot).
>> After receiving the dot, or shortly after sending the esc char
>> (microseconds), you can send your command.
>> The Command "<V000" should indeed provide you with a response,
>> unless the number of byets sent to MacIO is incorrect. (the demo app
>> shows the commands it outputs to MacIO, so you can easily check this,
>> but I think 5 chars is indeed the command length).
When experimenting, check and report result() every time you do serial
I/O.
Tom has a typo, I think. The escape character (ESC) is 27 decimal and
1B hex. You can send it like this:
write numToChar(27) to driver "/dev/cu.usbserial-3B1"
There are several ways you can read the dot. I think that is simply
the period character.
You can do this in an experiment:
read from driver "/dev/cu.usbserial-3B1" for one character
The character read will be in it. The read might fail, though.
I would rather do this:
read from driver "/dev/cu.usbserial-3B1" until empty
That will return right away and will get whatever was received already
and in the buffer. You will need to have a delay and you can put them
into a loop. That might be in an outer loop that checks for the dot.
(Later, when you learn about send, use that.)
You might want to put that at the start before sending the ESC to clear
the buffer.
After getting the dot, do this:
write ">V000" to driver "/dev/cu.usbserial-3B1"
Then read until you get the data you want.
I have found that on OS X the write needs to end in a LF with the
serial drivers I use. I think this is a Revolution bug. A LF after
the ESC might botch the command, though. If it does, try sending the
ESC and command as a single string with a LF at the end, maybe with two
ESC at the start. If you are having trouble on OS X, try variations of
this:
write numToChar(27) & numToChar(27) & ">V000" & LF to driver
"/dev/cu.usbserial-3B1"
Dar Scott
More information about the use-livecode
mailing list