[問題]MATLAB的RS232通訊問題 已回收

看板MATLAB作者 (痛痛人)時間14年前 (2011/10/26 16:39), 編輯推噓3(307)
留言10則, 3人參與, 最新討論串1/1
想請問各位前輩我的程式是否有錯誤 因為都會跑出錯誤 小弟不才.所以想請教各位前輩 以下是我的程式code ===================== code ==================== s=serial('com1'); set(s,'BaudRate',115200); fopen(s); fprintf(s,'a'); out=fscanf(s); fclose(s); delete(s); clear s; 以下是出現的錯誤 ~~~~~~~~~~~~~~~~~~~~~ error ~~~~~~~~~~~~~~~~~~~ ??? Error using ==> serial.fopen at 72 Cannot connect to the COM1 port. Possible reasons are another application is connected to the port or the port does not exist. Error in ==> RS232_1 at 3 fopen(s); 其中??? Error using ==> serial.fopen at 72屬於內建的程式 錯誤的地方是:error('MATLAB:serial:fopen:opfailed', msg); 所以想請問各位前輩是我程式碼有錯還是它內建的程式碼有錯.謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.125.13.93

10/26 20:32, , 1F
你確定你要用的comport是com1??
10/26 20:32, 1F

10/27 00:18, , 2F
沒錯!!這點我有注意到
10/27 00:18, 2F

10/27 10:19, , 3F
你在第三行就錯了 一定是comport搞錯 設定到別的裝置在
10/27 10:19, 3F

10/27 10:20, , 4F
使用的 或著是你有用MATLAB成功使用過但不正常關閉
10/27 10:20, 4F

10/27 10:20, , 5F
那這樣你得重開MATLAB才可以
10/27 10:20, 5F

10/27 14:59, , 6F
我現在在set前面多加一行fclose(s);結果她顯示:
10/27 14:59, 6F

10/27 15:00, , 7F
Warning: A timeout occurred before the Terminator was
10/27 15:00, 7F

10/27 15:00, , 8F
reached.
10/27 15:00, 8F

10/27 15:14, , 9F
以解決~謝謝前輩給我的靈感^^
10/27 15:14, 9F

11/21 15:04, , 10F
請問你到後來是怎麼解決的
11/21 15:04, 10F
文章代碼(AID): #1EfySbqo (MATLAB)