<bdo id='q3CJ8'></bdo><ul id='q3CJ8'></ul>
    <legend id='q3CJ8'><style id='q3CJ8'><dir id='q3CJ8'><q id='q3CJ8'></q></dir></style></legend>

  1. <small id='q3CJ8'></small><noframes id='q3CJ8'>

  2. <tfoot id='q3CJ8'></tfoot>
  3. <i id='q3CJ8'><tr id='q3CJ8'><dt id='q3CJ8'><q id='q3CJ8'><span id='q3CJ8'><b id='q3CJ8'><form id='q3CJ8'><ins id='q3CJ8'></ins><ul id='q3CJ8'></ul><sub id='q3CJ8'></sub></form><legend id='q3CJ8'></legend><bdo id='q3CJ8'><pre id='q3CJ8'><center id='q3CJ8'></center></pre></bdo></b><th id='q3CJ8'></th></span></q></dt></tr></i><div id='q3CJ8'><tfoot id='q3CJ8'></tfoot><dl id='q3CJ8'><fieldset id='q3CJ8'></fieldset></dl></div>

      如何使用python制作串口嗅探器嗅探物理端口

      How to make a serial port sniffer sniffing physical port using a python(如何使用python制作串口嗅探器嗅探物理端口)

          <tbody id='RDV5U'></tbody>

            <bdo id='RDV5U'></bdo><ul id='RDV5U'></ul>

            <small id='RDV5U'></small><noframes id='RDV5U'>

          • <tfoot id='RDV5U'></tfoot>

            • <i id='RDV5U'><tr id='RDV5U'><dt id='RDV5U'><q id='RDV5U'><span id='RDV5U'><b id='RDV5U'><form id='RDV5U'><ins id='RDV5U'></ins><ul id='RDV5U'></ul><sub id='RDV5U'></sub></form><legend id='RDV5U'></legend><bdo id='RDV5U'><pre id='RDV5U'><center id='RDV5U'></center></pre></bdo></b><th id='RDV5U'></th></span></q></dt></tr></i><div id='RDV5U'><tfoot id='RDV5U'></tfoot><dl id='RDV5U'><fieldset id='RDV5U'></fieldset></dl></div>
              <legend id='RDV5U'><style id='RDV5U'><dir id='RDV5U'><q id='RDV5U'></q></dir></style></legend>

              1. 本文介绍了如何使用python制作串口嗅探器嗅探物理端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个 PC 软件(操作系统:Win 64 位),它通过物理串行端口 RS232 与机器通信,我想使用 python 为该端口制作一个嗅探器.请注意,我是串口的初学者.

                I have a PC Software (OS: Win 64bit) that communicates with a machine via physical serial port RS232 and I want to make a sniffer for that port using a python. Please note that I am beginner to serial ports.

                我已经阅读了多个在线发布的文档和问题,但其中大多数要求只使用 3rd-party 软件,但我不能这样做,因为必须将原始字节解码为字符串消息(我有自己的解码方式/encode 方法).

                I've read multiple documents and questions posted online but most of them asks to just use 3rd-party software, but I cannot do this way because raw bytes have to be decoded into string message (I have my way own of decode/encode method).

                目前我有这样的设置:

                ///////////////////       Physical COM1        /////////////
                // (PC) Software // <------------------------> // Machine //
                ///////////////////                            /////////////
                

                我希望 python 输出通过 COM1 的任何字节.

                And I want a python to output any bytes that went through COM1.

                Desired Behavior 图(虚拟串口有一个问号,因为我不确定这是否正确):

                Desired Behavior diagram (Virtual serial port has a question mark because I'm not sure if that is the right approach):

                ///////////////////       Physical COM1        /////////////
                // (PC) Software // <------------------------> // Machine //
                ///////////////////            | Virtual       /////////////
                                               | serial port?
                                               v
                                        //////////////////
                                        // (PC) Sniffer // (Python)
                                        //////////////////
                                               | 
                                               v
                                         (output bytes)
                

                那些知道 Advanced Serial Port Monitor 的人,它的spymode"功能正是我想要使用 python 实现的.

                Those of who knows Advanced Serial Port Monitor, its "spymode" functionality is exactly what I am trying to achieve using python.

                我尝试使用 com0com 和 PortMon,但我找不到配置 com0com 以嗅探物理端口的方法(据我观察,com0com 仅生成虚拟端口)并且 PortMon 不支持 Windows 64 位.

                I've tried to use com0com and PortMon but I can't find a way to configure com0com to sniff physical port (as far as my observation goes, com0com only makes virtual ports) and PortMon does not support Windows 64-bit.

                我已经被困了好几天了...感谢任何评论/链接/答案.谢谢,

                I've been stuck at this for days... any comments/links/answers are appreciated. Thank you,

                推荐答案

                你应该通过pySerial

                一次只能获取一个函数.

                对于单向通信(从机器到 PC 软件),我能想到的从串行端口嗅探的唯一方法是从端口 1 读取并写入端口 2,您的机器正在写入端口 1 和 PC 软件已修改为从端口 2 读取.

                For one-way communication(from machine to PC software), the only way I can think of to sniff from a serial port is to read from a port1 and write to port2, where your machine is writing to port1 and PC software has been modified to read from port2.

                import serial
                
                baud_rate = 4800 #whatever baudrate you are listening to
                com_port1 = '/dev/tty1' #replace with your first com port path
                com_port2 = '/dev/tty2' #replace with your second com port path
                
                listener = serial.Serial(com_port1, baudrate)
                forwarder = serial.Serial(com_port2, baudrate)
                
                while 1:
                    serial_out = listener.read(size=1)
                    print serial_out #or write it to a file 
                    forwarder.write(serial_out)
                

                要实现全双工(异步双向通信),您需要有两个进程,每个方向一个.您需要以某种方式同步这些进程.一种方法是,一个进程从端口 1 读取,另一个进程写入端口 2,反之亦然.阅读这个问题

                To achieve full duplex(asynchronous two way communication), you need to have a two processes, one for each direction. You will need to synchronize these process in some way. One way to do it could be, while one process reads from port1, the other writes to port2, and vice-versa. Read this question

                这篇关于如何使用python制作串口嗅探器嗅探物理端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                  <bdo id='z0gU6'></bdo><ul id='z0gU6'></ul>

                  <small id='z0gU6'></small><noframes id='z0gU6'>

                  <tfoot id='z0gU6'></tfoot>

                  1. <legend id='z0gU6'><style id='z0gU6'><dir id='z0gU6'><q id='z0gU6'></q></dir></style></legend>
                      <tbody id='z0gU6'></tbody>
                        <i id='z0gU6'><tr id='z0gU6'><dt id='z0gU6'><q id='z0gU6'><span id='z0gU6'><b id='z0gU6'><form id='z0gU6'><ins id='z0gU6'></ins><ul id='z0gU6'></ul><sub id='z0gU6'></sub></form><legend id='z0gU6'></legend><bdo id='z0gU6'><pre id='z0gU6'><center id='z0gU6'></center></pre></bdo></b><th id='z0gU6'></th></span></q></dt></tr></i><div id='z0gU6'><tfoot id='z0gU6'></tfoot><dl id='z0gU6'><fieldset id='z0gU6'></fieldset></dl></div>