Недавно я подключил контрольную вышку реактора через последовательный порт «COMMS» к моему компьютеру (от последовательного порта до USB). Кажется, создается соединение через порт COM4 (как указано в разделе «Устройства и принтеры» на панели управления). Тем не менее, это всегда дает мне следующее сообщение, когда я пытаюсь 'fwrite (s)' или 'fscanf (s)'.
Предупреждение. Неудачное чтение: указанный объем данных не был возвращен в течение периода ожидания.
%My COM4
s = serial('COM4');
s.BaudRate = 9600;
s.DataBits = 8;
s.Parity ='none';
s.StopBits = 1;
s.FlowControl='none';
s.Terminator = ';';
s.ByteOrder = 'LittleEndian';
s.ReadAsyncMode = 'manual';
% Building write message.
devID = '02'; % device ID
cmd = 'S'; % command read or write; S for write
readM = cell(961,3);% Read at most 961-by-3 values filling a 961–by–3 matrix in column order
strF = num2str(i);
strF = '11'; %pH parameter
strP = '15'; %pH set point
val = '006.8'; %pH set value
msg_ = strcat('!', devID, cmd, strF, strP, val);%output the string
chksum = dec2hex(mod(sum(msg_),256)); %conversion to hexdec
msg = strcat(msg_,':', char(chksum), ';');
fopen(s); %connects s to the device using fopen , writes and reads text data
fwrite(s, uint8(msg)); %writes the binary data/ Convert to 8-bit unsigned integer (unit8) to the instrument connected to s.
reply=fscanf(s); %reads ASCII data from the device connected to the serial port object and returns it to reply, for binary data use fread
fclose(s); %Disconnect s from the scope, and remove s from memory and the workspace.
Это заставляет меня поверить, что устройство подключено, но не отправляет или не получает информацию, и я не уверен, как я могу настроить это или даже реально проверить, происходит ли связь между башней и моим компьютером.