How to pass User input COM port into serial function?
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hello
I'm trying to create a inputdlg() where it ask the user to input the comport, which will then pass it to a serial function so it may communicate with an Arduino.
My problem is that when I run the code, it does gives me an "Invalid PORT specified" error. I type the comport in the inputdlg in paranthesis, e.g 'COM5', that doesn't work. I type just COM5, still doesn't work.
Reason why I do this is because the code is to be shared with different computers so they will hae to input different comports and what not.
Thanks to anyone who read and helps
if(~exist('serialFlag','var'))
prompt = {'Enter COM port number, if windows user use COM6 for example. If MAC user use /dev/tty. Use device manager to find Comport.'};
dlgtitle = 'COM port';
definput = {'COM5'};
answer = inputdlg(prompt,dlgtitle,[1 40],definput);
comPort = answer(1);
disp(comPort)
[gyroConnection.s,serialFlag]=setupSerial(comPort);
end
function [s,flag] = setupSerial2(comPort)
flag=1;
s=serial(comPort);
set(s,'DataBits',8);
set(s,'StopBits',1);
set(s,'BaudRate',9600);
set(s,'Parity','none');
fopen(s);
a='b';
while (a ~='a')
a=fread(s,1,'uchar');
end
if (a=='a')
disp('serial read');
end
fprintf(s,'%c','a');
mbox = msgbox('Serial Communication Setup.');
uiwait(mbox);
fscanf(s,'%u');
end
댓글 수: 1
Martin Velasquez
2019년 4월 16일
답변 (0개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!