From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with queues and serial communication

Hi,
 
Could you just verify that I've understand your code correctly?
 
As I understand it, the Producer Loop registers a change in position. This Enqueues value 14 of the enum and the value for the position. The Consumer loop goes to the Move to Absolute Position case and MOV A(position) is sent to the serial port. This behaviour is confirmed in the log table.
 
It's in the next step that I see a discrepency. From what I understand, the next event to occur is the Timeout. The first element to be enqueued is the default Get error code. The ERR? command should then be passed to the serial port but according to the log file, this command never goes.
 
It would be worth including some error handling to find out exactly what's happening at this point. Try probing the error input to the VISA Write in the Get Error Code case and the error output from the VISA Read and let me know what you're seeing.
 
Another thing to consider is the timing capability of the hardware you're using. Could you find out how much time it should take to respond to a query?
 
Also, if I've misunderstood your code, could you post some details of how it should be behaving.
 
Kind regards
Sarah
 
Applications Engineer | NI UK
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 11 of 27
(1,471 Views)

with no delay, here is what I mean by the program terminates on an indeterminate number of loops. It works for the first few MOV then POS query pairs, then it stops working permanently returning zero bytes.

I've tried all flow control  variations, including the recommended RTS/CTS and nothing is fixing this. Very confused.

 

0.00004665 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 11: MOV A1.125
0.00000307 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00467881 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 7: POS? A
0.00000391 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000698 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000726 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.00000670 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000559 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.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000670 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000615 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.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00001090 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000950 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 7: 1.1053
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000698 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00004833 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 11: MOV A1.187
0.00000279 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00053359 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.00000754 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000670 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.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000670 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  

...eventually times out
0 Kudos
Message 12 of 27
(1,465 Views)
... Actually I've just realised you press the scan button initially which reads the value of the postition. Let me look at it further...
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 13 of 27
(1,459 Views)

You've got it, timeout sends the ERR? command and the POS? A command just to keep track of what's going on. That works fine. I didn't include it because I'm limited to 5000 characters here.

The error occurs when I click on the Scan boolean. This enques the number of samples s on the front panel (x2 because there is also a query POS? A command for every MOV command). You can see this as the ScanOnOff value change event. This enqueues several hundred elements which are then dequeued by the consumer loop as quickly as possible. The fact that timeout might occur when these elements are being processed is not relevant, it just adds the timout elements to the end of the queue.

The error is occuring, according to LV, after the serial read function. But that is at odds with

1. What sysmon is telling me.

2. The fact that when rerunning the program, my device returns error 1 which corresponds to a syntax error (even though you can see from sysmon that the syntax is apparently unchanged!).

 

0.00004246 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 5: ERR?. 
0.00000279 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
...
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000810 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 2: 0
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00003548 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 7: POS? A
0.00000223 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000670 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
...
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 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.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000670 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000559 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00001117 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000978 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 7: 4.5171

0 Kudos
Message 14 of 27
(1,455 Views)
Also, it doesn't matter how long the device takes to respond to the data. I've told serial read to wait for 100 bytes or the termination character (LF), whichever comes first.  In fact it's always LF because the response is only a few (<10) bytes. The timeout is 2s, any message takes a fraction of a second. 
0 Kudos
Message 15 of 27
(1,452 Views)
so the Producer Loop Enqueues value 14 then value 20 of the enum. The consumer loop dequeues this data and goes to the Move to Absolute Position case. This writes MOV A(number) to the port. Then the case moves to Read Actual Position where POS? A is writen to the port and the VISA Read tries to read the data back. The code is hanging at the VISA Read VI. It keeps trying to read the data back and it won't terminate untill it gets something (or it times out!).
 
Could you try testing just the VISA Write and VISA Read VIs (away from the producer consumer loop) with just those two commands (MOV and POS?) and see if you can recreate the error.
 
And I could still do with the timing info on the hardware you're using.
 
Sarah
 
Applications Engineer | NI UK
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 16 of 27
(1,451 Views)

The only thing that has occurred to me is the following

0.00004414 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 11: MOV A1.249. 
0.00000279 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00053247 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 7: POS? A. 
0.00000279 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  

The program always falls down when two writes are back to back as quickly as possible, Could it be that the flush_buffers command is not actually clearing the memory properly before the POS? A command is being written, resulting in a corrupted message being sent to the device?

...but then why would portmon say that POS? A has been written successfully?

Smiley Sad

0 Kudos
Message 17 of 27
(1,445 Views)
OK, I'm going to take a step back and try and figure this out as I've tripped over myself with a few posts!!
 
I will need some more information to try and get the full picture though. Could you post the details of your hardware as well as attaching a copy of the two Portman files, one with the time delay, one without. I think you're right in thinking that the delay shouldn't make a difference but I'd like to examine what's actually happening.
 
I'm sure we'll figure it out, we just need a bit of perspective!
 
I still think it's work trying the offending piece of code independent of the P/C structure. Give it a go and let me know how it goes.
 
Best of luck!
Sarah
 
Applications Engineer | NI UK
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 18 of 27
(1,442 Views)
You've got it right.

I can't find any info about how long it normally takes to respond to a command. All I have is the baud rate, flow control, stop bits, etc as set up on the configure serial. Surely the point is that it is less than 2s, the timeout?
 
I'm running out of time today, let me try and quickly do the same without queues!
0 Kudos
Message 19 of 27
(1,437 Views)
Hi Sarah,
I've removed the enqueue stuff that happens when the Scan boolean is changed. It's now a simple while loop that executes when this button is clicked. It's attached (sorry about the mess, I'm normally tidier than this!). The same error occurs:
 
0.00004051 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 11: MOV A1.685
0.00000279 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00495566 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 7: POS? A
0.00000251 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00001034 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000782 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00001397 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00001173 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 7: 1.6692
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00005084 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 11: MOV A1.729
0.00000307 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00076490 LabVIEW.exe IRP_MJ_WRITE Serial0 SUCCESS Length 7: POS? A
0.00000307 LabVIEW.exe IRP_MJ_FLUSH_BUFFERS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000726 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000615 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IRP_MJ_READ Serial0 SUCCESS Length 0:  
0.00000587 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
0.00000643 LabVIEW.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS  
... timeout
 
And it's a VISA read error after the serial read.vi
 

 
0 Kudos
Message 20 of 27
(1,433 Views)