01-23-2018 06:12 AM
Good Morning, I wanted to know if anyone knows how to do so that the byte count number that I have to specify in the input of the read block to make a serial communication is set only. Let me explain: I am going to send a data that will have x bytes, if I always send the same data it is easy to know what to put in this entry, but if the data I send had a variable number of bytes, how do I make the read input? change automatically, that is to say that it detects by itself only how many bytes "I want to write" and give it as input. I do not know if I explained well. Thank you
01-23-2018 06:26 AM
the general advice you will get is not to use 'bytes at port', but to use a proper termination char, then VISA Read will do so until the termination char is found.
are you building your own communication interface? or do you write-to/read-from a third party device?
01-23-2018 06:31 AM
Short answer: it completely depends on the protocol of the message.
Are you using an ASCII formatted message (you can read it in a text editor)? Or are you using a binary/hex format (raw data)? Are you in control of the protocol?
Any more advice will depend on your answers of those questions.
01-23-2018 06:56 AM
To expand slightly on jwscs's response (to which I agree completely) ...
The Serial protocol has been around for decades. One version, called RS-232, was used to describe the lines and signals used to connect teletypes (who remembers those?) to mainframes in the 50's and 60's. At some point, a higher-level protocol, the Virtual Instrument Software Architecture (or VISA), was developed to describe how serial communication could be standardized to permit easier communication of information between equipment from different manufacturers.
The company that created the Laboratory Virtual Instrument Engineering Workbench (or LabVIEW) has provided a set of VISA functions to help you communicate with devices using a Serial Protocol. Of these, the most pertinent for this discussion is the VISA Configure Serial Port function. You probably know that one of the inputs, Baud Rate, matches the speed of the VISA chip to the speed of the data being sent or received, and that other inputs (parity, data bits, flow control) are often ignored (as the defaults are usually correct). However, the right two of the "top" inputs are important -- Enable Termination Character (boolean, default True) and Termination Character (U8, default 0x0A, linefeed, \n).
Instruments that send (string) data using the VISA protocol typically end the string with one of the "end-of-line" characters, \r (carriage return), \n (line feed), or \r\n (carriage return-line feed, sometimes called CRLF). If you are fortunate to be "listening" to such a well-behaved VISA sender, and if you have your VISA "listener" configured to use a Termination Character and the sender is using \n or CRLF, then all you need to do to receive the entire VISA string, without worrying about the size of the string, is to ask to read, say, 100 characters (anything you are sure is larger than the largest string you expect from your device). If you issue such a command, the VISA Read will return the entire String (including the Termination Character, I think) and you can then process the String to extract the data it contains (use the String Length function if you need to know "how long was my string".
Bob Schor
01-23-2018 09:35 AM
@Bob_Schor wrote:
The Serial protocol has been around for decades. One version, called RS-232, was used to describe the lines and signals used to connect teletypes (who remembers those?) to mainframes in the 50's and 60's. At some point, a higher-level protocol, the Virtual Instrument Software Architecture (or VISA), was developed to describe how serial communication could be standardized to permit easier communication of information between equipment from different manufacturers.
Being nitpicky but...
RS-232 only defines the hardware layer, not the data being sent over it. At one point, a standard UART protocol was made that used baud rate, parity, start and stop bits. UART is often used over RS-422 as well (a differential version of RS-232).
VISA is a software abstraction layer from the communication bus that works with serial/UART, GPIB, Ethernet, etc.
But all of that is just to get the data from point A to point B. How each side interprets that data is what we are now trying to focus on.