Read from driver 1 lines twice not same as 2 lines

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
see3d
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 15
Joined: Tue Apr 11, 2006 12:07 am
Location: Weaverville, NC

Read from driver 1 lines twice not same as 2 lines

Post by see3d » Tue Apr 02, 2019 2:54 am

Hi,

I am trying to optimize my read commands from a 3D printer USB serial device. I must not understand how the read from driver works. I open the driver like this:

open driver line 1 of field "Printer Path" for text update

I can then read and write to the device. However, I want to read the input from the device one line at a time, but reading that way, it drops data compared to reading all the lines at once.

I send a line to the device with a command, then wait for a response. The response may be one line or several lines, but it always ends with a line that has "ok" in it.

I read from it like this:

read from driver line 1 of field "Printer Path" for 1 lines in 1 seconds

This always works if there is only one line (and it has "ok" in it).

read from driver line 1 of field "Printer Path" for 2 lines in 1 seconds

Works with 1 or 2 lines with the last line having the "ok"

However, doing this:

read from driver line 1 of field "Printer Path" for 1 lines in 1 seconds
put it into someWhere.
read from driver line 1 of field "Printer Path" for 1 lines in 1 seconds
put it into someWhereElse.

Will not get the second line with the "ok" in it. I have tried everything I know of to figure out why the two ways do not read the 2 lines of input the same. It is like if there are two lines waiting in the interface, and I read one of then, it throws the second line away.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6030
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Read from driver 1 lines twice not same as 2 lines

Post by dunbarx » Tue Apr 02, 2019 2:06 pm

Hi.
read from driver line 1 of field "Printer Path" for 1 lines in 1 seconds
put it into someWhere.
read from driver line 1 of field "Printer Path" for 1 lines in 1 seconds
put it into someWhereElse.
If you invoke the same "read" command twice, you will not access the second line. How would LC know that you wanted to? The command:
read from driver line 1 of field "Printer Path" for 2 lines in 1 seconds
Does just what you want, and you can then place each line wherever you wish, no?


Craig Newman

see3d
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 15
Joined: Tue Apr 11, 2006 12:07 am
Location: Weaverville, NC

Re: Read from driver 1 lines twice not same as 2 lines

Post by see3d » Tue Apr 02, 2019 3:54 pm

dunbarx wrote:
Tue Apr 02, 2019 2:06 pm
Hi.

If you invoke the same "read" command twice, you will not access the second line. How would LC know that you wanted to?
Craig Newman
LC should not get confused. If I read 1 line from a file in a loop, LC will keep giving me the next line in the file. The same for a serial input stream. It reads out one line from the buffer and deletes that line from the buffer, then goes to the next line in the buffer. It is called a FIFO buffer.

In this case it appears to read one line then flush the whole FIFO buffer instead of just deleting the part it read.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6030
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Read from driver 1 lines twice not same as 2 lines

Post by dunbarx » Tue Apr 02, 2019 4:54 pm

Ah, so similar to the "read from file" command, where LC remembers the place where the most recent "read" or "write" process ended.

But though you mention the string "OK", you do not explicitly include it the "until string" parameter in the command. Are there two issues here?

In any case, is it possible that explicitly setting the "amount" parameter limits the read to "1 lines", and thus prevents LC from setting an index, so it just reads the same first line over and over? In other words, what I posited above?

Never used this command, so just wondering...

Craig

Post Reply

Return to “Mac OS”