Help with read/readline with serialport object for NanoVNA V2_2
8 次查看(过去 30 天)
显示 更早的评论
Dear everyone,
I found it to be very confusing to make the NanoVNA V2_2 to work with MATLAB.
On Matlab, a serialport object is to be used for serial port communication.
I am quite certain that I can send commands to the NanoVNA V2_2 like sweepStartHz, sweepStepHz, and swepPoints followed by the respective number, and the device responds to these commands by going into USB Mode.
The problem comes when I try to read the data from the device. I am just not able to do so. The MATLAB has commands like read and readline but how to use them with the NanoVNA V2_2? Is it the limited Matlab functionality of something else? I just cannot understand.
The code that works so far in my opinion is as follows:
port = 'COM4';
BaudRate = 9600;
device = serialport(port, BaudRate);
start = 100e6;
stop = 2e9;
points = 101;
step = (stop-start)/(points);
writeline(device,"sweepPoints"+ num2str(typecast(points,'uint16')));
writeline(device,"sweepStartHz"+ num2str(typecast(step,'uint64')));
writeline(device,"sweepStepHz"+ num2str(typecast(step,'uint64')));
回答(1 个)
Walter Roberson
2022-7-13
readline(device) possibly followed by using sscanf() to convert text into double.
2 个评论
Walter Roberson
2022-7-14
编辑:Walter Roberson
2024-2-13
Host to device command list shows that the commands are binary, not text, and are sent without separation. The command 0x0d is INDICATE (basically, test the link) and the response is always 0x32. Translating... when you send carriage return (0x0d) the device responds with the character '2' (0x32) which is decimal 50
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!