Help with read/readline with serialport object for NanoVNA V2_2
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Antworten (1)
Walter Roberson
am 13 Jul. 2022
readline(device) possibly followed by using sscanf() to convert text into double.
2 Kommentare
Walter Roberson
am 14 Jul. 2022
Bearbeitet: Walter Roberson
am 13 Feb. 2024
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
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!