Hi!
To the impatient, Question summary:
* Producer loop efficiency
* Find/Lock on Synch Word efficiency
* Open VI's, they are commented.. somewhat.
Details:
Situation:
Serial Data incomming on Com 1 @ 4800, semi-asynchronous (app. 1 package/second, but extra messages at times).
Basically, I have an external devices which gives me housekeeping data about once pr second.
Then, if I send a command, it will, quite aside from the housekeeping data, send me an "ack" or a "nack" on that command.
Now, the protocoll we have devised looks like this:
| Synch 4 | Length 1 | Controll 1 | Recipient 1 | Cmd. 1 | Data/Argument X | CRC-16 2|
Where the numbers correspond to number of bytes of that field and X is between 1 and 250.
The way I have it set up now, I have the producer as a while-loop that constantly checks to see if there is a byte on the serial port, and if so, to read it/them and place it in a queue.
The consumer operates in several stages, first it reads one and one byte from the queue until it finds the Synch characters in sequence. When it does, the next sub-vi will read one byte to get the length then using a for-loop, it will read the rest of the message, calculate the message CRC code and compare the calculated code with the received code. If they match, the "Data" field is pulled out and processed (charts and various indicators).
My problem:
Is there a good way to have the producer only use cpu-time when there is actual bytes at the serial port. I use VISA Read. Can one use the Event structure to do this?
I do not feel comfortable with manually optimizing timers in the producer loop for the best performance, as this will require me to custom tweak the time based on the end-user's computer.. To try and help the situation a little bit, the "read into my queue" sub-vi will read all bytes available up to chunks of 100. See the attached VI's for details.
Also, as it is now, I use a very ugly nested case vi to look for my synch word. I am aware of the string search, but I do not think I can use those, since I need to look at one byte at a time. *(to understand this, consider if I read say, 4 bytes at a time and did a string compare, and my synch word started on the last 2 bytes, then I would loos the entiere message.)
Included are my Synch-Word "extractor" vi (used as a sub-vi), and the (still early on, so not optimized) main VI and sub-vi's needed.
They are all compiled with LV 8 and when I try to save for LV 7.1 it gives me grief, so...
Message Edited by Kjell-Edmund on 02-18-2006 05:01 PM
---------------------------------------------------
Project Engineer
LabVIEW 2009
Run LabVIEW on WinXP and Vista system.
Used LabVIEW since May 2005
Certifications: CLD and CPI certified
Currently employed.