[英]baudrate serial windows port
為了探測 windows 串口我寫了這個程序。 我將串口波特率設置為 115200 bps。 當我運行這個程序時,經過的時間是 1250 毫秒,所以波特率只能達到 102400 bps。 我還用類似的程序檢查接收波特率,波特率是相同的。
這是程序:
char* message =
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
int numBytes = 144;
c0 = clock()
for (;;)
{
sendSerial(&hCom, message, numBytes );
tx +=numBytes;
//14400 bytes * 8 = 115200 bps
if (tx >= 14400)
{
c1 = clock();
runtime_diff_ms = (c1 - c0) * 1000. / CLOCKS_PER_SEC;
printf("Tx frames %d Time ms %f", tx, runtime_diff_ms);
system ("pause");
return -1;
}
}
bool sendSerial(HANDLE *hCom, char *WriteBuffer, DWORD dwBytesToWrite)
{
DWORD dwBytesWritten = 0;
BOOL bErrorFlag = FALSE;
bErrorFlag = WriteFile(
*hCom, // open file handle
WriteBuffer, // start of data to write
dwBytesToWrite, // number of bytes to write
&dwBytesWritten, // number of bytes that were written
NULL);
...
}
這些是我的串口規格:
DCB dcbSerialParams;
COMMTIMEOUTS timeouts;
dcbSerialParams.BaudRate=CBR_115200;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
timeouts.ReadIntervalTimeout=MAXDWORD;
timeouts.ReadTotalTimeoutMultiplier=MAXDWORD;
timeouts.ReadTotalTimeoutConstant=5000; // 5sec
timeouts.WriteTotalTimeoutMultiplier=10;
timeouts.WriteTotalTimeoutConstant=100;
有誰知道如何解決這個問題以達到 115200 bps?
每個字符有 10 位 - 8 位用於數據加上一個開始和停止位。
如果您計算在 115200 bps 下每個字符 10 位的 14400 個字符應該花費多長時間,那么您將得到 1250 毫秒:
(14400 characters * 10 bits/character) / (115200 bits/second) = 1.250 seconds
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.