VISA Serial Read - Unsuccessful read: A timeout occurred before the Terminator was reached.
I am trying to interact with stepper motor controllers using VISA serial communications. I have NI-DAQmx and NI-VISA support packages installed within MATLAB R2016a. Serial writes seem to function perfectly; however, serial reads issue a timeout warning (“Warning: Unsuccessful read: A timeout occurred before the Terminator was reached.”) and always take at least 1 second. Surprisingly, the serial read always retrieves the expected data. I have already have tried shortening (down to 1 ms) and lengthening (up to 10 s) the timeout, implementing a pause before reading the serial data (to give the controller time to process my request and put data onto the serial bus), and tried changing the read terminators to every possible ASCII character. The last characters in every data read are always (ASCII): EXT, CR and LF. Bottom line is that serial read kind of works, but always has a timeout warning and takes too long (at least 1 second). My code is attached. Any help or advice would be much appreciated!
% Serial settings vs = visa('ni', 'ASRL3::INSTR'); % Create VISA serial object vs.BaudRate = 9600; % Rate of transmission [bit/s] vs.DataBits = 8; % Number of data bits vs.Parity = 'none'; % No parity vs.FlowControl = 'none'; % No flow control vs.StopBits = 1; % Number of stop bits vs.Terminator = {'LF', 'CR'}; % Read and write terminator set(vs, 'Timeout', 0.05); % Set timeout [s]
query_cmds = '/1?8R'; % String to request encoder position
% Send serial commands to controllers fopen(vs); % Open serial port pause(.010) % Time delay [s]
disp('Query Commands Sent to Controllers') disp(query_cmds) fprintf(vs, query_cmds); % Ask controllers for encoder position tic query_resp = fscanf(vs); toc
fclose(vs); % Close serial port
0 Commenti
Risposta accettata
3 Commenti
Più risposte (0)
Vedere anche
Categorie
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!