How to make a serial port sniffer sniffing physical port using a python -
i have pc software (os: win 64bit) communicates machine via physical serial port rs232 , want make sniffer port using python. please note beginner serial ports.
i've read multiple documents , questions posted online of them asks use 3rd-party software, cannot way because raw bytes have decoded string message (i have way own of decode/encode method).
currently have setup this:
/////////////////// physical com1 ///////////// // (pc) software // <------------------------> // machine // /////////////////// ///////////// and want python output bytes went through com1.
desired behavior diagram (virtual serial port has question mark because i'm not sure if right approach):
/////////////////// physical com1 ///////////// // (pc) software // <------------------------> // machine // /////////////////// | virtual ///////////// | serial port? v ////////////////// // (pc) sniffer // (python) ////////////////// | v (output bytes) those of knows advanced serial port monitor, "spymode" functionality trying achieve using python.
i've tried use com0com , portmon can't find way configure com0com sniff physical port (as far observation goes, com0com makes virtual ports) , portmon not support windows 64-bit.
i've been stuck @ days... comments/links/answers appreciated. thank you,
you should go through pyserial
only 1 function can acquire serial port @ time.
for one-way communication(from machine pc software), way can think of sniff serial port read port1 , write port2, machine writing port1 , pc software has been modified read port2.
import serial baud_rate = 4800 #whatever baudrate listening com_port1 = '/dev/tty1' #replace com port path com_port1 = '/dev/tty2' 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 file forwarder.write(serial_out) to achieve full duplex(asynchronous 2 way communication), you need have 2 processes, 1 each direction. need synchronize these process in way. 1 way be, while 1 process reads port1, other writes port2, , vice-versa. read question
Comments
Post a Comment