rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
self.expanderwindow4.set_no_show_all(True) self.expanderwindow4.hide()
self.lyricseventbox.set_no_show_all(True) self.lyricseventbox.hide()
def prefs_lyrics_toggled(self, button): if button.get_active(): self.expanderwindow4.set_no_show_all(False) self.expanderwindow4.show() self.show_lyrics = True self.update_lyrics() else: self.expanderwindow4.set_no_show_all(True) self.expanderwindow4.hide() self.show_lyrics = False
if mins == "1": mins_text = _('minute') else: mins_text = _('minutes')
mins_text = gettext.ngettext('minute', 'minutes', int(mins))
def update_statusbar(self): if self.conn and self.status and self.show_statusbar: hours = None mins = None total_time = convert_time(self.total_time) try: mins = total_time.split(":")[-2] hours = total_time.split(":")[-3] except: pass if mins: if mins.startswith('0') and len(mins) > 1: mins = mins[1:] if mins == "1": m...
if hours == "1": hours_text = _('hour and') else: hours_text = _('hours and')
hours_text = gettext.ngettext('hour and', 'hours and', int(hours))
def update_statusbar(self): if self.conn and self.status and self.show_statusbar: hours = None mins = None total_time = convert_time(self.total_time) try: mins = total_time.split(":")[-2] hours = total_time.split(":")[-3] except: pass if mins: if mins.startswith('0') and len(mins) > 1: mins = mins[1:] if mins == "1": m...
if self.status.playlistlength == "1": songs_text = _('song') else: songs_text = _('songs')
songs_text = gettext.ngettext('song', 'songs', int(self.status.playlistlength))
def update_statusbar(self): if self.conn and self.status and self.show_statusbar: hours = None mins = None total_time = convert_time(self.total_time) try: mins = total_time.split(":")[-2] hours = total_time.split(":")[-3] except: pass if mins: if mins.startswith('0') and len(mins) > 1: mins = mins[1:] if mins == "1": m...
self.repeat_now(None) self.shuffle_now(None)
def handle_change_conn(self): if not self.conn: self.ppbutton.set_property('sensitive', False) self.stopbutton.set_property('sensitive', False) self.prevbutton.set_property('sensitive', False) self.nextbutton.set_property('sensitive', False) self.volumebutton.set_property('sensitive', False) self.trayimage.set_from_sto...
timeouts = (win32con.MAXDWORD, 0, 0, 0, 1000)
timeouts = (0, 0, 0, 0, 0)
def __init__(self, port, #number of device, numbering starts at #zero. if everything fails, the user #can specify a device string, note #that this isn't portable anymore baudrate=9600, #baudrate bytesize=EIGHTBITS, #number of databits parity=PARITY_NONE, #enable parity checking stopbits=S...
def getRI(self): """read terminal status line""" if not self.hComPort: raise portNotOpenError raise NotImplementedError def getCD(self): """read terminal status line""" if not self.hComPort: raise portNotOpenError raise NotImplementedError
def getDSR(self): if not self.hComPort: raise portNotOpenError comDCB = win32file.GetCommState(self.hComPort) return comDCB.fOutxDsrFlow
self.__tcgetattr()
try: self.__tcgetattr() except termios.error, msg: raise serialutil.SerialException, "could not open port: %s" % msg
def __init__(self, port, #number of device, numbering starts at #zero. if everything fails, the user #can specify a device string, note #that this isn't portable anymore baudrate=9600, #baudrate bytesize=EIGHTBITS, #number of databits parity=PARITY_NONE, #enable parity checking stopbits=S...
EVT_BUTTON(self, self.button_ok.GetId(), self.OnOK) EVT_BUTTON(self, self.button_cancel.GetId(), self.OnCancel)
self.Bind(EVT_BUTTON, self.OnOK, id = self.button_ok.GetId()) self.Bind(EVT_BUTTON, self.OnCancel, id = self.button_cancel.GetId())
def __attach_events(self): EVT_BUTTON(self, self.button_ok.GetId(), self.OnOK) EVT_BUTTON(self, self.button_cancel.GetId(), self.OnCancel)
if not self.alive:
if not self.alive.isSet():
def __init__(self, *args, **kwds): self.serial = serial.Serial() self.serial.timeout = 0.5 #make sure that the alive flag can be checked from time to time self.settings = TerminalSetup() #placeholder for the settings self.thread = None # begin wxGlade: TerminalFrame.__init__ kwds["style"] = wxDEFAULT_FRAME_STYLE wxFr...
self.alive = True
def StartThread(self): """Start the receiver thread""" self.alive = True self.thread = threading.Thread(target=self.ComPortThread) self.thread.setDaemon(1) self.thread.start()
self.alive = False
self.alive.clear()
def StopThread(self): """Stop the receiver thread, wait util it's finished.""" if self.thread is not None: self.alive = False #set termination flag for thread self.thread.join() #wait until thread has finished self.thread = None
EVT_MENU(self, ID_CLEAR, self.OnClear) EVT_MENU(self, ID_SAVEAS, self.OnSaveAs) EVT_MENU(self, ID_EXIT, self.OnExit) EVT_MENU(self, ID_SETTINGS, self.OnPortSettings) EVT_MENU(self, ID_TERM, self.OnTermSettings) EVT_CHAR(self, self.OnKey) EVT_CHAR(self.text_ctrl_output, self.OnKey) EVT_SERIALRX(self, self.OnSerialRead) ...
self.Bind(EVT_MENU, self.OnClear, id = ID_CLEAR) self.Bind(EVT_MENU, self.OnSaveAs, id = ID_SAVEAS) self.Bind(EVT_MENU, self.OnExit, id = ID_EXIT) self.Bind(EVT_MENU, self.OnPortSettings, id = ID_SETTINGS) self.Bind(EVT_MENU, self.OnTermSettings, id = ID_TERM) self.text_ctrl_output.Bind(EVT_CHAR, self.OnKey) self.Bind(...
def __attach_events(self): #register events at the controls EVT_MENU(self, ID_CLEAR, self.OnClear) EVT_MENU(self, ID_SAVEAS, self.OnSaveAs) EVT_MENU(self, ID_EXIT, self.OnExit) EVT_MENU(self, ID_SETTINGS, self.OnPortSettings) EVT_MENU(self, ID_TERM, self.OnTermSettings) EVT_CHAR(self, self.OnKey) EVT_CHAR(self.text_ctr...
self.alive = False
self.alive.clear()
def OnPortSettings(self, event=None): """Show the portsettings dialog. The reader thread is stopped for the settings change.""" if event is not None: #will be none iwhencalled on startup self.StopThread() self.serial.close() ok = False while not ok: dialog_serial_cfg = wxSerialConfigDialog.SerialConfigDialog(...
while self.alive:
while self.alive.isSet():
def ComPortThread(self): """Thread that handles the incomming traffic. Does the basic input transformation (newlines) and generates an SerialRxEvent""" while self.alive: #loop while this flag is true text = self.serial.read(1) #read one, with timout if text: #ch...
plat[:6] == 'netbsd' or \
def device(port): return '/dev/ttyp%d' % port
TERMIOS.ECHOCTL|TERMIOS.ECHOKE|TERMIOS.ISIG|TERMIOS.IEXTEN)
TERMIOS.ISIG|TERMIOS.IEXTEN) for flag in ('ECHOCTL', 'ECHOKE'): if hasattr(TERMIOS, flag): lflag &= ~getattr(TERMIOS, flag)
def _reconfigurePort(self): """Set commuication parameters on opened port.""" if self.fd is None: raise SerialException("Can only operate on a valid port handle") vmin = vtime = 0 #timeout is done via select try: iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self.fd) except termios....
if hasattr(TERMIOS, 'TIOCMGET'): TIOCMGET = TERMIOS.TIOCMGET TIOCMBIS = TERMIOS.TIOCMBIS TIOCMBIC = TERMIOS.TIOCMBIC TIOCMSET = TERMIOS.TIOCMSET TIOCM_DTR = TERMIOS.TIOCM_DTR TIOCM_RTS = TERMIOS.TIOCM_RTS TIOCM_CTS = TERMIOS.TIOCM_CTS TIOCM_CAR = TERMIOS.TIOCM_CAR TIOCM_RNG = TERMIOS.TIOCM_RNG TIOCM_DSR = TER...
TIOCMGET = hasattr(TERMIOS, 'TIOCMGET') and TERMIOS.TIOCMGET or 0x5415 TIOCMBIS = hasattr(TERMIOS, 'TIOCMBIS') and TERMIOS.TIOCMBIS or 0x5416 TIOCMBIC = hasattr(TERMIOS, 'TIOCMBIC') and TERMIOS.TIOCMBIC or 0x5417 TIOCMSET = hasattr(TERMIOS, 'TIOCMSET') and TERMIOS.TIOCMSET or 0x5418 TIOCM_DTR = hasattr(TERMIOS, '...
def device(port): return '/dev/tty0%d' % (port+1)
import termios, TERMIOS, sys, os
import termios, sys, os
def getkey(): while 1: if echo: z = msvcrt.getche() else: z = msvcrt.getch() if z == '\0' or z == '\xe0': #functions keys msvcrt.getch() else: return z
new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO new[6][TERMIOS.VMIN] = 1 new[6][TERMIOS.VTIME] = 0 termios.tcsetattr(fd, TERMIOS.TCSANOW, new)
new[3] = new[3] & ~termios.ICANON & ~termios.ECHO new[6][termios.VMIN] = 1 new[6][termios.VTIME] = 0 termios.tcsetattr(fd, termios.TCSANOW, new)
def getkey(): while 1: if echo: z = msvcrt.getche() else: z = msvcrt.getch() if z == '\0' or z == '\xe0': #functions keys msvcrt.getch() else: return z
c = sys.stdin.read(1) if echo: sys.stdout.write(c)
c = os.read(fd, 1) if echo: sys.stdout.write(c); sys.stdout.flush()
def getkey(): #~ c = os.read(fd, 1) c = sys.stdin.read(1) if echo: sys.stdout.write(c) return c
termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old) sys.exitfunc = clenaup_console
termios.tcsetattr(fd, termios.TCSAFLUSH, old) sys.exitfunc = clenaup_console
def clenaup_console(): termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)
if c == EXITCHARCTER: break s.write(c) if convert_outgoing_cr and c == '\r': s.write('\n') if echo: sys.stdout.write('\n')
if c == EXITCHARCTER: break if convert_outgoing_cr and c == '\n': s.write('\r') s.write(c)
def writer(): """loop and copy console->serial until EOF character is found""" while 1: c = getkey() if c == EXITCHARCTER: break #exit on esc s.write(c) #send character if convert_outgoing_cr and c == '\r': s.write('\n') if echo: sys.stdout.write('\n')
print >>sys.stderr, """USAGE: %s [options]
sys.stderr.write("""USAGE: %s [options]
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow control (...
-p, --port=PORT: port, a number, defualt = 0 or a device name
-p, --port=PORT: port, a number, default = 0 or a device name
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow control (...
-c, --cr: disable CR -> CR+LF translation
-c, --cr: disable LF -> CR+LF translation
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow control (...
""" % sys.argv[0]
""" % (sys.argv[0], ))
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow control (...
raise ValueError, "Baudrate must be a integer number"
raise ValueError, "Baudrate must be a integer number, not %r" % a
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow control (...
if port < 9: self.portstr = 'COM%d' % (port+1) else: self.portstr = r'\\.\COM%d' % (port+1)
self.portstr = device(port)
def __init__(self, port, #number of device, numbering starts at #zero. if everything fails, the user #can specify a device string, note #that this isn't portable anymore baudrate=9600, #baudrate bytesize=EIGHTBITS, #number of databits parity=PARITY_NONE, #enable parity checking stopbits=S...
if not self.fd:
if self.fd is None:
def _reconfigurePort(self): """Set commuication parameters on opened port.""" if not self.fd: raise SerialException("Can only operate on a valid port handle") vmin = vtime = 0 #timeout is done via select try: iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self.fd) except termios.erro...
if self.fd:
if self.fd is not None:
def close(self): """Close port""" if self._isOpen: if self.fd: os.close(self.fd) self.fd = None self._isOpen = False
if not self.fd: raise portNotOpenError
if self.fd is None: raise portNotOpenError
def read(self, size=1): """Read size bytes from the serial port. If a timeout is set it may return less characters as requested. With no timeout it will block until the requested number of bytes is read.""" if not self.fd: raise portNotOpenError read = '' inp = None if size > 0: while len(read) < size: #print "\tread()...
if not self.fd: raise portNotOpenError
if self.fd is None: raise portNotOpenError
def write(self, data): """Output the given string over the serial port.""" if not self.fd: raise portNotOpenError t = len(data) d = data while t>0: n = os.write(self.fd, d) d = d[n:] t = t - n
if not self.fd:
if self.fd is None:
def flushInput(self): """Clear input buffer, discarding all that is in the buffer.""" if not self.fd: raise portNotOpenError termios.tcflush(self.fd, TERMIOS.TCIFLUSH)
if not self.fd:
if self.fd is None:
def flushOutput(self): """Clear output buffer, aborting the current output and discarding all that is in the buffer.""" if not self.fd: raise portNotOpenError termios.tcflush(self.fd, TERMIOS.TCOFLUSH)
if not self.fd:
if self.fd is None:
def sendBreak(self): """Send break condition.""" if not self.fd: raise portNotOpenError termios.tcsendbreak(self.fd, 0)
if not self.fd: raise portNotOpenError
if self.fd is None: raise portNotOpenError
def setRTS(self,on=1): """Set terminal status line: Request To Send""" if not self.fd: raise portNotOpenError if on: fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_RTS_str) else: fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_RTS_str)
if not self.fd: raise portNotOpenError
if self.fd is None: raise portNotOpenError
def setDTR(self,on=1): """Set terminal status line: Data Terminal Ready""" if not self.fd: raise portNotOpenError if on: fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str) else: fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_DTR_str)
if not self.fd: raise portNotOpenError
if self.fd is None: raise portNotOpenError
def getCTS(self): """Read terminal status line: Clear To Send""" if not self.fd: raise portNotOpenError s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) return struct.unpack('I',s)[0] & TIOCM_CTS != 0
if not self.fd: raise portNotOpenError
if self.fd is None: raise portNotOpenError
def getDSR(self): """Read terminal status line: Data Set Ready""" if not self.fd: raise portNotOpenError s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) return struct.unpack('I',s)[0] & TIOCM_DSR != 0
if not self.fd: raise portNotOpenError
if self.fd is None: raise portNotOpenError
def getRI(self): """Read terminal status line: Ring Indicator""" if not self.fd: raise portNotOpenError s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) return struct.unpack('I',s)[0] & TIOCM_RI != 0
if not self.fd: raise portNotOpenError
if self.fd is None: raise portNotOpenError
def getCD(self): """Read terminal status line: Carrier Detect""" if not self.fd: raise portNotOpenError s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) return struct.unpack('I',s)[0] & TIOCM_CD != 0
if not self.fd: raise portNotOpenError
if self.fd is None: raise portNotOpenError
def drainOutput(self): """internal - not portable!""" if not self.fd: raise portNotOpenError termios.tcdrain(self.fd)
if not self.fd:
if self.fd is None:
def nonblocking(self): """internal - not portable!""" if not self.fd: raise portNotOpenError fcntl.fcntl(self.fd, FCNTL.F_SETFL, FCNTL.O_NONBLOCK)
self.alive.set()
def StartThread(self): """Start the receiver thread""" self.thread = threading.Thread(target=self.ComPortThread) self.thread.setDaemon(1) self.thread.start() self.alive.set()
port = property(getPort, setPort, "Port setting")
port = property(getPort, setPort, doc="Port setting")
def getPort(self): """Get the current port setting. The value that was passed on init or using setPort() is passed back. See also the attribute portstr which contains the name of the port as a string.""" return self._port
baudrate = property(getBaudrate, setBaudrate, "Baudrate setting")
baudrate = property(getBaudrate, setBaudrate, doc="Baudrate setting")
def getBaudrate(self): """Get the current baudrate setting.""" return self._baudrate
bytesize = property(getByteSize, setByteSize, "Byte size setting")
bytesize = property(getByteSize, setByteSize, doc="Byte size setting")
def getByteSize(self): """Get the current byte size setting.""" return self._bytesize
parity = property(getParity, setParity, "Parity setting")
parity = property(getParity, setParity, doc="Parity setting")
def getParity(self): """Get the current parity setting.""" return self._parity
stopbits = property(getStopbits, setStopbits, "Stopbits setting")
stopbits = property(getStopbits, setStopbits, doc="Stopbits setting")
def getStopbits(self): """Get the current stopbits setting.""" return self._stopbits
timeout = property(getTimeout, setTimeout, "Timeout setting for read()")
timeout = property(getTimeout, setTimeout, doc="Timeout setting for read()")
def getTimeout(self): """Get the current timeout setting.""" return self._timeout
writeTimeout = property(getWriteTimeout, setWriteTimeout, "Timeout setting for write()")
writeTimeout = property(getWriteTimeout, setWriteTimeout, doc="Timeout setting for write()")
def getWriteTimeout(self): """Get the current timeout setting.""" return self._writeTimeout
xonxoff = property(getXonXoff, setXonXoff, "Xon/Xoff setting")
xonxoff = property(getXonXoff, setXonXoff, doc="Xon/Xoff setting")
def getXonXoff(self): """Get the current XonXoff setting.""" return self._xonxoff
rtscts = property(getRtsCts, setRtsCts, "RTS/CTS setting")
rtscts = property(getRtsCts, setRtsCts, doc="RTS/CTS setting")
def getRtsCts(self): """Get the current RtsCts setting.""" return self._rtscts
win32event.WaitForSingleObject(self.overlapped.hEvent, win32event.INFINITE) n = win32file.GetOverlappedResult(self.hComPort, self.overlapped, 0)
n = win32file.GetOverlappedResult(self.hComPort, self.overlapped, 1)
def read(self, size=1): "read num bytes from serial port" if not self.hComPort: raise portNotOpenError read = '' if size > 0: if self.timeout == 0: flags, comstat = win32file.ClearCommError(self.hComPort) n = comstat.cbInQue if len(read) + n >= size: n = size-len(read) rc, buf = win32file.ReadFile(self.hComPort, win32f...
if type(port) == type(''):
if type(port) in [type(''), type(u'')]:
def setPort(self, port): """Change the port. The attribute portstr is set to a string that contains the name of the port.""" was_open = self._isOpen if was_open: self.close() if port is not None: if type(port) == type(''): #strings are taken directly self.portstr = port else: self.portstr = self.makeDeviceName(p...
while len(read) < size: flags, comstat = win32file.ClearCommError( self.hComPort ) rc, buf = win32file.ReadFile(self.hComPort, size-len(read), self.overlapped) if self.timeout > 0: rc = win32event.WaitForSingleObject(self.overlapped.hEvent, self.timeout*1000) n = win32file.GetOverlappedResult(self.hComPort, self.overl...
if self.timeout == 0: flags, comstat = win32file.ClearCommError(self.hComPort) n = comstat.cbInQue if len(read) + n >= size: n = size-len(read) rc, buf = win32file.ReadFile(self.hComPort, win32file.AllocateReadBuffer(n), self.overlapped) win32event.WaitForSingleObject(self.overlapped.hEvent, win32event.INFINITE) read =...
def read(self, size=1): "read num bytes from serial port" if not self.hComPort: raise portNotOpenError #print "read %d" %size ####debug read = '' if size > 0: while len(read) < size: flags, comstat = win32file.ClearCommError( self.hComPort ) rc, buf = win32file.ReadFile(self.hComPort, size-len(read), self.ove...
read = read + str(buf[0:n]) if self.timeout == 0: break
read = read + str(buf[:n]) if getq != n: break
def read(self, size=1): "read num bytes from serial port" if not self.hComPort: raise portNotOpenError #print "read %d" %size ####debug read = '' if size > 0: while len(read) < size: flags, comstat = win32file.ClearCommError( self.hComPort ) rc, buf = win32file.ReadFile(self.hComPort, size-len(read), self.ove...
print "x", rc
def read(self, size=1): "read num bytes from serial port" if not self.hComPort: raise portNotOpenError #print "read %d" %size ####debug read = '' if size > 0: while len(read) < size: flags, comstat = win32file.ClearCommError( self.hComPort ) rc, buf = win32file.ReadFile(self.hComPort, size-len(read), self.ove...
print "n", n
def read(self, size=1): "read num bytes from serial port" if not self.hComPort: raise portNotOpenError #print "read %d" %size ####debug read = '' if size > 0: while len(read) < size: flags, comstat = win32file.ClearCommError( self.hComPort ) rc, buf = win32file.ReadFile(self.hComPort, size-len(read), self.ove...
print n<togo and n or togo
def read(self, size=1): "read num bytes from serial port" if not self.hComPort: raise portNotOpenError #print "read %d" %size ####debug read = '' if size > 0: while len(read) < size: flags, comstat = win32file.ClearCommError( self.hComPort ) rc, buf = win32file.ReadFile(self.hComPort, size-len(read), self.ove...
self.sPort.setSerialPortParams(baudrate, databits, self.jstopbits, self.jparity)
self.sPort.setSerialPortParams(baudrate, self.databits, self.jstopbits, self.jparity)
def __init__(self, port, #number of device, numbering starts at #zero. if everything fails, the user #can specify a device string, note #that this isn't portable anymore baudrate=9600, #baudrate bytesize=EIGHTBITS, #number of databits parity=PARITY_NONE, #enable parity checking stopbits=S...
self.setRTS(0) self.setDTR(0)
def close(self): """close port""" if self.hComPort: #Wait until data is transmitted, but not too long... (Timeout-Time) #while 1: # flags, comState = win32file.ClearCommError(hComPort) # if comState.cbOutQue <= 0 or calcTimeout(startTime) > timeout: # break
sys.stdout.write(s.read())
data = s.read() if repr_mode: sys.stdout.write(repr(data)[1:-1]) else: sys.stdout.write(data)
def reader(): """loop forever and copy serial->console""" while 1: sys.stdout.write(s.read()) sys.stdout.flush()
"hp:b:rxec", ["help", "port=", "baud=", "rtscts", "xonxoff", "echo", "cr"]
"hp:b:rxecD", ["help", "port=", "baud=", "rtscts", "xonxoff", "echo", "cr", "debug"]
def usage(): sys.stderr.write("""USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: port, a number, default = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow control (def...
comDCB = win32file.GetCommState(self.hComPort)
def setRTS(self,level=1): """set terminal status line""" if not self.hComPort: raise portNotOpenError comDCB = win32file.GetCommState(self.hComPort) if level: comDCB.fRtsControl = win32file.RTS_CONTROL_ENABLE; else: comDCB.fRtsControl = win32file.RTS_CONTROL_DISABLE; win32file.SetCommState(self.hComPort, comDCB)
comDCB.fRtsControl = win32file.RTS_CONTROL_ENABLE; else: comDCB.fRtsControl = win32file.RTS_CONTROL_DISABLE; win32file.SetCommState(self.hComPort, comDCB)
win32file.EscapeCommFunction(self.hComPort, win32file.SETRTS) else: win32file.EscapeCommFunction(self.hComPort, win32file.CLRRTS)
def setRTS(self,level=1): """set terminal status line""" if not self.hComPort: raise portNotOpenError comDCB = win32file.GetCommState(self.hComPort) if level: comDCB.fRtsControl = win32file.RTS_CONTROL_ENABLE; else: comDCB.fRtsControl = win32file.RTS_CONTROL_DISABLE; win32file.SetCommState(self.hComPort, comDCB)
comDCB = win32file.GetCommState(self.hComPort)
def setDTR(self,level=1): """set terminal status line""" if not self.hComPort: raise portNotOpenError comDCB = win32file.GetCommState(self.hComPort) if level: comDCB.fDtrControl = win32file.DTR_CONTROL_ENABLE; else: comDCB.fDtrControl = win32file.DTR_CONTROL_DISABLE; win32file.SetCommState(self.hComPort, comDCB)
comDCB.fDtrControl = win32file.DTR_CONTROL_ENABLE; else: comDCB.fDtrControl = win32file.DTR_CONTROL_DISABLE; win32file.SetCommState(self.hComPort, comDCB)
win32file.EscapeCommFunction(self.hComPort, win32file.SETDTR) else: win32file.EscapeCommFunction(self.hComPort, win32file.CLRDTR)
def setDTR(self,level=1): """set terminal status line""" if not self.hComPort: raise portNotOpenError comDCB = win32file.GetCommState(self.hComPort) if level: comDCB.fDtrControl = win32file.DTR_CONTROL_ENABLE; else: comDCB.fDtrControl = win32file.DTR_CONTROL_DISABLE; win32file.SetCommState(self.hComPort, comDCB)
def reader(): """loop forever and copy serial->console""" global connection while 1: try: if connection: connection.sendall(s.read(s.inWaiting())) else: time.sleep(0.2) except socket.error, msg: print msg if connection: connection.close() connection = None except: pass
Note: no security measures are implemeted. Anyone can remotely connect to this service over the network. Only one connection at once is supported. If the connection is terminaed it waits for the next connect. """
def reader(): """loop forever and copy serial->console""" global connection while 1: try: if connection: connection.sendall(s.read(s.inWaiting())) else: time.sleep(0.2) #lower CPU usage... except socket.error, msg: print msg if connection: connection.close() connection = None except: pass
def writer(): """loop forever and copy console->serial""" global connection try: while 1: s.write(connection.recv(1024)) except socket.error, msg: print msg
import sys, os, serial, threading, getopt, socket
def writer(): """loop forever and copy console->serial""" global connection try: while 1: s.write(connection.recv(1024)) except socket.error, msg: print msg
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port.
class Redirector: def __init__(self, serial, socket): self.serial = serial self.socket = socket
def writer(): """loop forever and copy console->serial""" global connection try: while 1: s.write(connection.recv(1024)) except socket.error, msg: print msg
options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow control (default off) -P, --localport: TCP/IP port on which to run the server (default 7777) """ % sys.ar...
def shortcut(self): """connect the serial port to the tcp port by copying everything from one side to the other""" self.alive = True self.thread_read = threading.Thread(target=self.reader) self.thread_read.setDaemon(1) self.thread_read.start() self.writer() def reader(self): """loop forever and copy serial->socket""" ...
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
connection = None
ser = serial.Serial()
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
"hp:b:rxec", ["help", "port=", "baud=", "rtscts", "xonxoff", "echo", "cr"])
"hp:b:rxP", ["help", "port=", "baud=", "rtscts", "xonxoff", "localport"])
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
usage()
print >>sys.stderr, __doc__
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
port = 0 baudrate = 9600 rtscts = 0 xonxoff = 0
ser.port = 0 ser.baudrate = 9600 ser.rtscts = False ser.xonxoff = False ser.timeout = 1
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
port = int(a)
ser.port = int(a)
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
port = a
ser.port = a
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
baudrate = int(a)
ser.baudrate = int(a)
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
rtscts = 1
ser.rtscts = True
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
xonxoff = 1
ser.xonxoff = True
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
raise ValueError, "local port must be an integer number"
raise ValueError, "Local port must be an integer number"
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
r = threading.Thread(target=reader) r.setDaemon(1) r.start()
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
s = serial.Serial(port, baudrate, rtscts=rtscts, xonxoff=xonxoff) except: print "could not open port"
ser.open() except serial.SerialException, e: print "Could not open serial port %s: %s" % (ser.portstr, e)
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
writer()
r = Redirector(ser, connection) r.shortcut() print 'Disconnected' connection.close()
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
if connection: connection.close() connection = None
def usage(): print >>sys.stderr, """USAGE: %s [options] Simple Terminal Programm for the serial port. options: -p, --port=PORT: serial port, a number, defualt = 0 or a device name -b, --baud=BAUD: baudrate, default 9600 -r, --rtscts: enable RTS/CTS flow control (default off) -x, --xonxoff: enable software flow co...
sizer_flow.Add(10, 10, 1, wxEXPAND, 0)
def __do_layout(self): # begin wxGlade: SerialConfigDialog.__do_layout # end wxGlade sizer_2 = wxBoxSizer(wxVERTICAL) sizer_3 = wxBoxSizer(wxHORIZONTAL) sizer_basics = wxStaticBoxSizer(wxStaticBox(self, -1, "Basics"), wxVERTICAL) sizer_5 = wxBoxSizer(wxHORIZONTAL) sizer_5.Add(self.label_2, 1, wxALL|wxALIGN_CENTER_VERTI...
timeouts = (timeout*1000, 0, timeout*1000, 0, 0)
timeouts = (0, 0, timeout*1000, 0, timeout*1000)
def __init__(self, port, #number of device, numbering starts at #zero. if everything fails, the user #can specify a device string, note #that this isn't portable anymore baudrate=9600, #baudrate bytesize=EIGHTBITS, #number of databits parity=PARITY_NONE, #enable parity checking stopbits=S...
comDCB.fRtsControl = win32file.RTS_CONTROL_ENABLE comDCB.fDtrControl = win32file.DTR_CONTROL_ENABLE
comDCB.fRtsControl = self._rtsState comDCB.fDtrControl = self._dtrState
def _reconfigurePort(self): """Set commuication parameters on opened port.""" if not self.hComPort: raise SerialException("Can only operate on a valid port handle") #Set Windows timeout values #timeouts is a tuple with the following items: #(ReadIntervalTimeout,ReadTotalTimeoutMultiplier, # ReadTotalTimeoutConstant,Wr...
timeouts = (win32con.MAXDWORD, 0, 0, 0, 1000)
timeouts = (win32con.MAXDWORD, 0, 0, 0, 0)
def __init__(self, port, #number of device, numbering starts at #zero. if everything fails, the user #can specify a device string, note #that this isn't portable anymore baudrate=9600, #baudrate bytesize=EIGHTBITS, #number of databits parity=PARITY_NONE, #enable parity checking stopbits=S...
n = comstat.cbInQue if len(read) + n >= size: n = size-len(read) rc, buf = win32file.ReadFile(self.hComPort, win32file.AllocateReadBuffer(n), self.overlapped) win32event.WaitForSingleObject(self.overlapped.hEvent, win32event.INFINITE) read = read + str(buf)
n = min(comstat.cbInQue, size) if n > 0: rc, buf = win32file.ReadFile(self.hComPort, win32file.AllocateReadBuffer(n), self.overlapped) win32event.WaitForSingleObject(self.overlapped.hEvent, win32event.INFINITE) read = str(buf)
def read(self, size=1): "read num bytes from serial port" if not self.hComPort: raise portNotOpenError read = '' if size > 0: if self.timeout == 0: flags, comstat = win32file.ClearCommError(self.hComPort) n = comstat.cbInQue if len(read) + n >= size: n = size-len(read) rc, buf = win32file.ReadFile(self.hComPort, win32f...
while len(read) < size: flags, comstat = win32file.ClearCommError( self.hComPort ) getq = size-len(read) rc, buf = win32file.ReadFile(self.hComPort, win32file.AllocateReadBuffer(getq), self.overlapped) n = win32file.GetOverlappedResult(self.hComPort, self.overlapped, 1) read = read + str(buf[:n]) if getq != n: break
flags, comstat = win32file.ClearCommError(self.hComPort) getq = size-len(read) rc, buf = win32file.ReadFile(self.hComPort, win32file.AllocateReadBuffer(getq), self.overlapped) n = win32file.GetOverlappedResult(self.hComPort, self.overlapped, 1) read = str(buf[:n])
def read(self, size=1): "read num bytes from serial port" if not self.hComPort: raise portNotOpenError read = '' if size > 0: if self.timeout == 0: flags, comstat = win32file.ClearCommError(self.hComPort) n = comstat.cbInQue if len(read) + n >= size: n = size-len(read) rc, buf = win32file.ReadFile(self.hComPort, win32f...
comDCB = win32file.GetCommState(self.hComPort) return comDCB.fOutxCtsFlow
return MS_CTS_ON & win32file.GetCommModemStatus(self.hComPort) != 0
def getCTS(self): """read terminal status line""" if not self.hComPort: raise portNotOpenError comDCB = win32file.GetCommState(self.hComPort) return comDCB.fOutxCtsFlow
comDCB = win32file.GetCommState(self.hComPort) return comDCB.fOutxDsrFlow
return MS_DSR_ON & win32file.GetCommModemStatus(self.hComPort) != 0
def getDSR(self): """read terminal status line""" if not self.hComPort: raise portNotOpenError comDCB = win32file.GetCommState(self.hComPort) return comDCB.fOutxDsrFlow
raise NotImplementedError
return MS_RING_ON & win32file.GetCommModemStatus(self.hComPort) != 0
def getRI(self): """read terminal status line""" if not self.hComPort: raise portNotOpenError raise NotImplementedError
raise NotImplementedError
return MS_RLSD_ON & win32file.GetCommModemStatus(self.hComPort) != 0
def getCD(self): """read terminal status line""" if not self.hComPort: raise portNotOpenError raise NotImplementedError
["help", "port=", "baud=", "rtscts", "xonxoff", "localport"])
["help", "port=", "baud=", "rtscts", "xonxoff", "localport="])
def stop(self): """Stop copying""" if self.alive: self.alive = False self.thread_read.join()
return '/dev/com%d' % port
return '/dev/com%d' % (port + 1)
def device(port): return '/dev/com%d' % port
s = fcntl.ioctl(self.fd, TERMIOS.FIONREAD, TIOCM_zero_str)
s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
def inWaiting(self): """how many character are in the input queue""" s = fcntl.ioctl(self.fd, TERMIOS.FIONREAD, TIOCM_zero_str) return struct.unpack('I',s)[0]