請問為什麼我在
matlab的 command window 開啟port沒反應??
但是在GUI下開啟又正常.....請問各位神人問題在哪邊??
感謝各位神人。
func
tion result = PLCFNC(num,action)
try
s=serial('COM3','BaudRate',9600,'Parity','even','DataBits',7,'StopBits',1);
seris=s;
set(s,'OutputBufferSize',512);
set(s,'InputBufferSize',1024);
fopen(s);
catch
errmsg = lasterr;
errordlg(['不能打開port: COM3',char(10),'請檢查串口連接或該串口已打開'],'串口打開錯誤');
rethrow(lasterror);
end
switch num
case 0
if (action == 1)
tmp = '023730303035034646';
else
tmp = '023830303035033030';
end
case 1
if (action == 1)
tmp = '023730313035033030';
else
tmp = '023830313035033031';
end
case 2
if (action == 1)
tmp = '023730323035033031';
else
tmp = '023830323035033032';
end
case 3
if (action == 1)
tmp = '023730333035033032';
else
tmp = '023830333035033033';
end
case 4
if (action == 1)
tmp = '023730343035033033';
else
tmp = '023830343035033034';
end
case 5
if (action == 1)
tmp = '023730353035033034';
else
tmp = '023830353035033035';
end
case 6
if (action == 1)
tmp = '023730363035033035';
else
tmp = '023830363035033036';
end
case 7
if (action == 1)
tmp = '023730373035033036';
else
tmp = '023830373035033037';
end
case 10
if (action == 1)
tmp = '023730383035033037';
else
tmp = '023830383035033038';
end
case 11
if (action == 1)
tmp = '023730323935033038';
else
tmp = '023830393035033039';
end
case 12
if (action == 1)
tmp = '023730413035033130';
else
tmp = '023830413035033131';
end
case 13
if (action == 1)
tmp = '023730423035033131';
else
tmp = '023830423035033132';
end
case 14
if (action == 1)
tmp = '023730433035033132';
else
tmp = '023830433035033133';
end
case 15
if (action == 1)
tmp = '023730443035033133';
else
tmp = '023830443035033134';
end
case 16
if (action == 1)
tmp = '023730453035033134';
else
tmp = '023830453035033135';
end
case 17
if (action == 1)
tmp = '023730463035033135';
else
tmp = '023830463035033136';
end
%寫入命令
data = sscanf(tmp,'%02x')';
fwrite(s,data,'uint8');
fclose(s);
delete(s);
result = 1;
end