LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Write /Read

Hi Fredo,

 


@Fredo123Danzel wrote:

Unfortunately, I don’t have LabVIEW 2019.

I only use LabVIEW 2022


File -> Save for previous…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 11 of 20
(200 Views)

@Fredo123Danzel wrote:

I tested my system using PuTTY and found it to be very fast. That’s why I would like to develop a LabVIEW VI that can perform similarly to PuTTY.
What do you think of my VI, please?


Again, we need to know a lot more information on the messaging protocol your device is using. We can accomplish what you are asking, but you have to use the protocol to get anything useful out of it.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 12 of 20
(168 Views)

use an RS232 communication (FTDI). The supported baud rate by the board is 115200 bps.

 

I send hexadecimal frames using VISA Write, and I would also like to read hexadecimal data.

0 Kudos
Message 13 of 20
(151 Views)

@Fredo123Danzel wrote:

use an RS232 communication (FTDI). The supported baud rate by the board is 115200 bps.

 

I send hexadecimal frames using VISA Write, and I would also like to read hexadecimal data.


You misunderstood crossrulz' request. The things you mention here were already quite clear. But there are about zillion ways to transfer binary data (you don't transfer hexadecimal data, that is just the format your logger chooses to present the binary data to you).

 

The data is binary obviously but in order to transfer binary data there needs to be some sort of format: start character, end character, possible CRC data, length of message or how that length is encoded, etc. etc. Are multibyte values little endian or big endian?

 

Without this information it is simply impossible to come up with a good programmatic algorithm to receive and decode the data, or generate according data to send to the device. So far you just showed pictures of the protocol logging with some random numbers shown in hexadecimal notations. No real explanation about what each of those messages should mean, which part is protocol signaling and which part is data. You need to provide this protocol documentation, we can't invent it ourselves. You have the device with which you can do experiments. I and everybody else here can investigate unclear and missing protocol documentation only if we can get our hands on the hardware itself and do trial and error, which is not an option here.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 14 of 20
(138 Views)

@Fredo123Danzel wrote:

I send hexadecimal frames using VISA Write, and I would also like to read hexadecimal data.


And how are those frames defined? Is there any documentation from your device?



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 15 of 20
(123 Views)

Hi,

I use VISA Write to send commands to my board. For example, to start test mode: 1C20 AB13 0000 051A, where 1A is my CRC. My board accepts this frame and sends back a response frame (1B20 AB13 0001 0103 01C1) to indicate that test mode has started. VISA Read processes my response in ASCII format. I use an indicator to view my frame in hexadecimal.

0 Kudos
Message 16 of 20
(118 Views)

Your still are very vague.

 

First, are those hex values simply the hexadecimal values of the bytes you sent over the line or are you converting your binary data to hexadecimal text to send as ASCII text?

 

What is the meaning of the individual values? Why does the command start with 1C or maybe 1C20, or is it rather 1C20AB? What are the remaining data before the CRC? Do you know the algorithm to calculate the CRC? What is it?

 

Similar questions about the response.

 

Is every command always 8 bytes long? And every response 10? If not how does the receiver know how many bytes to read?

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 17 of 20
(110 Views)

I may have expressed myself poorly.

I am not using a commercial product.

 

My question is whether LabVIEW is as fast as PuTTY.

 

I have a private electronic board that contains an embedded program.

Once this board is powered on, I can communicate with it via the RS232 port.

I send bytes, with the last one being a CRC.

I have all possible frames. For each frame sent, I get a response.

 

I have used PuTTY and it works very well and quickly.

 

I have also used LabVIEW to communicate with the board, but the response is very slow.

That is why I wanted some explanations or to understand what might be wrong in the .vi file.

 

While researching, I was sometimes told that you must know the number of bytes to read, and other times I was told the opposite.

In the end, I no longer understand anything.

 

0 Kudos
Message 18 of 20
(91 Views)

So you have some fixed data sequences you have to write out. No problem, just write them. I can assure you that Putty won't be able to do it faster than LabVIEW. That's because the limiting factor by far is the serial port speed itself and with modern computers, LabVIEW can dance, balance an inverted pendulum, babysit a dozen of devices and send out a 8 byte string to your device at the same time you need  to blink once.

 

The problem is with the receiving end and putty does it the very inefficient and slow way of reading one byte after the other until there are no bytes left. Since it is a terminal program the limiting factor here is you, the operator as you can't notice that the bytes arrive one after the others on screen. And that's it, your screen displays these characters and does absolutely nothing else with them. You can stare at the screen for hours and try to make sense of the displayed characters, or simply dismiss it and send another command and then stare at the characters appearing on screen.

 

In LabVIEW however you want to read a number of bytes and then do something with it. You could of course read one byte after the other with a VISA Read reading each time one byte. That would be pretty much the same as what putty does. But when do you stop? When there wasn't any byte anymore for 100 ms, or maybe 500 ms, or rather 2 seconds? You have to have some way to abort in order to let your program continue with the next step. If you chose the timeout to short, you may conclude that the device has finished sending because it was slower than the computer (which it almost always is). If you chose it to long, you get what you perceive as slow communication in LabVIEW since the VISA Read function waits the full timeout before returning a timeout error. So trying to mimic putty is not a very good strategy and it is not that putty is faster, but that what putty shows you appears faster but simply because putty does nothing else than constantly waiting on the serial line for new data and whenever it appears it displays it on the screen.

 

But I know how long my message is, it is always xyz bytes! Great! In that case simply issue a VISA Read for exactly this amount of data and the problem is solved.

 

Or, I do not know how long my response is beforehand but there are characteristics that are always the same. This could be:

 

- There is always a specific byte at the end of the message. Pronto, simply configure the VISA session to terminate on that character, and issue a VISA Read with more bytes to read than the longest message you expect. VISA Read will terminate as soon as it encounters that byte. This is most commonly used for text protocols where the command is terminated with carriage return, line feed or both. But there are also binary protocols that use for instance a start of text (0x2) and end of text (0x3) byte code. The difficulty is that if it is a true binary protocol, it can also contain these byte codes in the data part and the sender then has to escape it if it is part of the data by for instance doubling that byte. Your protocol seems definitely not to fall under this category since you have as last byte a CRC, which of course will vary with every text response depending on its content.

 

- There is a header of some sort that has always the same size and contains the number of variable sized data elements that follows.

 

- The size of the entire answer is known from one of the first bytes in the message and that indicates what type of response it is and that type of response has always the same amount of bytes for this particular type

 

- The size of the answer is known from the command that was previously send. That is a pretty unreliable method, since you can not be sure that you are reading the response to the last command or a response that was send to an earlier command but not yet read because of a software error or similar.

 

If your message protocol does not fall under one of these (and the last point I would also not really allow to count), it's not a protocol but garbage.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 19 of 20
(76 Views)

"My question is whether LabVIEW is as fast as PuTTY."

 

It's faster, if used right.  I guarantee you if you try to use something else like C++/C# or Python to do this you will have the exact same problem.

 

"I have a private electronic board that contains an embedded program."

 

Can you change this program to send data back in a different format?  Or is it "private" from someone else and you have no control over it?  Whether it was you or someone else who made it, they clearly didn't research standard protocols for serial communication first and you are now in this messy situation.

 

"While researching, I was sometimes told that you must know the number of bytes to read, and other times I was told the opposite."

Both are true in different circumstances.

 

You "think" PuTTY is "fast" because the response shows up right away, but that's because PuTTY does not have to decide where to split the message if it gets more than one reply.

 

So, you put this in the terminal of PuTTY:

<8 hex bytes>

Then in the reply from PuTTY, you see:

<10 hex bytes>

And since you see it immediately, you're thinking "Ah ha!  PuTTY is super fast!  I just wish LabVIEW worked like this!"

 

Well, consider this... what if you put this into PuTTY instead:

<8 hex bytes, command 1><8 hex bytes, command 2><8 hex bytes, command 3>

Then you see in the reply from PuTTY:

<31 hex bytes>

Well, now what?  You have 3 replies mashed together and the bytes are not a multiple of 3.  How do you split them up?  10,10,11?  11,10,10?  10,11,10? Or what if it's 9,12,10? 

 

Your only option given the "protocol" you're using is to check one byte at a time to see if it equals the CRC of all the bytes received before it.  And that's a super bad way to do it.  It might work, but you have 2 big problems:

1. If the CRC ever fails due to bad comms (the reason the CRC is added in the first place...) you won't ever find the end.

2. Since your message is just arbitrary bytes, there's going to be a 1 in 256 chance each time that the byte you read will accidentally be a CRC match for the bytes before it.

 

The only option you have given the "protocol" you are using now is to lower the timeout, and then wait for the timeout, and just hope that you pick the correct timing.  And that's a bad option too, because this can happen because you're using a non-real-time OS (Windows, but even Mac or desktop Linux would have the same problem):

YOU: <send command>

OS: Here's a byte of a reply.  LABVIEW: Thanks, got it.

OS: Here's a byte of a reply.  LABVIEW: Thanks, got it.

OS: Here's a byte of a reply.  LABVIEW: Thanks, got it.

OS: Here's a byte of a reply.  LABVIEW: Thanks, got it.

OS: Here's a byte of a reply.  LABVIEW: Thanks, got it.

OS: Here's a byte of a reply.  LABVIEW: Thanks, got it.

OS: HOLD ON, TASK SWITCH TIME, I AM PAUSING THE SERIAL PORT READ TO SEND SOME VERY IMPORTANT DATA TO ONEDRIVE

LabVIEW: Looks like it timed out.  Here's your full reply!  Looks like the CRC check fails though.  Best of luck.

OS: Here's a byte of a reply.  LABVIEW: Thanks, I'll hold on to that and read it later, I'll pretend it's the first byte of the next reply to the command that hasn't even been sent yet.  It'll be super funny trying to parse that!

 

 

0 Kudos
Message 20 of 20
(71 Views)