03-18-2025 03:38 PM
If you are familiar with C#, this might be easier to understand where I'm coming from. In C#, I would use this function to put together a blob of binary data to write to VISA:
IMessageBasedSession.FormattedIO.Write();
That particular method can take strings, arrays of bytes, etc. To my knowledge I can find no equivalent in the VISA VIs available in LabVIEW. I think the VISA write VI provided automatically writes and flushes the buffer, so I would need to build the entirety of what I am sending into one data structure, then send it on its way. It only accepts a string, so I thought to convert the bytes to string - didn't work.
[SOUR1:DATA:ARB1 HALFSINE_POS, ] - then from there append the array of bytes. In C#, I would write a string to the buffer, then write the bytes to the buffer (as bytes), then flush and everything worked. I'm seeing no option to do that here - am I missing something?
Solved! Go to Solution.
03-18-2025 03:45 PM
Hi P²,
@Psquared wrote:
[SOUR1:DATA:ARB1 HALFSINE_POS, ] - then from there append the array of bytes. In C#, I would write a string to the buffer, then write the bytes to the buffer (as bytes), then flush and everything worked. I'm seeing no option to do that here - am I missing something?
A string is the same as an array of bytes, and there are two functions to convert between them (StringToU8Array, U8ArrayToString).
What have you tried and where are you stuck?
03-18-2025 03:46 PM
You say you "so I thought to convert the bytes to string - didn't work".... how did you do the conversion? Was it this?:
https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/byte-array-to-string.html
That is exactly how I have sent binary data over VISA before and it has worked.
Perhaps there's something else involved? You don't say what device you're writing to so I can't look up the protocol, but perhaps you need to prepend a message length, or add a null termination character, or something else along those lines.
03-18-2025 04:42 PM
I am talking to a Keysight 33622A Function Generator. Everything I am trying to do in LabVIEW I have already done in C#, so I know that it is possible. The unsigned byte array to string conversion was one of the efforts I had made, but since you've said you have made it work I will have to take a look at the string as a whole when I get back to it in the morning. It sounds like I might be on the right track; I'm hoping it is something simple.
03-18-2025 04:51 PM
@GerdW
Tried:
Type cast (Byte Array -> String)
Flatten to String
Byte Array to String
What I do is write the command, then concatenate the Byte array -> String conversion and then call the VISA write VI. The instrument doesn't like any of the above.
03-18-2025 05:24 PM
It's almost certainly in IEEE-488.2 binary block format, then.
So, in addition to your binary data you need to send a # sign, then the length of the length, then the actual length, and only then add your binary in.
Plus also making sure that the byte order is correct...
03-18-2025 07:38 PM
@Psquared wrote:
I am talking to a Keysight 33622A Function Generator. Everything I am trying to do in LabVIEW I have already done in C#, so I know that it is possible. The unsigned byte array to string conversion was one of the efforts I had made, but since you've said you have made it work I will have to take a look at the string as a whole when I get back to it in the morning. It sounds like I might be on the right track; I'm hoping it is something simple.
It is simple. Not quite a no-brainer, but the advice given is sound so you should be able to work out the details with no problem.
03-19-2025 10:43 AM - edited 03-19-2025 10:46 AM
@Kyle97330 wrote:
It's almost certainly in IEEE-488.2 binary block format, then.
So, in addition to your binary data you need to send a # sign, then the length of the length, then the actual length, and only then add your binary in.
Plus also making sure that the byte order is correct...
This.
I realize now what was going on. I remember debugging a similar issue in C#, except that then I coded the BinBlock format into the string and for "some" reason I saw the #3456 on the write buffer to the device. Turned out that the WriteBinary method in C# automatically coded BinBlock into the write. That's not the case here in LabVIEW, since don't have that option - building that BinBlock string and adding that in did the job. I buried that functionality into the abstraction of my classes once it got working in C#. Another interesting thing I came across is that I had to swap the "endian" of my float -> bytes conversion in C# and didn't have to do that here.
Simple things indeed. But a good learning experience. Thanks for the guidance.