对于通过环回流量控制的串行通信,应设置 [英] For Serial communication through loop back flow control should be set

查看:85
本文介绍了对于通过环回流量控制的串行通信,应设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过环回电缆建立串行端口通信.未收到适当的字节.我们应该设置流控制参数吗?意思是iam从一台设备向另一台设备发送60字节,但是串行端口第一次只接收28个字节并执行操作.此后它将剩余的60-28 = 32字节与其他新接收到的字节附加并执行操作.错误(通过环回电缆).当我使用虚拟com端口时,不存在此问题,它将在1枪时接收60个字节.但是我需要支持环回电缆并检查字节.

I am establishing serial port communication through loopback cable.proper bytes are not received .we should set flow control parameters? means iam sending 60 bytes from 1 device to other device.but serial port receives only 28 bytes at first time and performs operation .after tht it will append remaining 60-28=32 bytes with other newly received bytes and performs operation.but it is wrong (through loop back cable).when i use virtual com ports this problem doesn''t exist it will receive 60 bytes at 1 shot.but i need to support loop back cable and check the bytes.

推荐答案

谢谢!这样有帮助.

问题是串行端口速度很慢.与您的处理器相比非常慢.

使用虚拟端口时,数据将在一个块中流出,然后在一个块中进入.
当您使用真实端口时,数据以单个字符输出(嗯,该端口可能有一个缓冲区,但是可能是2个字节,8个字节或16个字节-不够!),更重要的是,是以单个字符收录.

收到字符后,Windows将其存储并确定将其发送到何处.然后,它将Windows消息发布到您的应用程序,说有数据".当您的应用程序最终处理消息时(取决于您的应用程序正在执行的操作以及Windows中发生的其他操作),您将从串行端口读取当前数据.这将包括到目前为止接收到的所有数据:不一定是您发送的所有数据,因为其中一半可能尚未清除发送器-可能在Windows缓冲区或硬件缓冲区中,或在这两者中.

您需要做的就是继续接收并整理数据,直到获得完整的消息为止.在实际情况下(即没有环回),流量控制会使情况变得更糟,而不是更好,因为它所能做的就是降低变送器的速度!
Thank you! That helps.

The problem is that Serial ports are slow. Very slow compared to your processor.

When you use a virtual port then data goes out in a block, and comes in in a block.
When you use a real port, data goes out in individual characters (well, the port probably has a buffer, but that could be 2 bytes, 8 bytes or 16 bytes - it won''t be enough!) and more importantly, is recived in individual characters.

When the character is received, Windows stores it and works out where to send it. It then posts a windows message to your application to say "there is data". When you app finally processes the message - which depends on what else your app is doing, as well as what else is going on in windows - you read the current data from the serial port. This will include all data received so far: not necessarily all the data you sent, because half of it may not have cleared the transmitter yet - it could be in windows buffers, or hardware buffers, or both.

What you need to do is keep on receiving, and assemble your data until you have the whole message. In a real-world situation (i.e. without the loop back) flow control will make this worse, not better, because all it can do is slow down the transmitter!


这篇关于对于通过环回流量控制的串行通信,应设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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