LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

queue/dequeue issues

Solved!
Go to solution

Guys,

 

I'm adapting some LV code to the next iteration of our PIC program that sends data much more quickly.  In order for the LV code to keep up, I decided I needed a producer/consumer structure so that the processing of the data read from the serial port can be processed at its own pace (see attached code).  The 'read' only switches on when a notifier from a 'write' loop tells it to.  

 

The issue I'm having is that I want an entire line of text to be queued up to the '\n' and for that same entire line to be de-queued in the consumer loop.  It seems simple, but the devil appears to be in the details.  Right now, only partial lines appear to be queued and dequeued.  I've tried adding a property node that tells the VISA read to read up to the '\n', but I'm not sure if that helped.  I think, also, that the consumer loop is still slaved to the producer loop in terms of how fast it iterates.  Is there any way to queue an entire line of text at once and de-queue it the same way at its own pace?  The number of bytes in a line varies, so I can't use that method.

0 Kudos
Message 1 of 10
(3,356 Views)
Could you grab it one character at a time until you get a \n?  Just a quick thought ...
-Matt Bradley

************ kudos always appreciated, but only when deserved **************************




Message 2 of 10
(3,335 Views)
I'm not quite sure what you mean.  Can you post a 'VISA read' picture showing how to do that?
0 Kudos
Message 3 of 10
(3,326 Views)

Hi,

 

Just look at the attachments and its how you can ensure enqueue of complete string.

Message Edited by JK1 on 05-28-2009 09:47 PM
With regards,
JK
(Certified LabVIEW Developer)
Give Kudos for Good Answers, and Mark it a solution if your problem is solved.
0 Kudos
Message 4 of 10
(3,322 Views)
Solution
Accepted by topic author PRCalDude

Some issues with your code.

 

1.  Your VISA reads has the enum value of TermChar going into the number of bytes to read.  That doesn't make sense.  It is looking for a number not an enum.  That is why there is a coercion dot.  The value of TermChar is actually 2, so you read 2 bytes.  You have a property node there to tell you the number of bytes at the port, but you don't use it.

 

2.  Your upper while loop will never stop because you have a False constant wired to the loop terminal.  The only way to stop this program is to Abort it.

 

3.  You never release the "GO" notifier you created in the top loop and middle loop.

 

4.  Why do you have the word "INOP" on your Stop buttons?  Also, it is more desirable to have a single Stop button that stops the whole program rather than having to hit multiple stop buttons for each individual loop.

 

 

 

JK1,

 

Wouldn't it be easier (since the termination character is enabled and is the default of \n) to just read a sufficiently large number of bytes, larger than any number of bytes you'd ever expect to receive in a message.?

 

A VISA read terminates in one of 3 ways.

1.  When the requested number of bytes have been read.

2.  The termination character (if enabled) has been received.

3.  The timeout has occurred before #1 or #2 have happened.

Message Edited by Ravens Fan on 05-28-2009 10:52 PM
Message 5 of 10
(3,318 Views)

Hi,

 

Ya dint notice the termination character enabled.  So "bytes at port" can be conviniently used to gather all the bytes in buffer and check its integrity and enque it.

 

Ravens: Thank you for pointing out tht.

With regards,
JK
(Certified LabVIEW Developer)
Give Kudos for Good Answers, and Mark it a solution if your problem is solved.
0 Kudos
Message 6 of 10
(3,307 Views)

Ravens Fan wrote:

Some issues with your code.

 

1.  Your VISA reads has the enum value of TermChar going into the number of bytes to read.  That doesn't make sense.  It is looking for a number not an enum.  That is why there is a coercion dot.  The value of TermChar is actually 2, so you read 2 bytes.  You have a property node there to tell you the number of bytes at the port, but you don't use it.

 

2.  Your upper while loop will never stop because you have a False constant wired to the loop terminal.  The only way to stop this program is to Abort it.

 

3.  You never release the "GO" notifier you created in the top loop and middle loop.

 

4.  Why do you have the word "INOP" on your Stop buttons?  Also, it is more desirable to have a single Stop button that stops the whole program rather than having to hit multiple stop buttons for each individual loop.

 

 

 

JK1,

 

Wouldn't it be easier (since the termination character is enabled and is the default of \n) to just read a sufficiently large number of bytes, larger than any number of bytes you'd ever expect to receive in a message.?

 

A VISA read terminates in one of 3 ways.

1.  When the requested number of bytes have been read.

2.  The termination character (if enabled) has been received.

3.  The timeout has occurred before #1 or #2 have happened.

Message Edited by Ravens Fan on 05-28-2009 10:52 PM

Ravens,

 

The 'INOP' buttons are the 'Stop' buttons for the individual while loops.  What I really need to do is put the whole thing inside the first "error/no error" case structure inside of an even structure that waits for a single 'Stop' button to be pushed and then stops all loops as well as sends a 'S\r\n' string to the PIC.  That's on my 'to-do' list. Proper stopping of VIs is not something I'm good at yet.

 

I'll fix the "GO" notifier also.  

 

I didn't realize I had wired an 'enum' to the VISA read.  I tried creating a property node that looks for the term char, but I'm not sure if that's necessary given that I enabled a term char when I initialized the serial port.  If I wire a "bytes at port" property node to the read, will it still only grab one line because of the term char enable?  It seems like it'll read whatever number of bytes I tell it to read, whether or not I have the term char enabled.  This isn't clear at all in the help files or anything I've read. 

 

 

0 Kudos
Message 7 of 10
(3,265 Views)

JK1 wrote:

Hi,

 

Just look at the attachments and its how you can ensure enqueue of complete string.

Message Edited by JK1 on 05-28-2009 09:47 PM

Do you think you could re-post that in LabView 8.5?

0 Kudos
Message 8 of 10
(3,264 Views)

PRCalDude wrote:

 

The 'INOP' buttons are the 'Stop' buttons for the individual while loops. 

 


Then why not label the buttons "Stop"?  It would be clearer to an operator.   Or does the word "INOP" mean stop in another language?

 

Here is JK1's VI saved back to LV8.0

Message Edited by Ravens Fan on 05-29-2009 10:34 PM
0 Kudos
Message 9 of 10
(3,248 Views)

Ravens,

 

Thanks a lot.  I wired a constant of 256 to the read statement and it started grabbing and enqueueing entire lines just the way I wanted.  I removed the 'bytes at port' property node.

 

 I'm going to set about fixing the 'Stop' button.

 

 

 

0 Kudos
Message 10 of 10
(3,178 Views)