串行設備驅動_第1頁
串行設備驅動_第2頁
串行設備驅動_第3頁
串行設備驅動_第4頁
串行設備驅動_第5頁
已閱讀5頁,還剩30頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

串行設備驅動第一頁,共三十五頁,編輯于2023年,星期六主要內(nèi)容1、WindowsCE.net串行設備簡介2、串口設備驅動3、串行設備API簡介4、串口設備操作5、紅外設備簡介第二頁,共三十五頁,編輯于2023年,星期六1、WindowsCE.net串行設備簡介第三頁,共三十五頁,編輯于2023年,星期六WindowsCE.net串行設備WindowsCE.net的串行設備應用十分廣泛GPRS通信智能數(shù)據(jù)終端GPS定位系統(tǒng)紅外通訊設備第四頁,共三十五頁,編輯于2023年,星期六使用通用碼流進行數(shù)據(jù)傳輸,與標準串口完全兼容支持3線/9線串口方式串口模型基本延續(xù)了桌面系統(tǒng)的風格和基本的API,但未封裝成類第五頁,共三十五頁,編輯于2023年,星期六串口的7層結構第六頁,共三十五頁,編輯于2023年,星期六第七頁,共三十五頁,編輯于2023年,星期六Netarm2410-S串行設備情況UART0(3線)標準格式化信息輸出串口;基本通訊串口UART1(3線)基本通訊串口(未使用)UART2(3線)紅外通訊串口;基本通訊串口第八頁,共三十五頁,編輯于2023年,星期六2、串口設備驅動第九頁,共三十五頁,編輯于2023年,星期六串口設備驅動是一種流驅動BSP中提供的串口驅動模型較為復雜,在結構上也分層為MDD和PDD層第十頁,共三十五頁,編輯于2023年,星期六第十一頁,共三十五頁,編輯于2023年,星期六第十二頁,共三十五頁,編輯于2023年,星期六3、串行設備API簡介第十三頁,共三十五頁,編輯于2023年,星期六串口的APICreateFileOpensaserialport.GetCommStateFillsinadevice-controlblock—DCBstructure—withthecurrentcontrolsettingsforaspecifiedcommunicationdevice.SetCommStateConfiguresacommunicationdeviceaccordingtothespecificationsinaDCBstructure.Thefunctionreinitializesallhardwareandcontrolsettings,butdoesnotemptyI/Oqueues.GetCommTimeoutsRetrievesthetime-outparametersforallread/writeoperationsonaspecifiedcommunicationdevice.SetCommTimeoutsSetsthetime-outparametersforallread/writeoperationsonaspecifiedcommunicationdevice.WriteFileWritesdatatoaserialport,whichtransfersdatatothedeviceattheotherendofaserialconnection.ReadFileReadsdatafromaserialport,whichreceivesdatafromadeviceattheotherendofaserialconnection.第十四頁,共三十五頁,編輯于2023年,星期六串口的APISetCommMaskSpecifiesasetofeventstomonitorforacommunicationdevice.GetCommMaskRetrievesthevalueoftheeventmaskforaspecifiedcommunicationdevice.WaitCommEventWaitsforaneventtooccurforaspecifiedcommunicationdevice.ThesetofeventsmonitoredbyWaitCommEventiscontainedintheeventmaskassociatedwiththedevicehandle.EscapeCommFunctionDirectsaspecifiedcommunicationdevicetoperformanextendedfunction.OftenusedtosetaserialporttoIRmode.ClearCommBreakRestorescharactertransmissionforaspecifiedcommunicationdeviceandplacesthetransmissionlineinanon-breakstate.ClearCommErrorRetrievescommunicationerrordataandreportsthecurrentstatusofaspecifiedcommunicationdevice.第十五頁,共三十五頁,編輯于2023年,星期六4、串口設備操作第十六頁,共三十五頁,編輯于2023年,星期六打開串口//Opentheserialport.hPort=CreateFile(lpszPortName,//PointertothenameoftheportGENERIC_READ|GENERIC_WRITE,//Access(read-write)mode0,//SharemodeNULL,//PointertothesecurityattributeOPEN_EXISTING,//Howtoopentheserialport0,//PortattributesNULL);//Handletoportwithattribute//tocopy第十七頁,共三十五頁,編輯于2023年,星期六配置串口//InitializetheDCBlengthmember.PortDCB.DCBlength=sizeof(DCB);//Getthedefaultportsettinginformation.GetCommState(hPort,&PortDCB);//ChangetheDCBstructuresettings.PortDCB.BaudRate=9600;//CurrentbaudPortDCB.fBinary=TRUE;//Binarymode;noEOFcheckPortDCB.fParity=TRUE;//EnableparitycheckingPortDCB.fOutxCtsFlow=FALSE;//NoCTSoutputflowcontrolPortDCB.fOutxDsrFlow=FALSE;//NoDSRoutputflowcontrolPortDCB.fDtrControl=DTR_CONTROL_ENABLE;//DTRflowcontroltypePortDCB.fDsrSensitivity=FALSE;//DSRsensitivityPortDCB.fTXContinueOnXoff=TRUE;//XOFFcontinuesTxPortDCB.fOutX=FALSE;//NoXON/XOFFoutflowcontrolPortDCB.fInX=FALSE;//NoXON/XOFFinflowcontrolPortDCB.fErrorChar=FALSE;//DisableerrorreplacementPortDCB.fNull=FALSE;//DisablenullstrippingPortDCB.fRtsControl=RTS_CONTROL_ENABLE;//RTSflowcontrolPortDCB.fAbortOnError=FALSE;//Donotabortreads/writesonerrorPortDCB.ByteSize=8;//Numberofbits/byte,4-8PortDCB.Parity=NOPARITY;//0-4=no,odd,even,mark,spacePortDCB.StopBits=ONESTOPBIT;//0,1,2=1,1.5,2//ConfiguretheportaccordingtothespecificationsoftheDCBstructure.if(!SetCommState(hPort,&PortDCB)){//Couldnotconfiguretheserialport.dwError=GetLastError();MessageBox(hMainWnd,TEXT("Unabletoconfiguretheserialport"),TEXT("Error"),MB_OK);returnFALSE;}第十八頁,共三十五頁,編輯于2023年,星期六設置超時值//Retrievethetime-outparametersforallreadandwriteoperationsontheport.COMMTIMEOUTSCommTimeouts;GetCommTimeouts(hPort,&CommTimeouts);//ChangetheCOMMTIMEOUTSstructuresettings.CommTimeouts.ReadIntervalTimeout=MAXDWORD;CommTimeouts.ReadTotalTimeoutMultiplier=0;CommTimeouts.ReadTotalTimeoutConstant=0;CommTimeouts.WriteTotalTimeoutMultiplier=10;CommTimeouts.WriteTotalTimeoutConstant=1000;//Setthetime-outparametersforallreadandwriteoperationsontheport.if(!SetCommTimeouts(hPort,&CommTimeouts)){//Couldnotsetthetime-outparameters.MessageBox(hMainWnd,TEXT("Unabletosetthetime-outparameters"),TEXT("Error"),MB_OK);dwError=GetLastError();returnFALSE;}第十九頁,共三十五頁,編輯于2023年,星期六寫串口DWORDdwError,dwNumBytesWritten;WriteFile(hPort,//Porthandle&Byte,//Pointertothedatatowrite1,//Numberofbytestowrite&dwNumBytesWritten,//Pointertothenumberofbytes//writtenNULL//MustbeNULLforWindowsCE);第二十頁,共三十五頁,編輯于2023年,星期六讀串口BYTEByte;DWORDdwBytesTransferred;ReadFile(hPort,//Porthandle&Byte,//Pointertodatatoread1,//Numberofbytestoread&dwBytesTransferred,//Pointertonumberofbytes//readNULL//MustbeNULLforWindowsCE);第二十一頁,共三十五頁,編輯于2023年,星期六使用通訊事件BYTEByte;DWORDdwBytesTransferred;//Specifyasetofeventstobemonitoredfortheport.SetCommMask(hPort,EV_RXCHAR|EV_CTS|EV_DSR|EV_RLSD|EV_RING);while(hPort!=INVALID_HANDLE_VALUE){//Waitforaneventtooccurfortheport.WaitCommEvent(hPort,&dwCommModemStatus,0);//Re-specifythesetofeventstobemonitoredfortheport.SetCommMask(hPort,EV_RXCHAR|EV_CTS|EV_DSR|EV_RING);if(dwCommModemStatus&EV_RXCHAR){//Loopforwaitingforthedata.do{//Readthedatafromtheserialport.ReadFile(hPort,&Byte,1,&dwBytesTransferred,0);//Displaythedataread.if(dwBytesTransferred==1)ProcessChar(Byte);}while(dwBytesTransferred==1);}第二十二頁,共三十五頁,編輯于2023年,星期六通訊事件簡介Event DescriptionEV_BREAK Abreakoccurredoninput.EV_CTS TheCTSsignalchangedstate.EV_DSR TheDSRsignalchangedstate.EV_ERR Aline-statuserroroccurred.Line-statuserrorsareCE_FRAME,CE_OVERRUN,andCE_RXPARITY.EV_RING Aringindicatorwasdetected.EV_RLSDThereceive-line-signal-detectsignalchangedstate.EV_RXCHAR Acharacterwasreceivedandplacedintheinputbuffer.EV_RXFLAG Theeventcharacterwasreceivedandplacedintheinputbuffer.EV_TXEMPTY Thelastcharacterintheoutputbufferwassent.第二十三頁,共三十五頁,編輯于2023年,星期六關閉串口BOOLCloseHandle(HANDLEhObject);關閉一個已經(jīng)打開的對象句柄,使用這種方法來關閉串口參數(shù):待關閉的句柄返回值:是否關閉成功第二十四頁,共三十五頁,編輯于2023年,星期六5、紅外設備簡介第二十五頁,共三十五頁,編輯于2023年,星期六紅外通訊紅外線是波長在750nm至1mm之間的電磁波,其頻率高于微波而低于可見光,是一種人的眼眼看不到的光線。目前無線電波和微波已被廣泛應用在長距離的無線通信中,但由于紅外線的波長較短,對障礙物的衍射能力差,所以

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論