필터 지우기
필터 지우기

Error using fclose Invalid file identifier. Use fopen to generate a valid file identifier.

조회 수: 2 (최근 30일)
Hello,
My code is:
% Find a serial port object.
obj1 = instrfind('Type', 'serial', 'Port', 'COM3', 'Tag', '');
obj1.Baudrate=115200;
obj1.Timeout=2000;
obj1.Terminator='CR';
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = serial('COM3');
else
fclose(obj1);
obj1 = obj1(1)
end
% Connect to instrument object, obj1.
fopen(obj1);
%send message
fprintf(obj1,'#1Zmt\r');
%read the command
fscanf(obj1)
Could you please help me? If I use the tmtool first,connect to the instrument and then Run this code, it will work. But if I open Matlab and try to run it, it gives me this error.
Thank you
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 3월 14일
Your code does not check that the fopen works, but you should be checking that it works before trying to use the port
I do not know why it is failing

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Instrument Connection and Communication에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by