Matlab串列埠讀取錯誤

2021-09-28 01:04:52 字數 2049 閱讀 3303

matlab串列埠讀取錯誤)

fwrite(scom,uint8(hex2dec(moter_monitor(moto_num))));

outdec = fread(scom,17,'uchar');

outhex = dec2hex(outdec)

outstr = reshape(outhex.',1,);

motohz = hex2dec(outstr(7:10))/10; %輸出頻率

motoa = hex2dec(outstr(11:14))/10; %輸出電流

motov = hex2dec(outstr(15:18)); %輸出電壓

motorpm = hex2dec(outstr(19:22)); %電機轉速

motodcv = hex2dec(outstr(23:26)); %內部直流電壓

motoinputv = hex2dec(outstr(27:30)); %輸入電壓

set(handles.text13,'string',motohz);

set(handles.text14,'string',motoa);

set(handles.text15,'string',motov);

set(handles.text16,'string',motorpm);

set(handles.text17,'string',motoinputv);

set(handles.text18,'string',motodcv)

;

在寫matlab串列埠程式的過程中,在timer中設定了一組主機輪詢的程式,單獨執行時串列埠讀取正常,資料切片也顯示正常。但是在guide中執行時,資料切片顯示的資料一直存在問題。

function pushbutton2_callback(hobject, eventdata, handles)

% hobject handle to pushbutton2 (see gcbo)

% eventdata reserved - to be defined in a future version of matlab

% handles structure with handles and user data (see guidata)

global scom moto_num rotspd

rotspd = str2num(get(handles.edit2,'string'));

fwrite(scom,uint8(hex2dec(request_spd(moto_num,rotspd))

));

經過檢查發現在程式的其他地方存在乙個串列埠的寫入程式 fwrite(scom,uint8(hex2dec(request_spd(moto_num,rotspd))));

但是此處並沒有進行串列埠的讀取,使得資料在串列埠快取中累積,而timer中串列埠的讀取從此處累計的開始讀取,所以使得timer的資料切片不正常。

修改後

function pushbutton2_callback(hobject, eventdata, handles)

% hobject handle to pushbutton2 (see gcbo)

% eventdata reserved - to be defined in a future version of matlab

% handles structure with handles and user data (see guidata)

global scom moto_num rotspd

rotspd = str2num(get(handles.edit2,'string'));

fwrite(scom,uint8(hex2dec(request_spd(moto_num,rotspd))));

fread(scom,8,'uchar'

);

讀取串列埠資料 MATLAB讀取JY901串列埠資料

這個jy901的體積比較小,最關鍵是使用起來很方便。串列埠通訊,基本上線一接。驅動一裝。開啟上位機三個軸的角度資料就出來了。借商家的上位機給大家看看結果。他們這個三個軸的角度是根據東北天座標系來定義。如下圖所示。大致思路和大家說一下簡答分成兩個部分串列埠程式編寫和資料處理 現在jy901是通過串列埠...

關閉串列埠 MATLAB讀取串列埠資料(一 指令碼

今天我們來介紹如何編寫在matlab中編寫指令碼來讀取串列埠資料。matlab中內建了串列埠功能函式,我們在使用時只需要呼叫函式進行相應配置即可,我們來看串列埠函式。serial s p,parity none baudrate baudrate1,databits 8,stopbits 1 這個函...

串列埠 matlab 示波器

具體的,我使用115200bps的串列埠速度傳送資料,然後在pc上用串列埠獵人接收,並將資料儲存成txt格式文字,完成後開啟matlab,在mtalab中執行本程式即可。由於fpga串列埠程式不難,自己編寫即可,需要注意的是串列埠傳送和接收順序 串列埠一般是由低到高傳送 需要保證在pc上還原出的資料...