与外部设备进行软件和串行通信时的波特率限制 [英] Baud rate limits in software and serial communication with an external device

查看:203
本文介绍了与外部设备进行软件和串行通信时的波特率限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用USB端口端口作为虚拟COM端口,以实现使用MATLAB或Visual Basic 6与外部设备的串行通信.我面临的波特率限制取决于我与该设备进行通信所使用的软件. MATLAB(2018a)没问题,因为它可以设置高波特率.另一方面,Visual Basic 6面临可以在软件中设置的波特率的限制.在解决方案方面,我已经研究过在Visual Basic 6中设置更高的波特率: https://www.mev.co.uk/pages/Support/VB-Baud.html

I am using a USB port port operating as a virtual COM port to achieve serial communication with an external device using MATLAB or Visual Basic 6. I am facing baud rate limitations depending on the software I use to communicate with the device. MATLAB (2018a) has no problems because it can set high baud rates. Visual Basic 6 on the other hand faces limitations on the baud rates that can be set in the software. In terms of solutions, I have looked into this to set a higher baud rate in Visual Basic 6: https://www.mev.co.uk/pages/Support/VB-Baud.html

虚拟COM端口的驱动程序由FTDI制作,可以在以下位置找到: http: //www.ftdichip.com/Drivers/VCP.htm .在设备管理器中进行配置后,我正在与之通信的设备在设备管理器中的端口(COM&LPT)"下显示为"USB串行端口(COM4)".

The drivers for the virtual COM port are made by FTDI and can be found here: http://www.ftdichip.com/Drivers/VCP.htm . After configuration in the Device Manger, the device I am communicating with appears under 'Ports (COM & LPT)' as 'USB Serial Port (COM4)' in the Device Manager.

该设备需要1000000的波特率和2个停止位才能成功通信(如果需要更多信息,请告知我).据我所知,通过串行端口进行通信的软件中设置的波特率必须为1000000,才能与我使用的外部设备相匹配.我认为我的问题可能需要对USB端口充当虚拟COM端口时串行通信的工作方式进行一些解释,因为我担心,如果可能的话,它与使用真实"串行端口的通信有所不同. FTDI驱动程序似乎非常灵活,因此我不明白为什么Visual Basic无法利用这种灵活性.在Visual Basic 6中不可能将波特率设置为1000000吗?如果不可能,是否有任何方法可以克服此限制?

The device requires a baud rate of 1000000 and 2 stop bits for successful communication (if you need any more information, please let me know). As far as I am aware, the baud rate set in the software to communicate via the serial port has to be 1000000 to match that of the external device I am using. I think my problem might require a bit an explanation of how serial communication works when a USB port is acting as a virtual COM port because I worry that it differs from communication using a 'real' serial port, if possible. The FTDI driver appears to be very flexible so I do not understand why Visual Basic cannot tap into this flexibility. Is it impossible to set a baud rate of 1000000 in Visual Basic 6? If it is impossible, are there any methods to overcome this limitation?

以下是波特率设置的VB6代码,其中端口"是COM端口的地址,例如COM4,COM3:

The VB6 code for baud rate setting is found below, where 'Port' is the address of COM port e.g. COM4, COM3:

MainForm.MSComm1.CommPort = Port
MainForm.MSComm1.Settings = "9600,N,8,1"

如果有人能帮助我了解在这种情况下串行通信的工作原理,并且能克服Visual Basic 6的限制,我将不胜感激.

If anyone can help me understand how serial communication works in this setting and if I can overcome the constraints of Visual Basic 6, I would be very grateful.

推荐答案

似乎您正在使用MSComm32.ocx,而不是直接使用VB6.
您可以为此设置的最大速度为256,000 bps.

It seems that you are using MSComm32.ocx, not VB6 directly.
The maximum speed you can set for this is 256,000 bps.

如何使用Mscomm32.ocx发送​​到串行端口

以下波特率值有效:110、300、600、1200、2400、4800、9600(默认),14400、19200、28800、38400、56000、57600、115200、128000、256000.

The following baud rate values are valid: 110, 300, 600, 1200, 2400, 4800, 9600 (default), 14400, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 256000.

如果要提高速度,请直接将Win32 API与以下库等配合使用.

If you want more speed, please use Win32 API directly with the following library etc.

通过Win32 API进行串行端口VB6编程

串行端口通信

使用Windows API在Visual Basic上进行串行端口编程

grricks/vb6SerialAPI

或者,如果FTDI提供的库是由上述函数的Declare Function定义的,是否可以使用?

Or, can it be used if the library provided by FTDI is defined by Declare Function like the above library?

D2XX程序员指南

6.9 FT_W32_SetCommState
示例

6.9 FT_W32_SetCommState
Example

FT_HANDLE ftHandle; // setup by FT_W32_CreateFile 
FTDCB ftDCB; 

if (FT_W32_GetCommState(ftHandle,&ftDCB)) {
    // FT_W32_GetCommState ok, device state is in ftDCB
    ftDCB.BaudRate = 921600; // Change the baud rate
    if (FT_W32_SetCommState(ftHandle,&ftDCB))
        ; // FT_W32_SetCommState ok 
    else
        ; // FT_W32_SetCommState failed
}
else
    ; // FT_W32_GetCommState failed

这篇关于与外部设备进行软件和串行通信时的波特率限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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