LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help, please! Unbundle data from serial string (com-port)

GerdW, thank you for recommendation!

I try to do it.

Bes regards, Mikhail.

0 Kudos
Message 21 of 30
(1,795 Views)
Hello GerdW!
At that time we convert string to byte array (u8), but now I need scan string fron serial port simpliciter, and when my subVI "see" symbol "A", its begin work (attached VI in previous message)
When I power on my device first and then on my VI, that all right, but if I start my VI first, and then power on my device, that I have a problem, becouse VI can start scan string in the middle, and graph plot wrong.
I need scann string on "A" or "B" symbol one time and then and continue passing the incoming data. How a can do it using string functions?
 
Mihalis.
0 Kudos
Message 22 of 30
(1,785 Views)
You should start your vi first, then power on your equipment to make sure the vi catches the very first serial character sent by your equipment.  In your vi, the first thing to do is create a loop that waits for serial bytes to appear at the serial port.  After receiving some bytes, check for the start character.  Repeat until start character is found.  Then process the data with the start character.  Then another loop to recevie the characters and process them.  See attached vi for an example.
- tbob

Inventor of the WORM Global
0 Kudos
Message 23 of 30
(1,772 Views)
Hi Tbob!
Thank you. This VI - what I need. However it is intricate, in my opinion. Do it is can done more easier ?
 
Mihalis.
 
0 Kudos
Message 24 of 30
(1,763 Views)
Here is a simpler version.  However, with this version, if you receive characters before the start character, the process data section will see all the characters, not just the ones after the start character.  You would have to filter those before the start character only on the loop in which the start character appears.  To me, my first vi is better because it breaks this down into sections that is easier to see.  Also, if you are very sure that there will always be bytes at the serial port, you can eliminate that part of the code that waits for bytes at port.  Then what happens if the com link breaks?  You start getting errors.  The intricacy of the first vi is such that it handles this error.  Your vi's should be written as such, no matter how intricate.  You don't want to have error conditions break your vi do you?
- tbob

Inventor of the WORM Global
Message 25 of 30
(1,757 Views)
Yes, you are right.
I try  use both versions of VIs.
It s great help!!!
Thank you!
0 Kudos
Message 26 of 30
(1,746 Views)

Hello

 

interesting subject, I'm doing something similar.

Let's say there is a piece of equipment that transmits a small message i.e 'IM_ALIVE', 8 ASCII chars. Then it transmits data i.e ABCDABCDABCD (four bytes of ASCII) all the time

To syhcronise: 1) run VI waiting for 'IM_ALIVE' string. 2) start external equipment that transmits this. 3) after 8 byte string recognised, plot data A to graph 1, data B to graph 2 etc... (decimate these 4 bytes).

 

Problem: need to receive 8 bytes for first part, then change to 4 bytes for ABCD data. (without missing anything in between) i.e total message:    IM_ALIVEABCDABCDABCDABCD..........

Any ideas out there?

Cheers in advance

Aid

 

 

0 Kudos
Message 27 of 30
(1,597 Views)
Here is a description of a template to use.  Create a while loop.  Inside the loop, put code to wait for bytes at port (smaller loop) and then read 8 bytes.  After reading, check if it is equal to the desired string (IM_ALIVE).  Wire comparison output to a case structure.  Inside the True case, put another while loop with code to wait for bytes at port and then read 4 bytes, then plot graph.  This loop continues until some condition is met.  Wire a True constant from the loop thru the True case to the main while loop stop sign.  Everything will stop.  In the False case, wire a False constant to the main loop stop sign.  The main loop will repeat waiting for IM_ALIVE.
- tbob

Inventor of the WORM Global
0 Kudos
Message 28 of 30
(1,590 Views)

Hi

 

Had a go at that idea.

I want main stop button to stop everything, then when ran again back to waiting for start string. see attached

By resetting the external equipment, I can monitor the recieved string value, it only gets the full 'IM_ALIVE' now and again, not every time! even if it gets all the string, it doesn't break out of the first while loop, hence nothing plotted.

Is this as your spec, or have I missed something?

Thanks for help though

Aid

 

0 Kudos
Message 29 of 30
(1,574 Views)

You are not using the Visa Serial Bytes at Port function.  It is located in the same palette as the Serial Read and Write functions.  It will return the number of bytes waiting to be read at the serial port.  Just put it in a loop to wait for 8 bytes, then break out of the loop.  This ensures that you will read all 8 bytes.  See picture below for an example.  The NumBytes should be set to the number of bytes you are waiting for (4 or 8 in your case).  Timeout is the number of tenths of a second to wait before exiting the loop.  This is so you don't get stuck in an endless loop if the serial port breaks or the external device does not transmit.  You should add code to check if a timeout occured before trying to read (use a case structure).

Message Edited by tbob on 10-03-2006 10:43 AM

- tbob

Inventor of the WORM Global
0 Kudos
Message 30 of 30
(1,545 Views)