I am trying to setup a serial communication with a optical power meter and I am not able to read the returned string.
古いコメントを表示
I am using a newport power meter (91936-R) with RS232. I set up the communication with the following code beow. I am running into a weird situation.
The readlinerespone is The first is ""PM:CALDATE?" However when I send the readline command again I get the right response "30NOV2022". Its almost like readline stops once it reaches the first termination character and doesnt continue. I tried adding a pause incase I am reading the port too fast but no sucess.
I am not sure and matlab doesnt have more documention online on serial port so I was hoping someone can answer this.
clear s
clear all
s = serialport("COM12",38400);
configureTerminator(s,"CR/LF","CR");
writeline(s,"PM:CALDATE?")
% pause(4)
readline(s)
%readline(s)
採用された回答
その他の回答 (2 件)
"The RS232 Parameters are fixed at Baud Rate 38400, Data Bits 8, Stop Bits 1, Parity None, Xon/Xoff Xoff"
Have you verified the rest of the protocol besides the baud rate?
Looks like maybe the echo mode is on so you're seeing the instrument echo the command back to you...
7.4.1 Setting Echo Mode From the Keypad
The echo mode can be turned ON/OFF from within the menu structure.
7.4.2 Setting Echo Mode via Remote Interface
To set the echo mode use the “ECHO” command. Use the “ECHO?” to see if the echo mode is enabled or disabled.
Garmit Pant
2024 年 8 月 7 日
0 投票
Hello OmartheEngineer,
Based on the details you have provided, the output of the “readline” function seems to be the expected behavior of the function.
For loopback devices connected to a port, the data you write to the device is returned to MATLAB. According to the user manual of the Newport Power Meter (91936-R) device, it has multiple ‘ECHO’ modes. When the ‘ECHO’ mode is enabled, all characters sent to the power meter are echoed back over the interface. Therefore, if the device has its ‘ECHO’ mode enabled, the “readline” function reads the response as the message written using the “writeline” function.
You can refer to Section 7.4 “RS-232C Communication” in the user manual to get more information about the device communicating over the RS-232 port.
For further understanding, kindly refer to the following MathWorks documentation:
- Refer to the ‘Examples’ section to understand the behavior of the “readline” and “writeline” functions: readline() Documentation.
I hope you find the above explanation and suggestions useful!
カテゴリ
ヘルプ センター および File Exchange で Instrument Control Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!