In addition to what Jean-Paul Calderon said (which was the correct answer), I also made the following script in python using socat.
This can be imported and instantiated into the interpreter, and then you can use the writeLine method to write data to the serial port (vritual), which connects via socat to another (virtual) serial port on which another twisted application can happen. But, as Jean-Paul Calderone said: if you just want you to want this, you really don't need to do this. Just read the documents he mentioned.
import os, subprocess, serial, time from ConfigParser import SafeConfigParser class SerialEmulator(object): def __init__(self,configfile): config=SafeConfigParser() config.readfp(open(configfile,'r')) self.inport=os.path.expanduser(config.get('virtualSerialPorts','inport')) self.outport=os.path.expanduser(config.get('virtualSerialPorts','outport')) cmd=['/usr/bin/socat','-d','-d','PTY,link=%s,raw,echo=1'%self.inport,'PTY,link=%s,raw,echo=1'%self.outport] self.proc=subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) time.sleep(3) self.serial=serial.Serial(self.inport) self.err='' self.out='' def writeLine(self,line): line=line.strip('\r\n') self.serial.write('%s\r\n'%line) def __del__(self): self.stop() def stop(self): self.proc.kill() self.out,self.err=self.proc.communicate()
source share