11-03-2009 12:25 PM
@RTSLVU: I think the problem is, that the time is needed by the controller to switch its mode. In Hyperterminal it doesn't send a message after switching at all... so I don't know if there will be bytes arriving...
11-03-2009 12:44 PM - edited 11-03-2009 12:46 PM
RTSLVU wrote:Instead of hard wait times I suggest you use the "bytes at port" to wait just long enough to get the data.
My example shows waiting until the byte coult is not=0 but if you know the exact amount of bytes and it's always going to be the same change it to wait until you get that byte count.
You can adjust the loop delay if needed too.
Not a good idea.
Suppose your incoming message is expected to be 10 bytes. You wait unti the bytes at port != 0. Suppose only 1 byte as arrived at the instant you check that property node. Now the loop ends, you read only the 1 byte. The other 9 that make up the message get left hanging in the serial port and you return with an incomplete message.
I find that relying on bytes at port is very rarely the correct solution for a serial communication scheme.
You could wait for bytes at port not equal to zero. But don't use that number for the bytes to read. Use the expected number of bytes or a sufficiently large number of bytes and the termination character to end the read. But even if you do, you should probably still have a timeout mechanism in your waiting loop so you don't cause your program to freeze waiting for bytes that may never arrive due to some reason such as a disconnected serial cable.
11-03-2009 12:50 PM - edited 11-03-2009 12:53 PM
Ravens Fan wrote:
RTSLVU wrote:Instead of hard wait times I suggest you use the "bytes at port" to wait just long enough to get the data.
My example shows waiting until the byte coult is not=0 but if you know the exact amount of bytes and it's always going to be the same change it to wait until you get that byte count.
You can adjust the loop delay if needed too.
Not a good idea.
Suppose your incoming message is expected to be 10 bytes. You wait unti the bytes at port != 0. Suppose only 1 byte as arrived at the instant you check that property node. Now the loop ends, you read only the 1 byte. The other 9 that make up the message get left hanging in the serial port and you return with an incomplete message.
I find that relying on bytes at port is very rarely the correct solution for a serial communication scheme.
Intresting, I have been using varations of this method for years without instance...
11-03-2009 12:53 PM
Andband wrote:@RTSLVU: I think the problem is, that the time is needed by the controller to switch its mode. In Hyperterminal it doesn't send a message after switching at all... so I don't know if there will be bytes arriving...
I guess I do not understand your last diagram. It's loos to me like you are sending mod=d then waiting for data (but I do not know what is inside your read vi), then sending another command and waiting for data...
You can always add a time out or change the amount of data to wait for (an exact number not just not=0)
11-03-2009 01:18 PM
Within read vi there is just a visa read, to catch up the echo of my mod=d,
a visa write "get+ENTER"
a visa read to catch the echo of get
and a visa read to catch the actual data (see picture)
What I wanted to say was, that I think the controller I am talking to just needs some time to execute the change of the mode. And I don't know if he will send a message if he is ready again. I don't think so.
So I thought furthermore, before I ask for the controller the data I give it some time. For example if I change the counter to 1000 the mode-change won't work correctly anymore.
11-03-2009 01:31 PM
so no, I am not waiting for data with mod=d or mod=h . It is just to change the mode of the controller (the data will be acquired with 'get')