Last active
January 4, 2017 14:37
-
-
Save marcolivierarsenault/1bfcd329d6f107ae852c8063fbb41e37 to your computer and use it in GitHub Desktop.
Protocol sniffer between two serial port. Dump the output to a file and in the consol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Protocol sniffer between two serial port. Dump the output to a file and in the consol | |
@Author Marc-Olivier Arsenault | |
@Date Jan 3rd 2017 | |
''' | |
import serial | |
import sys | |
port1 = "/dev/ttyS1" | |
port2 = "/dev/ttyS3" | |
baud = 9600 | |
current = 0 | |
fileName = "out.txt" | |
target = open(fileName, 'r+') | |
ser1 = serial.Serial(port1, baud, timeout=1) | |
if ser1.isOpen(): | |
print(ser1.name + ' is open...') | |
ser2 = serial.Serial(port2, baud, timeout=1) | |
if ser2.isOpen(): | |
print(ser2.name + ' is open...') | |
while True: | |
if ser1.inWaiting() > 0: | |
if current!=1: | |
print("") | |
print("=================SER1====================") | |
target.write("\n") | |
target.write("=================SER1====================") | |
current = 1 | |
a = ser1.read() | |
sys.stdout.write(hex(ord(a))) | |
sys.stdout.write(' ') | |
target.write(hex(ord(a))) | |
target.write(' ') | |
ser2.write(a) | |
if ser2.inWaiting() > 0: | |
if current!=2: | |
print("") | |
print("=================SER2====================") | |
target.write("\n") | |
target.write("=================SER2====================") | |
current = 2 | |
a = ser2.read() | |
sys.stdout.write(hex(ord(a))) | |
sys.stdout.write(' ') | |
target.write(hex(ord(a))) | |
target.write(' ') | |
ser1.write(a) | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment