LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with queues and serial communication

I'm having a problem when using queues to handle serial communication. I've attached a VI (sorry it's a bit of a mess).
 
Basically the issue I've found is that when I run the dequeue loop with no delay, it stops execution after typically a few iterations with a serial read timeout error. Adding a delay of 50ms into the loop gives the expected execution.
 
What am I missing?
 
As a diagnostic, I get a "syntax error" from my device with no delay, yet no "syntax error" with a 50ms delay. Am I attempting to write the values too quickly to the port and it's getting scrambled?

Thanks in advance
 
0 Kudos
Message 1 of 27
(5,121 Views)
It sounds like timing is your issue. Without any delay, a loop will try to run as quickly as the CPU will let it. Even adding a small amount of timing will stabilise execution.
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 2 of 27
(5,040 Views)
Here are some resources that expain the principle behind loop timing:
 
 
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 3 of 27
(5,038 Views)

Thanks for your response.

The while loop in this programme only executes when a queue element is available, so it does not hog resources in the same way a free running while loop would. I don't know why timing is important in this case - I am happy for the while loop to dequeue elements as quickly as possible, that's the point of using asynchronous queue handling after all.

If you can provide a specific answer to this I would be very happy!

0 Kudos
Message 4 of 27
(5,032 Views)
Could you give me some more details on the error your getting? Is there an error code or anything?
 
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 5 of 27
(5,027 Views)
>serial read timeout error
0 Kudos
Message 6 of 27
(5,024 Views)

Hi,

I've tried running your code but I'm missing the enumerated control "PI-E-816Commands". Could you post that please? Also, what hardware are you using?

Where does the error typically occur? Is it at the same VI each time or is it only in certain cases?

Could you have a look at the following knowledge base that has a section on common serial problems. The "Timing in Program, Hanging" looks similar to the error you're seeing.

Try using the Bytes at Serial Port VI as suggested and see if that makes a difference.

Good luck,
Sarah
 
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 7 of 27
(5,011 Views)

 

The programme hangs after an indeterminate number of loops, typically a few, but it doesn't seem to be repeatable.

I don't think it's a common serial error, I'm familiar with those. I've used the Bytes at Serial Port. When it hangs, there are no bytes at the serial port, apparently because the Serial Write has been corrupted (that's what I meant by the fact that my instrument returns a "syntax error" when it hangs, because it hasn't received a properly constructed query). So it's not the classic of waiting for too many bytes, missing a termination character, etc.

I think it's a subtelty about when visa write returns control. Just guessing though.

0 Kudos
Message 8 of 27
(5,008 Views)
Could you try the following?
 
Here is a link to some software that monitors the serial port activity on a system. If you download this and run it with your code without time delay and then with the time delay.
 
That should give us an idea if the problem is down to timing or if there's something else we need to look into:
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 9 of 27
(5,003 Views)

No delay

0.00005392 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 11: MOV A1.000. 
0.00000279 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000670 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00067131 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 7: POS? A
0.00000279 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000838 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  

I move the device to position 1.000 then query its position. There are no bytes in the input buffer, and the program keeps returning zero bytes until the serial read time out occurs.

 

50ms delay

0.00004805 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 11: MOV A1.969. 
0.00000251 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00001173 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00004498 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 7: POS? A
0.00000279 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000810 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
... 
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000559 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000866 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000810 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 7: 1.9679

I ask it to move to position 1.969, then I query the position and after a few serial read calls, it eventually gets 7 bytes in the buffer and returns them to my program.

I'm now really confused, it  seems to be that the POS? A query works fine with a delay, but not without a delay in which case the buffer is always empty. Any ideas?

0 Kudos
Message 10 of 27
(4,999 Views)