def __init__(self, port, baudrate, wait_ready = True, timeout = True): # si le port n'est pas utilisé if port not in ARDUINO_PORTS: raise InvalidPort(port) # si le baudrate n'existe pas if baudrate not in Serial.BAUDRATES: raise InvalidBaudRate(baudrate) # on appel le constructeur parent Serial.__init__(self, port, baudrate, timeout = timeout) # connection start : temps de début de connexion self.connection_start = time() # on dort un petit moment if not isinstance(wait_ready, bool): time.sleep(wait_ready) # temps qu'on n'a pas de réponse on attend elif True: while not self.read(): continue # temps nécéssaire pour obtenir la première connexion self.connection_first_answer = time() - self.connection_start print(self.connection_first_answer)
def connect_to_balance(self,args,kwargs): # input: args, kwargs # output: nothing! # desc: attempts to connect and configure the balance over a serial connection. This handles all errors relating # to the balance and raises its concerns to the wner of the Balance object # notes: the "jet fuel can't melt steel beams" identifier was Cameron's idea ports_list = list(serial.tools.list_ports.comports()) com_port = 'None' for i in ports_list: if 'USB CDC serial port emulation' in i[1]: com_port = i[0] break if com_port == 'None': raise BalanceException('Balance not found') else: kwargs['port'] = com_port kwargs['baudrate'] = 9600 kwargs['timeout'] = 1 try: Serial.__init__(self, *args, **kwargs) except Exception as e: ID = "jet fuel can't melt steel beams" else: self.write([27,120,49,95]) ID = self.readline() if (ID != 'Mod. PRACTUM2101-1S\r\n' and ID != "jet fuel can't melt steel beams"): raise BalanceException('Balance is not powered on')
def __init__(self,quitEvent,rasterToPrinterQueue): ''' Constructor ''' baudrate = 19200 self.BYTE_TIME =(12.0) / float(baudrate) self.LINE_TIME=self.BYTE_TIME*10 self.resumeTime = 0.0 self.dotPrintTime = 0.80#vigtigt self.dotFeedTime = 0.060 args = [ "/dev/ttyAMA0", baudrate ] print "initing printer" Serial.__init__(self, "/dev/ttyAMA0", baudrate) time.sleep(1) self.reset() print "setting queues" self.rasterToPrinterQueue=rasterToPrinterQueue self.quitEvent=quitEvent print "making print consumer thread" self.consumerThread=threading.Thread(target=self.consumer) self.consumerThread.daemon=True print "starting print consumer thread" self.consumerThread.start() print "printer made thread"
def __init__(self, port, baud): Serial.__init__(self) EventDispatcher.__init__(self) self.port = port self.baudrate = baud self.listeners = {} self.waiting = True self.detected = False self.readyMsg = "" self.repeatsWaiting = False self.messageEnd = b"" self.inUse = False self.notFound = False self.connectionError = False self.lastSpeed = 1000 self.statusRequest = False self.busy = False self._stopping = False self.connecting = True try: self.open() except SerialException as se: if os.name == "nt": if str(se).find('FileNotFoundError') >= 0: self.notFound = True self.dispatch('connection-error') elif str(se).find('PermissionError') >= 0: self.inUse = True self.connectionError = True self.dispatch('connection-error') return detectThread = Thread(target=self.detectSetup) detectThread.start()
def __init__(self, gui=None): if Printer.__single: raise RuntimeError('A Printer already exists') Printer.__single = self if gui: self.gui = gui else: self.gui = dddumbui.DumbGui() Serial.__init__(self) self.usbId = None # Command sequence number [1..255] self.lineNr = 1 # The last (max. 256) commands sent, for command re-send self.lastCommands = {} # Retry counter on rx and tx errors self.rxErrors = 0 self.txErrors = 0 self.startTime = None self.curDirBits = 0
def __init__(self, *arguments, **keywords): # init the serial interface Serial.__init__(self, *arguments, **keywords) # init the cache self.ttl = 0 self.cache = {}
def __init__(self): Serial.__init__(self) self.usbId = None self.mode = None self.endTokens = None self.lastSend = 0 self.gcodeData = [] self.gcodePos = 0 # Retry counter on rx errors self.rxErrors = 0 # Timespan where we monitor the serial line after the # print has finished. self.postMonitor = 0 self.printing = False self.startTime = None self.wantReply = None self.wantAck = None # Part of a response read from printer self.recvPart = ""
def __init__(self, *args, **kwargs): #ensure that a reasonable timeout is set timeout = kwargs.get('timeout',0.1) if timeout < 0.01: timeout = 0.1 kwargs['timeout'] = timeout Serial.__init__(self, *args, **kwargs) self.buf = ''
def __init__(self,port='/dev/ttyUSB0',baudrate= 115200): Serial.__init__(self,port,baudrate) self.__outBuffer=list() self.__destAdress=[0,0,0,0,0,0,0,0] self.__readyToSend = False self.__inpFrame = {'Payload':list()} self.__availableFrame = False self.flush()
def __init__(self, *args, **kwargs): #ensure that a reasonable timeout is set timeout = kwargs.get('timeout',0.1) if timeout < 0.01: timeout = 0.01 kwargs['timeout'] = 0.01 Serial.__init__(self, *args, **kwargs) self.buf = '' self.lastMillis = 0 self.messaggehandlers = {} self.isClosing= False;
def __init__(self, port = None, baudrate = 0, timeout = 0.2, ): ''' Initialize the underlying serial port and provide the wrapper ''' Serial.__init__(self, port = port, baudrate = baudrate, timeout = timeout) self._sio = io.TextIOWrapper(io.BufferedRWPair(self, self), newline='\r', line_buffering=True, encoding = 'ISO-8859-1') self._sio_lock = threading.Lock() return
def __init__(self, port="/dev/ttyUSB0", baudrate=115200, p=3, debug=False, dbglevel=100): Serial.__init__(self, port, baudrate) self.pin = p self.debug = debug self.dbglevel = dbglevel
def __init__(self, address): print "Establishing a serial connection with " + address Serial.__init__(self, address, timeout=0.1) self.mode = "INIT" print "Attempting a startup handshake with " + address self.put("K>S") self.readlines() self.put("K>R") self.expect("K<R") self.mode = "EXPECTED"
def __init__(self, *args, **kwargs): #ensure that a reasonable timeout is set timeout = kwargs.get('timeout',0.1) if timeout < 0.01: timeout = 0.1 kwargs['timeout'] = timeout Serial.__init__(self, *args, **kwargs) self.buffer_lock = Lock() self.buf = '' self.pyserial_version = self.get_pyserial_version() self.is_pyserial_v3 = self.pyserial_version >= 3.0
def __init__(self, port, *args, **kwargs): Serial.__init__(self, port, timeout=1.5, baudrate=9600) self.com_lock = Lock() sleep(1) with self.com_lock: self.write('UNI,0\n'.encode()) self.readline() self.write('\x05\n'.encode()) self.readline()
def __init__(self, device, baudrate=9600): # WARNING: Never change these default options, some drivers are based # on this to work. Maybe we should change this and make all the driver # specify its options, but right now I think that's ok, since these # options are common to most of the drivers. Serial.__init__(self, device, baudrate=baudrate, bytesize=EIGHTBITS, parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=3, writeTimeout=0) self.setDTR(True) self.flushInput() self.flushOutput()
def __init__(self,port,baudrate,timeout): Serial.__init__(self) self.port=port self.baudrate=baudrate self.timeout=timeout self.bytesize = serial.EIGHTBITS #number of bits per bytes self.parity = serial.PARITY_NONE #set parity check: no parity self.stopbits = serial.STOPBITS_ONE #number of stop bits self.xonxoff=False self.rtscts=False self.dsrdtr=False self.writeTimeout=2
def __init__(self, port, endian = '>', baudrate=115200, timeout = 0.1): """ port: Serial port of the IBOB ending :(don't change) The endianness of the system, 'big'(same as network endianness) timeout : timeout of the serial port(used for readline(s) method ) baudrate :(don't change) baudrate of the system(for IBOB it's 115200, should be no need to change)s """ Serial.__init__(self, port, baudrate=baudrate, timeout=timeout) self.endian = endian self.__logger = logging.getLogger('IBOBControl') self.registers = {} # create a dictionary mapping registers to their addresses self.__update_registers() # fill the dictionary with the appropriate values
def __init__(self, *args, **kwargs): if len(args) == 0: args = ["/dev/ttyUSB0", self.baudRate] elif len(args) == 1: args = [args[0], self.baudRate] else: baudrate = args[1] # i will use this later so I can get rid of wait_response() method self.byteTime = 11.0 / float(baudrate) Serial.__init__(self, *args, **kwargs)
def __init__(self, port, baudrate, stopbits=1, parity='N', timeout=0.5): # Initializes the parent class Serial.__init__(self, port=port, baudrate=baudrate, stopbits=stopbits, parity=parity, timeout=timeout) # IDs of the master and slave. self.MASTER_ID = '\x01' self.SLAVE_ID = '\x02' if self._isOpen: self.flushInput()
def __init__(self, *args, **kwargs): #ensure that a reasonable timeout is set timeout = kwargs.get('timeout',0.1) if timeout < 0.01: timeout = 0.01 kwargs['timeout'] = 0.01 Serial.__init__(self, *args, **kwargs) self.buf = '' self.msgBytesRead = 0 self.lastMillis = 0 self.messaggehandlers = {} self.isClosing= False; self.dataqueue = Queue.Queue(0) self.parsingMessage = False
def __init__(self, baud_rate, port, data_bits=__DEFAULT_DATA_BITS, stop_bits=__DEFAULT_STOP_BITS, parity=__DEFAULT_PARITY, flow_control=__DEFAULT_FLOW_CONTROL, timeout=__DEFAULT_PORT_TIMEOUT): """ Class constructor. Instantiates a new ``XBeeSerialPort`` object with the given port parameters. Args: baud_rate (Integer): serial port baud rate. port (String): serial port name to use. data_bits (Integer, optional): serial data bits. Default to 8. stop_bits (Float, optional): serial stop bits. Default to 1. parity (Char, optional): serial parity. Default to 'N' (None). flow_control (Integer, optional): serial flow control. Default to ``None``. timeout (Integer, optional): read timeout. Default to 0.1 seconds. .. seealso:: | _PySerial: https://github.com/pyserial/pyserial """ if flow_control == FlowControl.SOFTWARE: Serial.__init__(self, port=port, baudrate=baud_rate, bytesize=data_bits, stopbits=stop_bits, parity=parity, timeout=timeout, xonxoff=True) elif flow_control == FlowControl.HARDWARE_DSR_DTR: Serial.__init__(self, port=port, baudrate=baud_rate, bytesize=data_bits, stopbits=stop_bits, parity=parity, timeout=timeout, dsrdtr=True) elif flow_control == FlowControl.HARDWARE_RTS_CTS: Serial.__init__(self, port=port, baudrate=baud_rate, bytesize=data_bits, stopbits=stop_bits, parity=parity, timeout=timeout, rtscts=True) else: Serial.__init__(self, port=port, baudrate=baud_rate, bytesize=data_bits, stopbits=stop_bits, parity=parity, timeout=timeout) self._isOpen = True if port is not None else False
def __init__(self, device, baudrate=9600): Serial.__init__(self, device) self.setDTR(True) self.flushInput() self.flushOutput() self.setBaudrate(baudrate) # WARNING: Never change these default options, some drivers are based # on this to work. Maybe we should change this and make all the driver # specify its options, but right now I think that's ok, since these # options are common to most of the drivers. self.setByteSize(EIGHTBITS) self.setParity(PARITY_NONE) self.setStopbits(STOPBITS_ONE) self.setTimeout(3) self.setWriteTimeout(0)
def __init__(self, port_num, baudrate, timeout=0.1): try: Serial.__init__(self, port=port_num, baudrate=baudrate, timeout=timeout) self.portnum = port_num self.baudrate = baudrate self.timeout = timeout self.buffer = [] except Exception as e: raise
def __init__(self, port, timeout=0.01, baudrate=9600, xonxoff=True, parity='N', stopbits=1, bytesize=8, verbosity=1): try: port = str(port) port = "COM"+port.upper().strip('COM') Serial.__init__(self, port) self.setBaudrate(baudrate) self.timeout = timeout self.xonxoff = xonxoff self.parity = parity self.stopbits = stopbits self.bytesize = bytesize self.verbosity = verbosity except Exception: print("Error connecting to port {0}\n".format(self.port), file=sys.stderr) return None
def __init__( self, port=None, baudrate=0, timeout=0.2, ): ''' Initialize the underlying serial port and provide the wrapper ''' Serial.__init__(self, port=port, baudrate=baudrate, timeout=timeout) self._sio = io.TextIOWrapper(io.BufferedRWPair(self, self), newline='\r', line_buffering=True, encoding='ISO-8859-1') self._sio_lock = threading.Lock() return
def __init__(self, *args, **kwargs): # NEW BEHAVIOR: if no parameters given, output is written # to stdout, to be piped through 'lp -o raw' (old behavior # was to use default port & baud rate). baudrate = 19200 if len(args) == 0: self.writeToStdout = True if len(args) == 1: # If only port is passed, use default baud rate. args = [args[0], baudrate] elif len(args) == 2: # If both passed, use those values. baudrate = args[1] # Firmware is assumed version 2.68. Can override this # with the 'firmware=X' argument, where X is the major # version number * 100 + the minor version number (e.g. # pass "firmware=264" for version 2.64. self.firmwareVersion = kwargs.get('firmware', 268) if self.writeToStdout is False: # Calculate time to issue one byte to the printer. # 11 bits (not 8) to accommodate idle, start and # stop bits. Idle time might be unnecessary, but # erring on side of caution here. self.byteTime = 11.0 / float(baudrate) Serial.__init__(self, *args, **kwargs) # Remainder of this method was previously in begin() # The printer can't start receiving data immediately # upon power up -- it needs a moment to cold boot # and initialize. Allow at least 1/2 sec of uptime # before printer can receive data. self.timeoutSet(0.5) self.wake() self.reset() self.dotPrintTime = 0.03 self.dotFeedTime = 0.0021 else: self.reset() # Inits some vars
def __init__(self, port, write_sleep=0.05): """ Initialization. Parallax Propeller needs a baud rate of 2400, no parity, and one or two stop bits. Parameters ---------- port : str The name of the serial port. Usually '/dev/ttyUSB0' for Linux, 'COM3' for Windows, etc. write_sleep : float, optional How long to wait in seconds after writing. For 2400 baud rate, less than 0.03 tends to cause communication errors. """ Serial.__init__(self, port=port, baudrate=2400, parity='N', stopbits=1, timeout=5.0) self.write_sleep = write_sleep time.sleep(0.1)
def __init__(self, *args, **kwargs): Serial.__init__(self) super(ESP8266, self).__init__(*args, **kwargs) self._send_res = Queue.Queue() self._on_data_callback = lambda d, l: None msg_config = { '0,CONNECT\r\n': self._echo, '1,CONNECT\r\n': self._echo, '2,CONNECT\r\n': self._echo, '3,CONNECT\r\n': self._echo, '0,CLOSED\r\n': self._echo, '1,CLOSED\r\n': self._echo, '2,CLOSED\r\n': self._echo, '3,CLOSED\r\n': self._echo, '\r\n+IPD,': self._ipd } for k in msg_config: self.msg_protocol(k, msg_config[k])
def __init__(self, *args, **kwargs): # If no parameters given, use default port & baud rate. # If only port is passed, use default baud rate. # If both passed, use those values. baudrate = 115200 if len(args) == 0: args = [ "/dev/ttyAMA0", baudrate ] elif len(args) == 1: args = [ args[0], baudrate ] else: baudrate = args[1] # Calculate time to issue one byte to the printer. # 11 bits (not 8) to accommodate idle, start and stop bits. # Idle time might be unnecessary, but erring on side of # caution here. self.byteTime = 11.0 / float(baudrate) Serial.__init__(self, *args, **kwargs) # Remainder of this method was previously in begin() # The printer can't start receiving data immediately upon # power up -- it needs a moment to cold boot and initialize. # Allow at least 1/2 sec of uptime before printer can # receive data. self.timeoutSet(0.5) self.wake() self.reset() self.writeBytes( 27, # Esc 64) # 7 (print settings) self.dotPrintTime = 0.03 self.dotFeedTime = 0.0021
def __init__(self, baud_rate, port, data_bits=__DEFAULT_DATA_BITS, stop_bits=__DEFAULT_STOP_BITS, parity=__DEFAULT_PARITY, flow_control=__DEFAULT_FLOW_CONTROL, timeout=__DEFAULT_PORT_TIMEOUT, exclusive=__DEFAULT_EXCLUSIVE): """ Class constructor. Instantiates a new `XBeeSerialPort` object with the given port parameters. Args: baud_rate (Integer): Serial port baud rate. port (String): Serial port name to use. data_bits (Integer, optional, default=8): Serial data bits. stop_bits (Float, optional, default=1): sSerial stop bits. parity (Char, optional, default=`N`): Parity. Default to 'N' (None). flow_control (Integer, optional, default=`None`): Flow control. timeout (Integer, optional, default=0.1): Read timeout (seconds). exclusive (Boolean, optional, default=`True`): Set exclusive access mode (POSIX only). A port cannot be opened in exclusive access mode if it is already open in exclusive access mode. .. seealso:: | _PySerial: https://github.com/pyserial/pyserial """ if flow_control == FlowControl.SOFTWARE: Serial.__init__(self, port=None, baudrate=baud_rate, bytesize=data_bits, stopbits=stop_bits, parity=parity, timeout=timeout, xonxoff=True, exclusive=exclusive) elif flow_control == FlowControl.HARDWARE_DSR_DTR: Serial.__init__(self, port=None, baudrate=baud_rate, bytesize=data_bits, stopbits=stop_bits, parity=parity, timeout=timeout, dsrdtr=True, exclusive=exclusive) elif flow_control == FlowControl.HARDWARE_RTS_CTS: Serial.__init__(self, port=None, baudrate=baud_rate, bytesize=data_bits, stopbits=stop_bits, parity=parity, timeout=timeout, rtscts=True, exclusive=exclusive) else: Serial.__init__(self, port=None, baudrate=baud_rate, bytesize=data_bits, stopbits=stop_bits, parity=parity, timeout=timeout, exclusive=exclusive) self.setPort(port) self._is_reading = False
def __init__(self,baudrate = 57600,timeout = 0.05): Serial.__init__(self) self.setBaudrate(baudrate) self.setTimeout(timeout) self.GetFreePort()
def __init__(self, port="COM3", baudrate=38400): '''constructor ''' Serial.__init__(self) self.port = port self.baudrate = baudrate
def __init__(self, q, port='/dev/ttyACM0', baudrate=115200): Thread.__init__(self) Serial.__init__(self, port, baudrate) self.daemon = True self.queue = q
def __init__(self, *args, **kwargs): # NEW BEHAVIOR: if no parameters given, output is written # to stdout, to be piped through 'lp -o raw' (old behavior # was to use default port & baud rate). baudrate = 19200 if len(args) == 0: self.writeToStdout = True if len(args) == 1: # If only port is passed, use default baud rate. args = [args[0], baudrate] elif len(args) == 2: # If both passed, use those values. baudrate = args[1] # Firmware is assumed version 2.68. Can override this # with the 'firmware=X' argument, where X is the major # version number * 100 + the minor version number (e.g. # pass "firmware=264" for version 2.64. self.firmwareVersion = kwargs.get('firmware', 268) if self.writeToStdout is False: # Calculate time to issue one byte to the printer. # 11 bits (not 8) to accommodate idle, start and # stop bits. Idle time might be unnecessary, but # erring on side of caution here. self.byteTime = 11.0 / float(baudrate) Serial.__init__(self, *args, **kwargs) # Remainder of this method was previously in begin() # The printer can't start receiving data immediately # upon power up -- it needs a moment to cold boot # and initialize. Allow at least 1/2 sec of uptime # before printer can receive data. self.timeoutSet(0.5) self.wake() self.reset() # Description of print settings from p. 23 of manual: # ESC 7 n1 n2 n3 Setting Control Parameter Command # Decimal: 27 55 n1 n2 n3 # max heating dots, heating time, heating interval # n1 = 0-255 Max heat dots, Unit (8dots), Default: 7 (64 dots) # n2 = 3-255 Heating time, Unit (10us), Default: 80 (800us) # n3 = 0-255 Heating interval, Unit (10us), Default: 2 (20us) # The more max heating dots, the more peak current # will cost when printing, the faster printing speed. # The max heating dots is 8*(n1+1). The more heating # time, the more density, but the slower printing # speed. If heating time is too short, blank page # may occur. The more heating interval, the more # clear, but the slower printing speed. heatTime = kwargs.get('heattime', self.defaultHeatTime) self.writeBytes( 27, # Esc 55, # 7 (print settings) 11, # Heat dots heatTime, # Lib default 40) # Heat interval # Description of print density from p. 23 of manual: # DC2 # n Set printing density # Decimal: 18 35 n # D4..D0 of n is used to set the printing density. # Density is 50% + 5% * n(D4-D0) printing density. # D7..D5 of n is used to set the printing break time. # Break time is n(D7-D5)*250us. # (Unsure of default values -- not documented) printDensity = 10 # 100% printBreakTime = 2 # 500 uS self.writeBytes( 18, # DC2 35, # Print density (printBreakTime << 5) | printDensity) self.dotPrintTime = 0.03 self.dotFeedTime = 0.0021 else: self.reset() # Inits some vars
def __init__(self, *args, **kwargs): # If no parameters given, use default port & baud rate. # If only port is passed, use default baud rate. # If both passed, use those values. baudrate = 19200 if len(args) == 0: args = [ "/dev/ttyAMA0", baudrate ] elif len(args) == 1: args = [ args[0], baudrate ] else: baudrate = args[1] # Calculate time to issue one byte to the printer. # 11 bits (not 8) to accommodate idle, start and stop bits. # Idle time might be unnecessary, but erring on side of # caution here. self.byteTime = 11.0 / float(baudrate) Serial.__init__(self, *args, **kwargs) # Remainder of this method was previously in begin() # The printer can't start receiving data immediately upon # power up -- it needs a moment to cold boot and initialize. # Allow at least 1/2 sec of uptime before printer can # receive data. self.timeoutSet(1) self.wake() self.reset() # Description of print settings from page 23 of the manual: # ESC 7 n1 n2 n3 Setting Control Parameter Command # Decimal: 27 55 n1 n2 n3 # Set "max heating dots", "heating time", "heating interval" # n1 = 0-255 Max heat dots, Unit (8dots), Default: 7 (64 dots) # n2 = 3-255 Heating time, Unit (10us), Default: 80 (800us) # n3 = 0-255 Heating interval, Unit (10us), Default: 2 (20us) # The more max heating dots, the more peak current will cost # when printing, the faster printing speed. The max heating # dots is 8*(n1+1). The more heating time, the more density, # but the slower printing speed. If heating time is too short, # blank page may occur. The more heating interval, the more # clear, but the slower printing speed. heatTime = kwargs.get('heattime', self.defaultHeatTime) self.writeBytes( 27, # Esc 55, # 7 (print settings) 20, # Heat dots (20 = balance darkness w/no jams) heatTime, # Lib default = 45 250) # Heat interval (500 uS = slower but darker) # Description of print density from page 23 of the manual: # DC2 # n Set printing density # Decimal: 18 35 n # D4..D0 of n is used to set the printing density. # Density is 50% + 5% * n(D4-D0) printing density. # D7..D5 of n is used to set the printing break time. # Break time is n(D7-D5)*250us. # (Unsure of the default value for either -- not documented) printDensity = 14 # 120% (can go higher, but text gets fuzzy) printBreakTime = 4 # 500 uS self.writeBytes( 18, # DC2 35, # Print density (printBreakTime << 5) | printDensity) self.dotPrintTime = 0.033 self.dotFeedTime = 0.0021
def __init__(self, timeout=2): if not _imported_serial: raise RuntimeError('The serial module was not imported.') Serial.__init__(self, timeout=timeout)
def __init__(self, *args, **kwargs): timeout=kwargs.get('timeout',0.1) kwargs['timeout']=timeout Serial.__init__(self, *args, **kwargs) self.buf=''
def __init__(self, *args, **kwargs): # If no parameters given, use default port & baud rate. # If only port is passed, use default baud rate. # If both passed, use those values. baudrate = 19200 rtscts = True if len(args) == 0: args = ["/dev/ttyAMA0", baudrate] elif len(args) == 1: args = [args[0], baudrate] else: baudrate = args[1] # Calculate time to issue one byte to the printer. # 11 bits (not 8) to accommodate idle, start and stop bits. # Idle time might be unnecessary, but erring on side of # caution here. self.byteTime = 11.0 / float(baudrate) Serial.__init__(self, *args, **kwargs) # Remainder of this method was previously in begin() # The printer can't start receiving data immediately upon # power up -- it needs a moment to cold boot and initialize. # Allow at least 1/2 sec of uptime before printer can # receive data. self.timeoutSet(0.5) self.wake() self.reset() # GPIO.setmode(GPIO.BOARD) # GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Description of print settings from page 23 of the manual: # ESC 7 n1 n2 n3 Setting Control Parameter Command # Decimal: 27 55 n1 n2 n3 # Set "max heating dots", "heating time", "heating interval" # n1 = 0-255 Max heat dots, Unit (8dots), Default: 7 (64 dots) # n2 = 3-255 Heating time, Unit (10us), Default: 80 (800us) # n3 = 0-255 Heating interval, Unit (10us), Default: 2 (20us) # The more max heating dots, the more peak current will cost # when printing, the faster printing speed. The max heating # dots is 8*(n1+1). The more heating time, the more density, # but the slower printing speed. If heating time is too short, # blank page may occur. The more heating interval, the more # clear, but the slower printing speed. heatTime = kwargs.get('heattime', self.defaultHeatTime) self.writeBytes( 27, # Esc 55, # 7 (print settings) 5, # Heat dots (20 = balance darkness w/no jams) heatTime, # Lib default = 45 250) # Heat interval (500 uS = slower but darker) # Description of print density from page 23 of the manual: # DC2 # n Set printing density # Decimal: 18 35 n # D4..D0 of n is used to set the printing density. # Density is 50% + 5% * n(D4-D0) printing density. # D7..D5 of n is used to set the printing break time. # Break time is n(D7-D5)*250us. # (Unsure of the default value for either -- not documented) printDensity = 12 # 120% (can go higher, but text gets fuzzy) printBreakTime = 7 # 500 uS self.writeBytes( 18, # DC2 35, # Print density (printBreakTime << 5) | printDensity) self.dotPrintTime = 0.03 self.dotFeedTime = 0.0021
def __init__(self): Serial.__init__(self) self.lastDirection = None self.logging = 'OFF'
def __init__(self, leds=1, *args, **kwargs): Serial.__init__(self, *args, **kwargs)
def __init__(self, port="/dev/ttyUSB0", baudrate=115200, p=3, debug = False, dbglevel = 100): Serial.__init__(self, port, baudrate) self.pin = p self.debug = debug self.dbglevel = dbglevel
def __init__(self, comPort='/dev/ttyACM0', baudRate=9600): """Overloaded to set default values - Check pySerial Documentation""" Serial.__init__(self, comPort, baudRate) print("Initialised Serial connection") time.sleep(3)
def __init__(self, device="/dev/ttyUSB0", baud=115200, timeout=1, writeTimeout=1, Sps=1000, filtercode=1): """ The 'baud' argument is provided to compensate for a possible difference between the Radipower BAUD rate andthe computer BAUD rate. Basically, it's best not to fiddle with the BAUD rate because getting it wrong locks up the device. @param device : USB port assigned to the power meter @type device : string @param baud : interface transfer rate in bps (bits per second) @type baud : int @param timeout : give up reading after this amount of time @type timeout : float @param writeTimeout : give up writing after this amount of time @type writeTimeout : float @param Sps : ADC samples per second @type Sps : int """ mylogger = logging.getLogger(logger.name+".Radipower") Serial.__init__(self, device, baud, timeout=timeout, writeTimeout=writeTimeout) sleep(0.02) self.name = basename(device) PowerMeter.__init__(self, self.name) self.logger = mylogger self.logger.debug(" initializing %s", device) self._attributes_ = [] self._attributes_.append('logger') if self.get_ID(): if self.ID: if Radipower.assigned.has_key(self.ID): self.logger.warning("__init__: %s already assigned as Radipower %d", device, found) else: Radipower.assigned[IDs[self.ID]] = device # show device as assigned self.name = "PM%02d" % IDs[self.ID] self._attributes_.append('name') self.identify() self._attributes_.append('model') self._attributes_.append("HWversion"), self._attributes_.append("SWversion") # These replace class PowerMeter defaults self.f_min = float(self.ask("FREQUENCY? MIN")[:-4])/1.e6 # GHz self.f_max = float(self.ask("FREQUENCY? MAX")[:-4])/1.e6 # GHz self.p_min = -55 # dBm self.p_max = +10 # dBm self.auto_averaging() # sets num_avg # units and trigmode are the same as the PowerMeter defaults if self.model[:7] == 'RPR1018': self.units = 0 # dBm self.ask("FILTER 3") # so it's like the 2006s else: self.units = self.ask("POWER_UNIT?") self.trigmode = None # triggering mode # use highest sampling speed try: self.ask("ACQ_SPEED "+str(Sps)) except RadipowerError as details: if str(details.message) == 'is not a valid command': # for old model radipowers pass else: raise RuntimeError(details) self.ask("FILTER "+str(filtercode)) self.logger.debug(" initialized %s", device[5:]) else: raise RadipowerError(self.ID, 'is not a valid response to ID_NUMBER?') else: self.logger.warning(" initialization failed")
def __init__(self, *args, **kwargs): #print serial_ports[kwargs.get('port')] kwargs['port'] = serial_ports[kwargs.get('port')] Serial.__init__(self, *args, **kwargs) self.buf = ''
def __init__(self, port): Serial.__init__(self, port) self.internal_temperature = Queue() self.thermocouple_temperature = Queue() self.updater = Thread()
def __init__(self, *args, **kwrags): # call default (base) constructor Serial.__init__(self, *args, **kwrags) self.lock = None self.lock_given = False
def __init__(self, *args, **kwargs): Serial.__init__(self, *args, **kwargs) self.escape_flag = False
def openPort(self): ports = comports() Serial.__init__(self, self.__findTeensy__(ports), 115200) self.timeout = 0.01 crap = self.read_all()
def __init__(self,*args,**argv): Serial.__init__(self,*args,**argv) while True: if b'' == self.read(): break
def __init__(self,port, baudrate): BaseSerial.__init__(self) self._baudrate = baudrate self.setPort(port) pass
def __init__(self): Serial.__init__(self, '/dev/ttyUSB0', 9600) self.flush()
def __init__(self, *args, **argv): Serial.__init__(self, *args, **argv) while True: if b'' == self.read(): break
def __init__(self,baudrate = 57600,timeout = 1): Serial.__init__(self) self.setBaudrate(baudrate) self.setTimeout(timeout) self.GetFreePort()
def __init__(self, *args, **kwargs): Serial.__init__(self, *args, **kwargs) self._writelock = threading.Lock() self._readlock = threading.Lock()