0
我是Matlab OOP的新手。 我附上了一個類,我試圖打開一個串口。我能夠生成SERIAL OBJ,但fopen函數不起作用。地位從未轉向。在matlab中的序列obj類
classdef Channel
properties
COM
Baudrate
SERIAL_obj
end
methods
% Constructor
function thisChannel=Channel(COM,Baudrate)
if nargin==2
thisChannel.COM=COM;
thisChannel.Baudrate=Baudrate;
end
end
% Generate SERIAL OBJ
function SERIAL_obj=get.SERIAL_obj(thisChannel)
SERIAL_obj = serial(thisChannel.COM,'Baudrate',thisChannel.Baudrate);
end
% Connect to SERIAL OBJ
function OPEN_SERIAL(thisChannel)
fopen(thisChannel.SERIAL_obj);
pause(0.2)
end
這裏是生成對象的腳本:
c=Channel('COM197',230400);
OPEN_SERIAL(c)
下面是結果:
Serial Port Object : Serial-COM196
Communication Settings
Port: COM196
BaudRate: 230400
Terminator: 'LF'
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0