取消
显示结果 
搜索替代 
您的意思是: 

Using comport data to start a sequence

已解决!
转到解答

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)

0 项奖励
1 条消息(共 27 条)
4,703 次查看
Does the data coming in have any sort of termination character such as a carriage return?  If so,  enable the termination character for the serial port.  Make sure you have a sufficiently long time out to either wait the entire minute or wait 10-15 seconds.  Have the serial read in a while loop so that if the functions times out AND the stop button has not been pressed, the loop will repeat .  (This will give you a way to stop the program without waiting 1-2 minutes for the serial reads to come in.)  Once the loop ends, you can execute your code.  It could be in a case structure so that the other code doesn't execute in the event of a timeout.
0 项奖励
2 条消息(共 27 条)
4,687 次查看

That's how I have done it in the past. The problem this time is the data stream has CRLF's in the string.

0 项奖励
3 条消息(共 27 条)
4,675 次查看

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.

0 项奖励
4 条消息(共 27 条)
4,672 次查看

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

0 项奖励
5 条消息(共 27 条)
4,653 次查看

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

0 项奖励
6 条消息(共 27 条)
4,637 次查看
解答
已被主题作者 ssmith490D 接受

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.

 

 

 

Message Edited by Ravens Fan on 11-25-2008 04:53 PM
7 条消息(共 27 条)
4,625 次查看

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

0 项奖励
8 条消息(共 27 条)
4,611 次查看

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 

9 条消息(共 27 条)
4,607 次查看

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

ssmith@bnl.gov

 

0 项奖励
10 条消息(共 27 条)
4,553 次查看