我用vs2005編寫的串列埠應用程式,寫好後同步到6410板子上
...
//開啟串列埠
bool cserial1dlg::openport(lpctstr port, int baudrate, int databits, int stopbits, int parity)
getcommstate(hcomm, &dcb); /* 讀取串列埠的dcb */
dcb.baudrate= baudrate; /*設定波特率*/
dcb.bytesize = databits; /*設定資料位*/
dcb.parity= parity; /*設定校驗位*/
dcb.stopbits= stopbits; /*設定停止位*/
dcb.fparity= false; /* 禁止奇偶校驗*/
dcb.fbinary= true;
dcb.foutx= 0;
dcb.finx= 0;
//設定狀態引數
setcommmask(hcomm, ev_rxchar); /* 串列埠事件:接收到乙個字元*/
setupcomm(hcomm, 16384, 16384); /* 設定接收與傳送的緩衝區大小*/
setcommstate(hcomm, &dcb);
bool issucces=setcommstate(hcomm, &dcb);/* 設定串列埠的dcb */
if(!issucces)
getcommtimeouts(hcomm, &commtimeouts); /*獲得超時引數*/
//設定超時引數
commtimeouts.readintervaltimeout = 100; /* 接收字元間最大時間間隔*/
commtimeouts.readtotaltimeoutmultiplier = 1;
commtimeouts.readtotaltimeoutconstant = 100; /* 讀資料總超時常量*/
commtimeouts.writetotaltimeoutmultiplier = 0;
commtimeouts.writetotaltimeoutconstant = 0;
if(!setcommtimeouts(hcomm, &commtimeouts))
purgecomm(hcomm, purge_txclear | purge_rxclear); /* 清除收/發緩衝區*/
return true;
} bool cserial1dlg::closeport(void)
return false;
} void callback cserial1dlg::oncomrecv(cwnd* pwnd, char *buf, int buflen)
precvstredit->setwindowtext(pdlg->strrecdisp); /* 顯示在視窗上*/
} dword cserial1dlg::comrecvthread(lpvoid lparam)
else }
} delete recvbuf;
return 0;
} void cserial1dlg::onopencom()
closehandle(hrecvthread);
butopen.enablewindow(false); /* 開啟埠按鍵禁止*/
butclose.enablewindow(true); /* 關閉埠按鍵使能*/
messagebox(_t("開啟串列埠com1成功!"));
} //「關閉串列埠」訊息處理
void cserial1dlg::onclosecom()
butopen.enablewindow(true); /* 開啟埠按鍵禁止*/
butclose.enablewindow(false); /* 關閉埠按鍵使能*/
closeport();
} //「傳送」訊息處理
void cserial1dlg::onsend()
updatedata(true);
int len = strsendedit.getlength(); /* 取得輸入字串長度*/
char *psendbuf = new char[len];
for(int i = 0; i < len;i++)
psendbuf[i] = (char)strsendedit.getat(i); /* 轉換為單位元組字元*/
writefile(hcomm, psendbuf, len, &dwactlen, null); /* 從串列埠傳送資料*/
delete psendbuf;
} //程式結束呼叫的函式
void cserial1dlg::ondestroy()
closeport(); /* 關閉串列埠*/
} ...
八串列埠擴充套件
今天老大讓我想實現在arm板上擴充套件八個串列埠的方法,用來連線外設。之前,提到監控系統,我想到影象傳輸需要較大頻寬的問題,串列埠能滿足傳輸率嗎?如果連線攝像頭的話,我想到,可以不可以擴充套件usb,利用usb來傳輸攝像頭拍攝的影象資訊。我猜測,如果需要特殊的要求,例如 8串列埠板,加hdmi,sa...
4 串列埠驅動
1 初始化gpio的模式和速度 2 配置中斷優先順序分組 3 串列埠初始化 4 串列埠服務函式編寫 我是分割線 一 gpio初始化 gpio埠設定 gpio inittypedef gpio initstructure rcc apb2periphclockcmd rcc apb2periph gp...
龍芯軟體開發 14 串列埠輸出
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!串列埠輸出東西太重要了,因此,再來仔細地看看串列埠呼叫的其它函式,這樣做到一目了然,沒有別的疑問在裡面,就可以做到庖丁解牛游刃有餘。像下面的函式 printstr config 上面這句,就是輸出一串字元到串裡顯示出來。其實它是乙個巨集定義,那麼它...