波特率串行端口的窗户 [英] baudrate serial windows port

查看:120
本文介绍了波特率串行端口的窗户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要探测的窗口串口我写了这个程序。我设置串口波特率为115200。当我运行这个程序的运行时间为1250毫秒,这样一来,波特率只有reachs 102400个基点。我还检查接收波特率有类似的计划和波特率是相同的。

To probe the windows serial port I have written this program. I set the serial port baudrate to 115200 bps. When I run this program the elapsed time is 1250 ms, so that, the baudrate only reachs 102400 bps. I also check in reception the baudrate with a similar program and the baudrate is the same.

下面是程序:

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;

任何人知道如何解决这个问题,达到115200?

Anyone know how to fix this problem to reach 115200 bps?

推荐答案

有每个字符10位 - 为8位数据加上一个起始位和停止位

There are 10 bits per character - 8 bits for the data plus a start and stop bit.

如果你计算出多久,每字10位字符14400应在115200那么你得到1250毫秒:

If you calculate how long 14400 characters at 10 bits per character should take at 115200 bps then you get 1250 ms:

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

这篇关于波特率串行端口的窗户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆