Serial Port Woes
Sarah Reichelt
sarah.reichelt at gmail.com
Tue Jan 12 17:21:15 EST 2010
On Wed, Jan 13, 2010 at 1:40 AM, Len Morgan <len-morgan at crcom.net> wrote:
> I'm having a lot of trouble consistently reading a serial port. I'm trying
> to talk to a microcontroller using ModBus ASCII and the basic idea is to
> send a request for data (about 12 bytes) and then wait for an answer (about
> 300 bytes). There is between a 1/4 and 1/2 second delay from when I send
> the command and the controller STARTS sending it back.
>
> I also can't get it to work at all if I open it for update (either text or
> binary). I have to open the com port, send the command, then close the port
> and reopen it for read to get anything at all.
>
> I've tried "until linefeed", "until empty", "until eof", "for 1 line", etc.
> and none of them seem to work reliably. I KNOW that a response ends with a
> CRLF pair and there is only ever 1 "line" in a response so if I could just
> wait until I got the LF and it happened in say 3 seconds or less, I'd be
> happy.
Hi Len,
I have done a lot of work with serial ports, and although I always put
in lots of checks that close & re-open the port if there is an error,
this is not a normal occurrence.
Have a look at my serial test stack
<http://www.troz.net/rev/stacks/SerialTest.rev> which allows you to
configure the expected line endings as well as all the serial port
parameters. It sends data, and then constantly checks for incoming
responses from the serial device.
Cheers,
Sarah
More information about the use-livecode
mailing list