cannot read from Serial Port object

11 visualizzazioni (ultimi 30 giorni)
Wendong
Wendong il 2 Mag 2013
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 Commento
Matt Kindig
Matt Kindig il 3 Mag 2013
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

Accedi per commentare.

Risposte (2)

Wendong
Wendong il 15 Mag 2013
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 il 15 Mag 2013
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

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by