cannot read from Serial Port object

조회 수: 4 (최근 30일)
Wendong
Wendong 2013년 5월 2일
Hi,
I am trying to communicate with a set of three flow meters (Omega FMA-1600A series) connected through a Serial-USB adapter. They are configured such that when the port receive 'A' (or 'B' or 'C'), the reading of the first (or the second, or the third) flow meter is sent back. This command line works well in the serial port program Terminal (https://sites.google.com/site/terminalbpp/)
In MatLab, I can create and connect to the serial port and get properties of the serial port, such as below: Serial Port Object : Serial-COM5
Communication Settings
Port: COM5
BaudRate: 19200
Terminator: 'LF'
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
However, when I sent letter 'A' using function fprintf(s,'A'), I receive no data back. See below:
s.BytesAvailable
ans =
0
I have read some of the answers to the problems in the community, and followed the steps to make sure that the device/port is on before turning on Matlab, and make sure that no other program is connected to the port. Still no success.
The system I am using R2012a, on Windows 7. Could anyone help with the issue? Thanks!!
Wendong
  댓글 수: 1
Matt Kindig
Matt Kindig 2013년 5월 3일
I note that the 'Status' of the port is shown as 'closed'. Have you made sure to fopen() the port first? Such as:
s= serial('COM5', ....); %your serial settings here
fopen(s);
fprintf(s,'A');
s.BytesAvailable

댓글을 달려면 로그인하십시오.

답변 (2개)

Wendong
Wendong 2013년 5월 15일
Hey Chago, I did solve the problem. I called the company who make the flow meters, and they instructed me to change the terminator from the "line feed (LF)" to "carriage return (CR)". And also, make sure that when you fprintf, include a CR in the format string like "%s\r". The default "\n" (which is line feed) does not work with the flow meters I have.
I don't know the specifics of your device, but I suppose there might be some subtle things you have to tweak in order to make it work. Why not call the manufacturer to find out more?
Wish you good luck! Wendong

Chago Rodriguez
Chago Rodriguez 2013년 5월 15일
Wendog,
Have you resolved your issue ... I am super frustrated ... try everything ... an dit looks form MANY postings that this is a REAL flaw with MATLAB.
Like most everybody, I can communicate with between PC and device OK. I can write commands to the serial device (FMCW Radar), and commands are accepted. But I cannot READ anything and BytesAvailable also returns ZERO.
I have MATLAB R2012b, I took care of terminators, correctly setting DTR ..., to no avail. Let me know if you have a solution.
Chago

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by