KYT7201读卡器波特率修改问题求助
智能卡读卡器波特率设置问题
我正在开发一个用C语言编写的智能卡读写程序,使用的KYT7201读卡器通过COM口连接电脑。目前文件读写功能正常,但调整波特率时遇到问题。
根据读卡器手册7.3节的说明,我发送了设置38400波特率的命令:02000242020341,收到的返回值是0200034E3035034B,但波特率仍保持默认的19200(仍能通过19200波特率的COM口读卡)。
核心疑问:
- 该波特率设置命令应何时发送?
- 为何读卡器未更改波特率?
- 是否需要使用PPSS等其他命令?
- 正确的设置命令是什么?
我使用WinAPI的WriteFile发送命令,相关代码如下:
const uint8_t SendBitRate [0x7] = {0x02, 0x00, 0x02, 0x42 , 0x00, 0x03, 0x43}; void outputToPort(HANDLE* hCom, char* msgOut, int msgOutLen) { int i=0; DWORD NumberofBytesTransmitted; LPDWORD lpErrors=0; LPCOMSTAT lpStat=0; i = WriteFile( *hCom, msgOut, msgOutLen, &NumberofBytesTransmitted, NULL ); if (i == 0) { printf("\nWrite Error: 0x%x\n", GetLastError()); ClearCommError(hCom, lpErrors, lpStat); // Clears the device error flag to enable additional input and output operations. Retrieves information of the communications error. } //else // printf("\nSuccessful transmission, there were %ld bytes transmitted\n", NumberofBytesTransmitted); } DWORD inputFromPort(HANDLE* hCom, LPVOID buf, DWORD szBuf) { int i = 0; DWORD NumberofBytesRead; LPDWORD lpErrors = 0; LPCOMSTAT lpStat = 0; i = ReadFile( *hCom, buf, szBuf, &NumberofBytesRead, NULL ); if (i == 0) // Handle the timeout error { printf("\nRead Error: 0x%x\n", GetLastError()); ClearCommError(hCom, lpErrors, lpStat); // Clears the device error flag to enable additional input and output operations. Retrieves information ofthe communications error. } return(NumberofBytesRead); }
内容的提问来源于stack exchange,提问作者mikerock
相关产品推荐
相关产品推荐

