I am trying to setup a serial communication with a optical power meter and I am not able to read the returned string.
조회 수: 6 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
채택된 답변
dpb
2024년 8월 8일
편집: dpb
2024년 8월 8일
"I cant turn it off on the keypad...."
I'd be pretty sure there is a place in the menu system given that the vendor manual says there is...you may not have found it yet, but it'll be there. Contact the vendor support if needs be; that isn't a MATLAB problem.
But
writeline(s,"PM:ECHO echo set")
won't be the correct syntax to turn it off...it'll need a value of <0> somewhere in the command -- whether the syntax includes an <=> sign or not you'll have to read the documentation to ascertain, but your command as above is not correct syntax, I'd be certain...
Dig more deeply into the documentation for examples and/or contact the vendor or ask in their support group; but this isn't MATLAB but the instrument command syntax that has to come from its documentation and/or the vendor.
8.3.3.8 ECHO
Description Echo command
Syntax ECHO echo set
Remarks The ECHO command is used to turn ON or OFF the
echoing of commands sent to the power meter over RS-232
communication interface. By default, the echo is turned
ON.
Response Value Description
echo set 0 Echo OFF
1 Echo ON
The doc specifically says the value of the "echo set" parameter is 0|1 to turn it off|on and the example at the beginning of the section shows there is no equal sign used, just space delimited.
The list of commands in table 8.3.1 on p 70 of the doc also does NOT include the "PM:" prefix that some others do; read and follow the details of each command precisely as they are documented...
writeline(s,"ECHO 0")
댓글 수: 2
dpb
2024년 8월 8일
편집: dpb
2024년 8월 8일
ADDENDUM: I would submit that using
Response Value Description
could be a little misleading to the inexperienced instrumentation user--it would be more accurate if it were
Parameter Value Description
or
Argument Value Description
since it is a command, not a query.
I didn't go back and look at the manual again to see if this was just a one-time foopah where the ECHO? query command was copied over and the editors missed fixing it or whether it is consistent throughout. Either way, send the value desired, not the descriptive parameter name text in the format described.
추가 답변 (2개)
dpb
2024년 8월 7일
이동: dpb
2024년 8월 8일
"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일
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!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!