11-24-2008 02:49 PM
All--
I'm sure my terminology is bad here so allow me to explain what I want to do. I wish to monitor a com port and when the data stream arrives do things like parse, plot, send to indicators and write the data to a file. I have built a series of cases to do each of the tasks in sequence. I need a nice neat way to start the sequence when the data is finished arriving and then wait for the next data transmission. The data arrives about once per minute. Unfortunately, for now, the data will only come in at 1200 bps, so the transmission takes about 3 seconds. I think an event structure would work but I have no idea how to create/uses dataflow on the comport to start the sequence. Thanks in advance for the help.
ssmith@bnl.gov (Scott)
Solved! Go to Solution.
11-24-2008 03:20 PM
11-24-2008 08:15 PM
That's how I have done it in the past. The problem this time is the data stream has CRLF's in the string.
11-24-2008 08:43 PM
Does the device always send the same number of bytes, or does it vary?
Then don't use the termination character if CR or LF is part of the data stream. Read a sufficiently large number of bytes and set a timeout that is larger than the number of bytes you'll ever expect to receive. You will always get a timeout message because you will always be trying to read more bytes than you get, but if you get data and a timeout message, advance to the other parts of your code. If you don't get data, then repeat the serial read.
It sounds like you have a state machine architecture already. Also look at all of the examples for serial read and write in the example finder. I believe what you want to do is already in there, or may be a combination of a couple of examples.
11-25-2008 08:18 AM
I tried using the timeout on the "Configure Serial Port" vi but it did not work very well. The example uses a property node with the read function. How does this timeout differ from the Config Ser. port" timeout function?? Thanks.
Scott
11-25-2008 11:18 AM
Ideally I want program execution to wait in the READ case until data arrives. Once the data arrives I want program execution to continue and then wait in the READ case again. And so on. I've attached the VI for you to look at. Thanks.
Scott
11-25-2008 03:52 PM - edited 11-25-2008 03:53 PM
ssmith490D wrote:I tried using the timeout on the "Configure Serial Port" vi but it did not work very well. The example uses a property node with the read function. How does this timeout differ from the Config Ser. port" timeout function?? Thanks.
Scott
I'm not sure which example you are referring to here or which property node with the read function you are talking about.
How come you have 60,000 wired to the property node for data bits? The only valid setting for that are 5-8. And the only likely settings would be 8 or 7. I think you have that setting confused with timeout.
I would recommend opening your serial port and configuring the settings only once during the intialization frame of your state machine. Close the port only once in a frame that occurs once when you stop the program. In between, you just carry the VISA reference through the loop by way of shift registers.
(Actually you should be using a lot more shift registers. You are relying too heavily on local variables to get data from one state to another. It could possibly cause problems down the road.)
Your architecture right now is technically a state machine, but basically just a step above a flat sequence structure. You can use decisions to determine which code to execute next. See the attached screenshot.

11-26-2008 08:10 AM
Ravens Fan--
As you can tell I am a Labview beginner. The 60,000 in the property node is a mistake, it was originally for timeout. Opening the serial port in the Initialize case is a good idea. I started out using shift registers but the program got too busy with all the shift registers. Last night a light bulb in my head went on...can I bundle a bunch of wires and send them through one shift register?? The logic to control the case selection in the example you gave me is a neat way to do it. Do I have to worry about the program racing while it continually loops throught the read case until it sees data as oppsed to waiting for data?? Thanks for all the help.
Scott
11-26-2008 08:17 AM
Scott,
Clusters are good for that very purpose. A recent thread on the Forum discussed that at some length.
Most loops should have a wait somewhere to avoid what are called "greedy loops." The VISA Read may wait for the specified number of bytes. This could provide the wait.
Lynn
12-01-2008 12:56 PM
Lynn--
Waiting for the specified number of bytes did the trick. It does however give me another problem, although not a deal breaker. There is a clock on the front panel and the code for that is in the "read" case. Now that I'm waiting the clock updates once a minute instead of once per second. I tried moving into a parallel while loop with no success. How can I make the clock update once per second while the "read" waits for data to come in?? Thanks for the help.
Scott