06-04-2012 11:36 AM
Thanks,actually i need to configure all the parameters with given values(value will be set by the user).so that i just combine all string commands and send it togrther.could i also send commands one after another? I just need to set all the parameters once and just get a data from device.For getting a data ,there is also same like commands.for example:
To set :
{<V01/DST01/SRC62/PT08/DT01><C04/R01//R001/C001><Set Value>}
To get:
{<V01/DST01/SRC62/PT08/DT01><C04/R01/A00></R001/C001><>}.
Is there any way to send data serially one after another??
06-04-2012 11:43 AM
Thanks,actually i need to configure all the parameters with given values(value will be set by the user).so that i just combine all string commands and send it togrther.could i also send commands one after another? I just need to set all the parameters once and just get a data from device.For getting a data ,there is also same like commands.for example:
To set :
{<V01/DST01/SRC62/PT08/DT01><C04/R01//R001/C001><Set Value>}
To get:
{<V01/DST01/SRC62/PT08/DT01><C04/R01/A00></R001/C001><>}.
There is no special resion for using 500ms.It was already fixed in basic serial communication example that i found in ni labVIEW.how much time i have to increase to pass all tha data?
06-04-2012 04:08 PM
Try increasing it by a factor of 2 and try again. Do some more if necessary.
When sending a log of commands, you are better off doing it in a loop rather than jammim them through all at once. Do a VISA Write then Read in a loop, and use index array to get the command set out of your array of commands.
06-05-2012 03:50 AM
@tadhika wrote:
Hi, i am using visa read and write to communicate with device via RS232. i have to sent several string commands.i just use basic serial communication to read and write the commands.my total string lengh is about 6626. i also used buffer size of about 7000. when i send all the string to visa write ,i will get a output number(byte) sometimes 6626 and sometimes less than this.Also i used property node for bytes at port which i used bytes number for visa read. But as output number here i get somtimes much more such as about more than 6670 and sometimes less than 6620 and sometimes only 4000and some and 5000 and some.it doesnot remain constant. how can i solve this problem?? why do i get more bytes as output from visa read than i have sent?? and sometimes less than??And sometimes more than visa write output number?? waiting for help.thank you. Tadhika,
Using Bytes at Serial Port to determine how many data to read is almost ALWAYS wrong. That property is useful to see if there is any data, and for very exotic transmission protocols it can be sometimes useful for other things, but almost any standard serial communication is definitely going to work wrong with it (unless you use ridiculously large delays between write and read to make sure all data has arrived when you attempt to read it, but that is very bad programming).
Serial communication (also over network like TCP/IP) has normally two different ways of operation. It is either a fixed size protocol, where each data frame has a fixed amount of bytes, or the number of bytes that the frame consist of are mentioned in the frame header, or it is a byte signaling terminated data stream. VISA (and the LabVIEW TCP/IP functions) provide for both possibilities. Fixed size implementations are obvious, as you usually read the header, determine the number of bytes that must follow and read that many more.
Byte signaling terminated data streams use a specific byte (character) to indicate to the receiver that the last byte of the data frame has been received. This of course requires the sender to actually append such a byte to every message. It is the most commonly used transmission mode in serial port communication and usually the carriage return or line feed, or the combination of both is used for that. Therefore you need to know this termination byte and configure your serial port to use this. The LabVIEW VISA Initialize Serial Port.vi by default enables termination on receiving the line feed (0xA) character (and should be therefore disabled for use in fixed size message frames, as they are usually binary data streams that can contain any character code as valid byte in the data stream.
If your termination character is configured properly you can simply write the command and follow directly with a VISA Read with long enough timeout. No need for any delays between write and read operation, and the read returns as soon as all the data has been received or an error occured. VISA Read will return if any of the following reasons happen:
1) an error occurred trying to read data from the serial port
2) the requested amoun of data has arrived
3) the configured termination byte has been received
4) the configured timeout has passed without any of the previous reasons being fullfilled and it returns a timeout error
This approach does require you to structure your communication a little differently. In general it is not a good idea to send a whole bunch of commands in one go and receive all the generated answers afterwards. It is better to send one command and receive it's response. Many devices don't even support receiving more data once they start to execute a received command. If you want to keep you current approach you need to loop your read with a not to long timeout until it returns with a timeout error indicating that the device did not send any more data.
06-05-2012 01:15 PM
@rolfk wrote:
Using Bytes at Serial Port to determine how many data to read is almost ALWAYS wrong. That property is useful to see if there is any data, and for very exotic transmission protocols it can be sometimes useful for other things, but almost any standard serial communication is definitely going to work wrong with it (unless you use ridiculously large delays between write and read to make sure all data has arrived when you attempt to read it, but that is very bad programming).
I completely agree with you here. That is one of the things that irritates me about the Basic Read Write Serial Example in the LabVIEW help. It is based around the Bytes at Port method. All new users use that example as the basis for their VI's (think how many times you've seen that posted on the forums as the user's VI with little or even no changes to it when they are looking for help.)
I think I have never used the Bytes at Port method on any of my serial comm VI's. The only time I think it might be useful is if I was creating some terminal emulation type of program where I just want to grab whatever data is in the port at the moment for display without worrying about message framing.
I really wish there were one or two more examples for serial port communication so that people can see the more common ways of communicating with a device and can use that as the basis of their VI rather than the useless Basic Serial example that is there. (The Advanced example is better, but has some things in it that are usually not needed, and no one ever seems to grab the Advanced example as the basis of their VI.)