简体   繁体   中英

Sniffing data of serial port without removing data from buffer

I am using the bgapi library to manage bluetooth communication using a USB dongle. The library will take a command from my program and will handle all serial communications through the COM port in its own thread. I want to echo back all data coming out of the COM port, but the library only gives me access to what it chooses to parse out itself.

I could go into the bgapi library and change the functionality of the code, setting up a variable or function to return what data is currently being read, but other people are also working on this project and changing the library could cause larger problems or invalidate updates.

Is there any way for me to access the data coming into the COM port without interfering with the library, like sniffing the data going through the COM port without taking it out of the buffer for the library? The library holds the port open for itself and discards the extra data that I want to see.

I'm not sure I understood completely how your library works so I'm not sure this will work for you but you can give it a try anyway.

What you can do (on Windows) is use Termite as a man-in-the-middle with port forwarding.

Since you probably want to keep everything inside one computer you can use com0com to create a couple of virtual ports.

To activate port forwarding on Termite you have to go to settings and then forward on the bottom-left side of the screen. You'll see a menu where you can choose the port you want to forward to. On the following screenshot I can forward from COM1 to COM2:

在此处输入图片说明

After selecting the right settings for COM1 you accept and connect by clicking on the big button marked COM1 57000 bps... and you'll see everything incoming on COM1 forwarded to COM2 and displayed on the console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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