LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

bytes at serial port

 
hi, I write a vi to read strings through the serial communication and i use the bytes at serial port to identify the number of the serial ports.
 
it can work   in debug model (in highligh executio), but when i run it in nomal status, it can not take some bytes, for example, it has 450 bytes in debug model and only 150 in normal status,
 
do i need to setup some timedelay  and how to do it?
 
thanks
0 Kudos
Message 1 of 16
(7,749 Views)
You need some delay because the instrument requires some finite amount of time to take a measurement and write it to the serial buffer. That's the downside to using VISA Bytes at Serial Port instead of a fixed byte count. If the number of bytes in  a reading is a constant or if the instrument puts a termination character at the end of each result, then using a fixed byte count with VISA Read will work better because it will just wait by itself until the number of bytes or the termination character is detected. When using VISA Bytes at Serial Port, you could put that into a loop and exit when bytes are greater than zero. Then do a read in a loop and exit when bytes are equal to 0. You could also use a fixed delay before your VISA Bytes at Serial Port. Use the Wait (ms) or Time Delay function. This is certainly the easiest to implement but it's not the most effecient.
Message 2 of 16
(7,732 Views)

thanks your quick answer. the problem is that the bytes in serial port isn't constant, if i put a bytes to read, it always to display "a framing error occured during transfer". so that is the reason why i use the bytes in ports function.

so, even i use that function, and exit if great than 0, it still can work in debug model(high ligh execution), but in normal status, i run it, it should obly take some bytes.

i also use the time delay, but it looks like still the same problem. i only got all bytes in debug model. and only some in normally run status.

0 Kudos
Message 3 of 16
(7,727 Views)
sorry,i just want to make cleat the questions.
 my problem is: when i run in debug model( highligh execution),  it can take 450bytes( for examople) in bytes at ports, but when i work in normal status, it only has 150(example) bytes in bytes at ports.
 
how can i take all bytes in normally running status.
 
thanks 
0 Kudos
Message 4 of 16
(7,724 Views)

Usually when something works in the debug mode and doesn't work in normal run mode it due to a timing issue. As Dennis says one way to do make it "catch" all the returned data is to put a delay between the writing of the command to the instrument and the reading of the resulting data. Using only a time delay isn't a good solution though, how long should you make the delay? If you make it very long then the program is inefficient. If you adjust it to be "just long enough" for this instance you may find that it isn't long enough if something changes in your system (you have to replace the instrument with a different one and it is slower than the original). As Dennis mentions a comination of the two is probably best. You could make your "Bytes at port" loop wait for greater than a certain number rather than greater than zero. This could allow the port time to get all the data. In this type of loop you want to make it conditional on the byte count or an error, so that you can have the port timeout also end the loop, so that you don't get trapped in the loop waiting for the correct number of bytes to come.

P.M.

 

Attached is in LV7.1.1

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 5 of 16
(7,716 Views)

thanks, and i set up the bytes at ports in loop and setup a certain number, but the questions is in the normal status, it can't be greater the number(for example, in debug model, it has 450 bytes, and i set the certain number is 400, it can't reach this number and it looks like a die loop. so how can i do?

0 Kudos
Message 6 of 16
(7,709 Views)

Hi srt,

Are you not using the "Bytes At Serial Port.vi" to set the number of bytes to read?  Otherwise, if you place a static value, such as 150 or 400 bytes, then one of 2 things will happen, it will ... "hang" ...  until the buffer has the required number of bytes, or it will timeout.   Both giving the appearance that it's not running, in other words, appears dead 😉 

What I mean by "Bytes At Serial Port.vi" is to obtain the number of bytes available to be read, then feeding this value to number of bytes to be read of the "Read Serial Port.vi".

JLV

Lemme look for a link that explains all this..

Message Edited by JoeLabView on 09-30-2005 01:43 PM

Message 7 of 16
(7,818 Views)

For your reading pleasure 😉

http://forums.ni.com/ni/board/message?board.id=170&message.id=111793&query.id=0#M111793

Or, if you're using LV7 and VISA.. :  (It may be too much details, but have a look at the bottom to "VISA Bytes At Serial Port" & "VISA Read")

 

Initializing the serial Port in LV7:

1. Go to the block diagram.

2. In the Functions Palette, select => Instrument IO => VISA => VISA Advanced and place the VISA Open vi on the block diagram.

3. Wire a "VISA resource name" control to the VISA Open vi. Also wire the Error-IN / OUT clusters appropriately.

4. Select the COMM port that you wish to use to connect to your instrument. (ex: COM1).

5. In the Functions Palette, select => Instrument IO => Serial; this is where you will find most of the useful VISA vi's relating to the serial communication.

6. Place the VISA Configure Serial Port.vi on the block diagram. You can wire the settings to this vi. You can use the Context Help for details (it is useful to show the connectors on the vi).

You can start with the following vi's:

a) "VISA Bytes At Serial Port" which indicates how many bytes are available top be read at the serial port buffer.

b) "VISA Write" Wire the string that you want to transmit to this vi. This vi also provides a return count for the number of bytes at the serial port (echoed data for instance).

c) "VISA Read" Reads the serial buffer as an output string. This is where you will want to wire the byte count (as an input) from the two vi's above.

d) "VISA Close" A very important vi, because it closes the communication session to the COMM port. Very useful if you switch back and forth with a software like HyperTerminal.

I think that this should get you going with the serial port communication. You may want to implement some sort of a loop (while for instance) in order to read the data from the serial port buffer until it is empty. Depending on the speed of the communication, you may also want to place a delay within the loop.

JLV

Message 8 of 16
(7,812 Views)

hi, thanks,

 

but i didn't find the "Bytes At Serial Port.vi" ( use labview 7.1) 

and also, how can i use the string i got from rs232, i mean, i want o compare it with some string to check whether it is right?

 

0 Kudos
Message 9 of 16
(7,804 Views)
Instrument I/O >> Serial >> VISA Bytes at Serial Port. Or Instrument I/O >> VISA >> VISA Advanced >> Property node - popup on the node and select Property >> Serial >> Bytes at port.

With the problems you have been having I would just display the string in an indicator and look at it until you get things working. Set the display mode to '\' Codes Display so that you can see non-printing characters like line feed and carriage return.

Just a thought... You are aware that you can only connect one RS-232 device per port, right?

Lynn
0 Kudos
Message 10 of 16
(7,793 Views)