09-09-2008 04:41 AM
I am scanning a serial port for a particular word, This word will turn up at any point in a long string sent from the serial port.
I have got my VI to scan for the word and find it succesfully using a while loop.
but I want the VI to write a shtdown command to the serial port if it has not recieved the word after a time period of 5 mins for example. Once the machine starts communicating again on the serial port i want the VI again to scan for the word is there any way to do this?
09-09-2008 05:04 AM
Hi Dowden1,
if you already use a while loop, then you can count the iterations. If you know how long the time for one iteration is, you can calculate the time you need and compare it with your time limit. Place a case structure after your while loop and insert the shutdown command into the true case. connect the compare result to it.
Hope it helps.
Mike
09-09-2008 08:03 AM
Hi Mike,
That has helped and in theory will do what I want as i have tried a basic version before implementing into my VI, although it seems that the loop will only increment each time a string is recieved from the serial connection rather than in a continuos loop which i can time and use. I have tried placing the read function out side the loop, but it reads one line and then gets stuck in the loop for the length of time i specified
Any help would be greatly appreciated.
Dowden1
09-09-2008 08:14 AM
Just use a second while loop to measure time.
Use a global variable (the easiest way. No race conditions here) to interact with the first loop.
09-09-2008 08:15 AM
I don't fully follow what you are describing.. Can you post your code?
R
09-09-2008 09:00 AM
Hi,
Here is my code,
i have removed a load of stuff to make it a bit simplier for you.
The idea is that the serial port is connected to a device that keeps sending data at random intervals over a period of time and I am looking for a word to trigger a series of tests (which were in the true case) and if the word isnt recieved with in a time, for example 5 mins for the VI to send a command which will restart the machine and hopefully trigger it to send the word this time.
I have tried the solution shown in code below however the loop only seems to iterate each time a string is recieved on the serial port.
If you could please help
Thank you
Dowden1
09-09-2008 09:53 AM
need also scan.vi
09-09-2008 10:06 AM
hi,
sorry here you go
09-09-2008 10:20 AM
I would suggest:
1. use ByteAt serial port.vi and connect to readbyte,
2 the waitms should be from 20-200ms to allow a block of data
3 you analyse (scan) the block of data.
Means you should take the approch to read a block of data and analyse the block of data
an could be a while loop with byteatserialport.vi with readbyte.vi and connect the output string to a shift register(1)
and the input value of the shift register(1) is connected to scanBlock.vi
first time it will just acquire. (init shiftreg(1) to empty string.
09-09-2008 10:27 AM
Hi,
Will this allow me to scan a continuous stream of data, as the machine the serial port is connected to keeps throwing data at the serial port and the word i am looking for could turn up anywhere in there, it is not guaranteed to be in the same place every time