如题所述
示ä¾ï¼ä» ä¾åèï¼
// 1.æå¼ä¸²è¡éä¿¡å£ï¼ä¿å串å£å¥æhCom=CreateFile("////.//COM10", GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);if(hCom==(HANDLE)INVALID_FILE_SIZE){MessageBox("端å£æ æ³æå¼");
return;}if(hCom != INVALID_HANDLE_VALUE){// 设置端å£SetupComm(hCom,OUT_BUFF_SIZE,IN_BUFF_SIZE);DCB myDCB;GetCommState(hCom, &myDCB);myDCB.BaudRate=57600;// æ³¢ç¹çmyDCB.fBinary=TRUE;// éä¿¡æ¹å¼ï¼äºè¿å¶myDCB.fParity=TRUE;// å¥å¶æ ¡éª TRUEï¼ä½¿ç¨ï¼FALSEï¼ä¸ä½¿ç¨myDCB.Parity=1; // æ ¡éªæ¹å¼:0ï¼æ 1ï¼å¥ 2ï¼å¶ 3ï¼æ å¿ 4ï¼ç©ºæ ¼myDCB.ByteSize=8;// æ°æ®ä½æ°myDCB.StopBits=1;// åæ¢ä½æ°:0ï¼1ä½ 1ï¼1.5ä½ 2ï¼2ä½SetCommState(hCom, &myDCB);}else{
MessageBox("端å£æ æ³æå¼");
return;}// 2.åéæ°æ®WriteFile(hCom, &datas, Len, NULL, NULL);// 3. 读ç¼å²åºå¹¶å¤çæ¶å°çæ°æ®ReadFile(hCom, &myByte, Len, NULL, NULL);
温馨提示:答案为网友推荐,仅供参考