Serial communication with device: cannot initialize connection, but commands work after initializing in LabView

3 ビュー (過去 30 日間)
Issue:
I cannot initialize a serial connection with a peristaltic pump and assign it a name using the Instrument Control Toolbox in Matlab 2015b. Strangely, if I initialize the pump in LabView on the relevant COM port, I can then send commands from MATLAB that the pump will execute.
Pump model: Cole-Parmer Masterflex 07551-30
Communication info from pump manual:
The serial data format is full duplex (simultaneously transmit and receive), 1 start bit, 7 data bits, one odd parity bit, and one stop bit at 4800 bits per second. All data transmitted will consist of characters from the standard ASCII character set. The computer should send the enquire <ENQ> command, then the pump responds with a line of the form "<STX>P?0<CR> = 600 rpm", and then the computer can assign a name (e.g. P01) by sending <STX>P01<CR>.
MATLAB initialization (doesn't work):
My code is below. The communication settings as the same as the LabView VISA (see below). The pump doesn't send any information to the serial port in response to this code, and won't execute commands subsequently sent to it.
obj = serial(com);
COMData={4800,7,'none','odd',1,'CR'};
set(obj,{'BaudRate','DataBits','FlowControl','Parity','StopBits','Terminator'},COMData)
fopen(obj);
fprintf(obj,'\05'); pause(0.1) %Enquire
fprintf(obj,'\02P01\r'); pause(0.1) %name pump P01
fclose(obj);
Steps that didn't work:
  1. Using a VISA in Matlab (vendor is NI, serial resource) instead of a serial object to initialize. I get the same behavior as with the serial object: the pump doesn't respond to the initialization code, but after initializing in LabView, the pump will execute commands sent by the VISA object.
  2. Using fwrite instead of fprintf.
  3. Changing the CR command from \r to 13.
LabView initialization (which works):
Configures a VISA with the given communication settings (also with FlowControl = none) and writes the enquire command \05 to the pump, then writes \02P01\r. The pump can then receive and execute commands from MATLAB like fprintf(obj, '\P01CMD\r'), where obj is the serial object and "CMD" is some arbitrary command. A screenshot of the LabView VI is attached (original source files are here).
  1 件のコメント
Charan Jadigam
Charan Jadigam 2020 年 3 月 23 日
編集済み: Charan Jadigam 2020 年 3 月 23 日
Try sending the 'ENQ' command with termination character.
fprintf(obj,'\05\r');
and also pause for some time after fopen() as initiliazation process might take some time and fopen() does not wait until iniliazation is completed.You can pause using
pause(<seconds>)

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLabVIEW についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by