09-30-2005 08:58 AM
09-30-2005 09:11 AM
09-30-2005 09:23 AM
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.
09-30-2005 09:42 AM
09-30-2005 10:45 AM
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
09-30-2005 11:16 AM
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?
09-30-2005 12:40 PM - edited 09-30-2005 12:40 PM
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
Message Edited by JoeLabView on 09-30-2005 01:43 PM
09-30-2005 12:49 PM
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
09-30-2005 01:49 PM
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?
09-30-2005 02:28 PM