简体   繁体   English

波特率串口 windows 端口

[英]baudrate serial windows port

To probe the windows serial port I have written this program.为了探测 windows 串口我写了这个程序。 I set the serial port baudrate to 115200 bps.我将串口波特率设置为 115200 bps。 When I run this program the elapsed time is 1250 ms, so that, the baudrate only reachs 102400 bps.当我运行这个程序时,经过的时间是 1250 毫秒,所以波特率只能达到 102400 bps。 I also check in reception the baudrate with a similar program and the baudrate is the same.我还用类似的程序检查接收波特率,波特率是相同的。

Here is the program:这是程序:

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);    
...
}

These are my serial port specifications:这些是我的串口规格:

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;

Anyone know how to fix this problem to reach 115200 bps?有谁知道如何解决这个问题以达到 115200 bps?

There are 10 bits per character - 8 bits for the data plus a start and stop bit.每个字符有 10 位 - 8 位用于数据加上一个开始和停止位。

If you calculate how long 14400 characters at 10 bits per character should take at 115200 bps then you get 1250 ms:如果您计算在 115200 bps 下每个字符 10 位的 14400 个字符应该花费多长时间,那么您将得到 1250 毫秒:

(14400 characters * 10 bits/character) / (115200 bits/second) =  1.250 seconds

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM