简体   繁体   English

Com端口队列延迟计量

[英]Com port queue latency metering

I have two programs (host and slave) communicating over a com port. 我有两个通过com端口通信的程序(主机和从机)。 In the simplest case, the host sends a command to the slave and waits for a response, then does it again. 在最简单的情况下,主机将命令发送到从属服务器,并等待响应,然后再次执行。 But this means that each side has to wait for the other for every transaction. 但这意味着双方在每笔交易中都必须等待对方。 So I use a queue so the second command can be sent before the first response comes back. 因此,我使用队列,以便可以在第一个响应返回之前发送第二个命令。 This keeps things flowing faster. 这样可以使流程运行得更快。

But I need a way of metering the use of the queue so that there are never more than N command/response pairs in route at any time. 但是我需要一种计量队列使用情况的方法,以使路由在任何时候都不会超过N个命令/响应对。 So for example if N is 3, I will wait to send the fourth command until I get the first response back, etc. And it must keep track of which response goes with which command. 因此,例如,如果N为3,则我将等待发送第四个命令,直到获得第一个响应,依此类推。它必须跟踪哪个响应与哪个命令一起进行。

One thought I had is to tag each command with an integer modulo counter which is also returned with the response. 我的一个想法是用整数模计数器标记每个命令,该计数器也随响应一起返回。 This would ensure that the command and response are always paired correctly and I can do a modulo compare to be able to meter the commands always N ahead of the responses. 这将确保命令和响应始终正确配对,并且我可以进行模比较,以便能够在响应之前始终对命令进行计数。

What I am wondering, is there a better way? 我在想,有没有更好的办法? Isn't this a somewhat common thing to do? 这不是一件常见的事吗?

(I am using Python, but that is not important.) (我正在使用Python,但这并不重要。)

Using a sequence number and modulo arithmetic is in fact quite a common way to both acknowledge messages received and tell the sender when it can send more messages - see eg http://en.wikipedia.org/wiki/Sliding_window_protocol . 实际上,使用序列号和取模算法是确认接收到的消息并告知发送方何时可以发送更多消息的一种常见方法-例如,参见http://en.wikipedia.org/wiki/Sliding_window_protocol Unfortunately for you, the obvious example, TCP, is unusual in that it uses a sequence number based on byte counts, not message counts, but the principle is much the same - TCP just has an extra degree of flexibility. 不幸的是,对于您来说,明显的示例TCP是不寻常的,因为它使用基于字节数而不是消息数的序列号,但是原理大体相同-TCP只是具有额外的灵活性。

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

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