Using tcpclient to Write and Read VXI-11 data from an instrument

I have been trying to use MATLAB to write and read values from a signal generator.
This signal generator uses the VXI-11 protocol to send commands, which I have been sending using tcpclient.
Using Wireshark, I can see the write and read commands going to the signal generator as expected. The signal generator also responds correctly, showing that it has accepted commands.
The TCP packets are structured with a Remote Procedure Call portion, followed by the VXI-11 portion.
However, when I try to use tcpclient.read, MATLAB only seems to see the Remote Procedure Call portion. The number of bytes read and the contents contain only this RPC info, omitting the VXI-11 bytes at the end.
Here's the "read" portion of code. The first "write" is writing a read command to the device. After waiting for some bytes to be available on server_name, it reads them out.
write(server_name,commstring_values);
%After writing, wait a short time for byte to be available before reading
waitin = true;
anybytes = 0;
cyclestowait = 50;
while waitin
anybytes = server_name.NumBytesAvailable;
if anybytes > 0
waitin = false;
['There were ' num2str(anybytes) ' bytes.']
end
cyclestowait = cyclestowait - 1;
if cyclestowait == 0
waitin = false;
'I gave up while waiting for bytes'
end
'I had to wait at least once for bytes'
pause(.0005);
end
visa_tcpip_return = read(server_name);

1 Comment

I believe I found the issue. After creating the VXI-11 link the server replies. I was not yet checking the result so my functions did not try to read this reply. Adding a tcpclient read after CREATE_LINK looks to fix the subsequent reads.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2021a

Asked:

on 25 Mar 2022

Commented:

on 25 Mar 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!