Exemple #1
0
 def test_PortSetting(self):
     self.s.port = PORT
     # portstr has to be set
     if isinstance(PORT, str):
         self.failUnlessEqual(self.s.portstr.lower(), PORT.lower())
     else:
         self.failUnlessEqual(self.s.portstr, serial.device(PORT))
     # test internals
     self.failUnlessEqual(self.s._port, PORT)
     # test on the fly change
     self.s.open()
     self.failUnless(self.s.isOpen())
     try:
         self.s.port = 0
     except serial.SerialException: # port not available on system
         pass        # can't test on this machine...
     else:
         self.failUnless(self.s.isOpen())
         self.failUnlessEqual(self.s.port, 0)
         self.failUnlessEqual(self.s.portstr, serial.device(0))
     try:
         self.s.port = 1
     except serial.SerialException: # port not available on system
         pass        # can't test on this machine...
     else:
         self.failUnless(self.s.isOpen())
         self.failUnlessEqual(self.s.port, 1)
         self.failUnlessEqual(self.s.portstr, serial.device(1))
Exemple #2
0
 def test_PortSetting(self):
     self.s.port = PORT
     # portstr has to be set
     if isinstance(PORT, str):
         self.failUnlessEqual(self.s.portstr.lower(), PORT.lower())
     else:
         self.failUnlessEqual(self.s.portstr, serial.device(PORT))
     # test internals
     self.failUnlessEqual(self.s._port, PORT)
     # test on the fly change
     self.s.open()
     self.failUnless(self.s.isOpen())
     try:
         self.s.port = 0
     except serial.SerialException:  # port not available on system
         pass  # can't test on this machine...
     else:
         self.failUnless(self.s.isOpen())
         self.failUnlessEqual(self.s.port, 0)
         self.failUnlessEqual(self.s.portstr, serial.device(0))
     try:
         self.s.port = 1
     except serial.SerialException:  # port not available on system
         pass  # can't test on this machine...
     else:
         self.failUnless(self.s.isOpen())
         self.failUnlessEqual(self.s.port, 1)
         self.failUnlessEqual(self.s.portstr, serial.device(1))
Exemple #3
0
def dispenser_controller():
  global dispenser_serial, rfid_device, dispenser_device
  while True:
    if settings.DISPENSER_COMPORT:
      print "Waiting for vending machine controller"
      dispenser_serial = get_serial(settings.DISPENSER_COMPORT)
      dispenser_device = settings.DISPENSER_COMPORT
    else:
      print "Looking for vending machine controller"
      dispenser_serial = None
      while not dispenser_serial:
        for i in range(1, 10):
          try:
            device = serial.device(i)
            if device != rfid_device:
              dispenser_serial = serial.Serial(device)
              dispenser_device = device
              break
          except serial.SerialException:
            continue
    print "Connected to vending machine controller"

    while True:
      try:
        if len(dispenser_serial.read(512)) == 0:
          break
      except:
        break
      time.sleep(3)
Exemple #4
0
def list(avoid=()):
    ports=[]
    names=[]

    #  Standard serial devices (/dev/ttyS??, COM?? ...)
    #
    for n in range(8):
        d = serial.device(n)
        names.append(d)

    #  Linux USB adapter devices
    #
    for n in range(8):
        d = '/dev/ttyUSB%d' % n
        names.append(d)

    #  Check the availability of each device
    #
    for name in names:
        try:
            if not name in avoid:
                com=serial.Serial(name)
                com.close()
                ports.append(name)
        except serial.SerialException, e:
            pass
Exemple #5
0
def list(avoid=()):
    ports = []
    names = []

    #  Standard serial devices (/dev/ttyS??, COM?? ...)
    #
    for n in range(8):
        d = serial.device(n)
        names.append(d)

    #  Linux USB adapter devices
    #
    for n in range(8):
        d = '/dev/ttyUSB%d' % n
        names.append(d)

    #  Check the availability of each device
    #
    for name in names:
        try:
            if not name in avoid:
                com = serial.Serial(name)
                com.close()
                ports.append(name)
        except serial.SerialException, e:
            pass
Exemple #6
0
    def __combo_init(self):
        #port init
        self.combo_box_port.Clear()
        cnt = 0
        for i in range(20):
            self.combo_box_port.Append(serial.device(i))
            if self.serial.portstr == serial.device(i):
                cnt = i
        self.combo_box_port.SetValue(serial.device(cnt))

        #baudrate init
        self.combo_box_baudrate.Clear()
        cnt = 0
        for i, item in enumerate(self.serial.BAUDRATES):
            self.combo_box_baudrate.Append(str(item))
            if item == self.serial.baudrate:
                cnt = i
        self.combo_box_baudrate.SetValue(str(self.serial.BAUDRATES[cnt]))

        #bytesize init
        self.combo_box_bytesize.Clear()
        cnt = 0
        for i, item in enumerate(self.serial.BYTESIZES):
            self.combo_box_bytesize.Append(str(item))
            if item == self.serial.bytesize:
                cnt = i
        self.combo_box_bytesize.SetValue(str(self.serial.BYTESIZES[cnt]))

        #stopbits init
        self.combo_box_stopbits.Clear()
        cnt = 0
        for i, item in enumerate(self.serial.STOPBITS):
            self.combo_box_stopbits.Append(str(item))
            if item == self.serial.stopbits:
                cnt = i
        self.combo_box_stopbits.SetValue(str(self.serial.STOPBITS[cnt]))

        #baudrate init
        self.combo_box_parity.Clear()
        cnt = 0
        for i, item in enumerate(self.serial.PARITIES):
            self.combo_box_parity.Append(str(item))
            if item == self.serial.parity:
                cnt = i
        self.combo_box_parity.SetValue(str(self.serial.PARITIES[cnt]))
        self.radio_box_rtscts.SetSelection(self.serial.rtscts)
        self.radio_box_xonxoff.SetSelection(self.serial.xonxoff)
Exemple #7
0
    def __combo_init(self):
        #port init
        self.combo_box_port.Clear()
        cnt = 0
        for i in range(20):
            self.combo_box_port.Append(serial.device(i))
            if self.serial.portstr == serial.device(i):
                cnt = i
        self.combo_box_port.SetValue(serial.device(cnt))
        
        #baudrate init
        self.combo_box_baudrate.Clear()
        cnt = 0
        for i, item in enumerate(self.serial.BAUDRATES):
            self.combo_box_baudrate.Append(str(item))
            if item == self.serial.baudrate:
                cnt = i
        self.combo_box_baudrate.SetValue(str(self.serial.BAUDRATES[cnt]))
        
        #bytesize init
        self.combo_box_bytesize.Clear()
        cnt = 0
        for i, item in enumerate(self.serial.BYTESIZES):
            self.combo_box_bytesize.Append(str(item))
            if item == self.serial.bytesize:
                cnt = i
        self.combo_box_bytesize.SetValue(str(self.serial.BYTESIZES[cnt]))

        #stopbits init
        self.combo_box_stopbits.Clear()
        cnt = 0
        for i, item in enumerate(self.serial.STOPBITS):
            self.combo_box_stopbits.Append(str(item))
            if item == self.serial.stopbits:
                cnt = i
        self.combo_box_stopbits.SetValue(str(self.serial.STOPBITS[cnt]))
        
        #baudrate init
        self.combo_box_parity.Clear()
        cnt = 0
        for i, item in enumerate(self.serial.PARITIES):
            self.combo_box_parity.Append(str(item))
            if item == self.serial.parity:
                cnt = i
        self.combo_box_parity.SetValue(str(self.serial.PARITIES[cnt]))
        self.radio_box_rtscts.SetSelection(self.serial.rtscts)
        self.radio_box_xonxoff.SetSelection(self.serial.xonxoff)
Exemple #8
0
    def SetContentFromPort(self):
        index = 0  # fill in ports and select current setting
        self.combo_box_port1.Clear()
        for n in range(4):
            portname = serial.device(n)
            self.combo_box_port1.Append(portname)
            if self.serial1.portstr == portname:
                index = n
        if self.serial1.portstr is not None:
            self.combo_box_port1.SetValue(str(self.serial1.portstr))
        else:
            self.combo_box_port1.SetSelection(index)

        if self.show & SHOW_BAUDRATE:
            #fill in badrates and select current setting
            self.choice_baudrate.Clear()
            for n, baudrate in enumerate(self.serial1.BAUDRATES):
                self.choice_baudrate.Append(str(baudrate))
                if self.serial1.baudrate == baudrate:
                    index = n
            self.choice_baudrate.SetSelection(index)
        if self.show & SHOW_FORMAT:
            #fill in databits and select current setting
            self.choice_databits.Clear()
            for n, bytesize in enumerate(self.serial1.BYTESIZES):
                self.choice_databits.Append(str(bytesize))
                if self.serial1.bytesize == bytesize:
                    index = n
            self.choice_databits.SetSelection(index)
            #fill in stopbits and select current setting
            self.choice_stopbits.Clear()
            for n, stopbits in enumerate(self.serial1.STOPBITS):
                self.choice_stopbits.Append(str(stopbits))
                if self.serial1.stopbits == stopbits:
                    index = n
            self.choice_stopbits.SetSelection(index)
            #fill in parities and select current setting
            self.choice_parity.Clear()
            for n, parity in enumerate(self.serial1.PARITIES):
                self.choice_parity.Append(str(serial.PARITY_NAMES[parity]))
                if self.serial1.parity == parity:
                    index = n
            self.choice_parity.SetSelection(index)
        if self.show & SHOW_TIMEOUT:
            if self.serial1.timeout is None:  # set the timeout mode and value
                self.checkbox_timeout.SetValue(False)
                self.text_ctrl_timeout.Enable(False)
            else:
                self.checkbox_timeout.SetValue(True)
                self.text_ctrl_timeout.Enable(True)
                self.text_ctrl_timeout.SetValue(str(self.serial1.timeout))
        if self.show & SHOW_FLOW:
            self.checkbox_rtscts.SetValue(
                self.serial1.rtscts)  # set the rtscts mode
            self.checkbox_xonxoff.SetValue(
                self.serial1.xonxoff)  # set the rtscts mode

        success = True
 def serialPorts(self):
     # find all available serial device names
     for each in range(10):
         try:
             serial.Serial(each)
             self.comList[serial.device(each)] = each
         except:
             pass
     return self.comList
Exemple #10
0
 def updateList(self):
     #self.baudRateListBox.setCurrentText(QString(str(self.baudRate)))
     self.baudRateListBox.setEditText(QString(str(self.baudRate)))
     portName = serial.device(self.port)
     if self.serialList.has_key(portName):
         self.serialListBox.setEditText(QString(portName))
     else:
         key = unicode(self.serialListBox.currentText())
         self.port = self.serialList[key]
Exemple #11
0
 def test_PortSetting(self):
     self.s.port = PORT
     # portstr has to be set
     if isinstance(PORT, str):
         self.assertEqual(self.s.portstr.lower(), PORT.lower())
     else:
         self.assertEqual(self.s.portstr, serial.device(PORT))
     # test internals
     self.assertEqual(self.s._port, PORT)
     # test on the fly change
     self.s.open()
     self.assertTrue(self.s.isOpen())
Exemple #12
0
 def test_PortSetting(self):
     self.s.port = PORT
     # portstr has to be set
     if isinstance(PORT, str):
         self.failUnlessEqual(self.s.portstr.lower(), PORT.lower())
     else:
         self.failUnlessEqual(self.s.portstr, serial.device(PORT))
     # test internals
     self.failUnlessEqual(self.s._port, PORT)
     # test on the fly change
     self.s.open()
     self.failUnless(self.s.isOpen())
Exemple #13
0
 def findExistSerialPort(self, portNum):
     try:
         tempPortObj = None
         tempPortObj =  serial.Serial(portNum)
     except SerialException:
         pass
     finally:
         if tempPortObj is not None:
             tempPortObj.close()
             return serial.device(portNum)
         else:
             return None
Exemple #14
0
 def SC_COM_connect(self, port_num, baudrate):
     """
     Opens the serial connection with the values passed in arguments.
     It also sets the DTR value to True.
     """
     # serial connection parameters
     port_device = serial.device(port_num)
     self.logger.debug("openning device port: %s" % port_device)
     self._ser.setPort(port_device)
     self._ser.setBaudrate(baudrate)
     # open the serial port
     self._ser.open()
     self._ser.setDTR(True)
Exemple #15
0
def serial_ports():

    if os.name == 'nt':
        for i in range(256):
            try:
                s = serial.Serial(i)
                s.close()
                yield serial.device(i)
            except serial.SerialException:
                pass
    else:
        for port in list_ports.comports():
            yield port[0]
Exemple #16
0
def get_ports():
    try:
        from serial.tools import list_ports
        ports = [p[0] for p in list_ports.comports()]
    except ImportError:
        #pyserial 2.6 or older
        ports = [serial.device(i) for i in range(5)]
        if os.name == "posix":
            for device in ["/dev/ttyUSB%d" % i for i in range(5)]:
                if os.path.exists(device):
                    ports.append(device)
            for device in ["/dev/ttyACM%d" % i for i in range(5)]:
                if os.path.exists(device):
                    ports.append(device)
    return ports
Exemple #17
0
def get_ports():
    try:
        from serial.tools import list_ports
        ports = [p[0] for p in list_ports.comports()]
    except ImportError:
        #pyserial 2.6 or older
        ports = [serial.device(i) for i in range(5)]
        if os.name == "posix":
            for device in ["/dev/ttyUSB%d" % i for i in range(5)]:
                if os.path.exists(device):
                    ports.append(device)
            for device in ["/dev/ttyACM%d" % i for i in range(5)]:
                if os.path.exists(device):
                    ports.append(device)
    return ports
 def __init__(self, wpm=10, sport=0, sbaudrate=9600, sbytesize=8, sparity='N',
              sstopbits=1, stimeout=None, sxonxoff=False, srtscts=False,
              sdsrdtr=False):
     u"""Crea una nueva instacia de CodigomorseSerial.
     
        Argumentos:
        wpm        --  Words Per Minute (Palabras Por Minuto)(default: 10)
        sport      --  Puerto serie a utilizar (default: 0)
        sbaudrate  --  Ratio de baudios a utilizar (default: 9600)
        sbytesize  --  Tamaño de bytes (default: 8)
        sparity    --  Bit de paridad (default: 'N')
        sstopbits  --  Bits de parada (default: 1)
        stimeout   --  Timeout (default: None)
        
        
        Atención: poner a True solamente uno de los 3 argumentos siguientes:
        sxonxoff   --  Control de flujo por software (default: False)
        srtscts    --  Control de flujo por hardware RTS/CTS (default: False)
        sdsrdtr    --  Control de flujo por hardware DSR/DTR (default: False)
     """
     try:
         # Inicializar puerto serie
         self.serialport = serial.Serial(port=sport, baudrate=sbaudrate,
                                         bytesize=sbytesize, parity=sparity,
                                         stopbits=sstopbits, timeout=stimeout,
                                         xonxoff=sxonxoff, rtscts=srtscts,
                                         dsrdtr=sdsrdtr)
         self.serialport.setRTS(0)
         self.serialport.setDTR(0)
     except serial.SerialException:
         print 'Se ha producido un error al intentar conectarse al' + \
               ' puerto {0} ("{1}")'.format(sport, serial.device(sport))
     
     self.words_per_minute = wpm
     # Utilizar números flotantes debido a un problema en la división realizada 
     # por el intérprete de Python 2.x
     self.time_unit = 1200.0 / wpm       
     self.tmp_dot = self.time_unit
     self.tmp_dash = self.tmp_dot * 3
     self.tmp_inter_elements_space = self.tmp_dot
     self.tmp_space_between_letters = self.tmp_dot * 3
     self.tmp_space_between_words = self.tmp_dot * 7
Exemple #19
0
    rfid_sock = None
  
except socket.error as e:
  if e.errno == 10048:
    raw_input("""!! Fatal Error: Socket already in use. Close all other instances of this server
!! and then restart it. If you don't have any visible instances open, try
!! checking for python.exe instances in the task manager.
[ENTER] to exit.""")
    exit()
  else:
    print e.errno
    raise e

## Serial Set-UP
if settings.RFID_SCANNER == NORMAL and type(settings.RFID_SCANNER_COMPORT) == int:
  settings.RFID_SCANNER_COMPORT = serial.device(settings.RFID_SCANNER_COMPORT - 1)
if settings.DISPENSER == NORMAL and type(settings.DISPENSER_COMPORT) == int:
  settings.DISPENSER_COMPORT = serial.device(settings.DISPENSER_COMPORT - 1)

rfid_serial = None
rfid_device = None
dispenser_serial = None
dispenser_device = None

## Subprocess Set-Up
money_process = None
def start_money():
  global money_process
  if settings.BILL_ACCEPTOR == NORMAL and not money_process:
    money_process = subprocess.Popen(["../Munay/bin/Release/Munay.exe"],
                                     creationflags = \
    def __init__(self, *args, **kwds):
        #grab the serial keyword and remove it from the dict
        self.serial = kwds['serial']
        del kwds['serial']
        self.show = SHOW_ALL
        if kwds.has_key('show'):
            self.show = kwds['show']
            del kwds['show']
        # begin wxGlade: SerialConfigDialog.__init__
        # end wxGlade
        kwds["style"] = wxDEFAULT_DIALOG_STYLE
        wxDialog.__init__(self, *args, **kwds)
        self.label_2 = wxStaticText(self, -1, "Port")
        self.combo_box_port = wxComboBox(
            self,
            -1,
            choices=["dummy1", "dummy2", "dummy3", "dummy4", "dummy5"],
            style=wxCB_DROPDOWN)
        if self.show & SHOW_BAUDRATE:
            self.label_1 = wxStaticText(self, -1, "Baudrate")
            self.choice_baudrate = wxChoice(self, -1, choices=["choice 1"])
        if self.show & SHOW_FORMAT:
            self.label_3 = wxStaticText(self, -1, "Data Bits")
            self.choice_databits = wxChoice(self, -1, choices=["choice 1"])
            self.label_4 = wxStaticText(self, -1, "Stop Bits")
            self.choice_stopbits = wxChoice(self, -1, choices=["choice 1"])
            self.label_5 = wxStaticText(self, -1, "Parity")
            self.choice_parity = wxChoice(self, -1, choices=["choice 1"])
        if self.show & SHOW_TIMEOUT:
            self.checkbox_timeout = wxCheckBox(self, -1, "Use Timeout")
            self.text_ctrl_timeout = wxTextCtrl(self, -1, "")
            self.label_6 = wxStaticText(self, -1, "seconds")
        if self.show & SHOW_FLOW:
            self.checkbox_rtscts = wxCheckBox(self, -1, "RTS/CTS")
            self.checkbox_xonxoff = wxCheckBox(self, -1, "Xon/Xoff")
        self.button_ok = wxButton(self, -1, "OK")
        self.button_cancel = wxButton(self, -1, "Cancel")

        self.__set_properties()
        self.__do_layout()
        #fill in ports and select current setting
        index = 0
        self.combo_box_port.Clear()
        for n in range(4):
            portname = serial.device(n)
            self.combo_box_port.Append(portname)
            if self.serial.portstr == portname:
                index = n
        if self.serial.portstr is not None:
            self.combo_box_port.SetValue(str(self.serial.portstr))
        else:
            self.combo_box_port.SetSelection(index)
        if self.show & SHOW_BAUDRATE:
            #fill in badrates and select current setting
            self.choice_baudrate.Clear()
            for n, baudrate in enumerate(self.serial.BAUDRATES):
                self.choice_baudrate.Append(str(baudrate))
                if self.serial.baudrate == baudrate:
                    index = n
            self.choice_baudrate.SetSelection(index)
        if self.show & SHOW_FORMAT:
            #fill in databits and select current setting
            self.choice_databits.Clear()
            for n, bytesize in enumerate(self.serial.BYTESIZES):
                self.choice_databits.Append(str(bytesize))
                if self.serial.bytesize == bytesize:
                    index = n
            self.choice_databits.SetSelection(index)
            #fill in stopbits and select current setting
            self.choice_stopbits.Clear()
            for n, stopbits in enumerate(self.serial.STOPBITS):
                self.choice_stopbits.Append(str(stopbits))
                if self.serial.stopbits == stopbits:
                    index = n
            self.choice_stopbits.SetSelection(index)
            #fill in parities and select current setting
            self.choice_parity.Clear()
            for n, parity in enumerate(self.serial.PARITIES):
                self.choice_parity.Append(str(serial.PARITY_NAMES[parity]))
                if self.serial.parity == parity:
                    index = n
            self.choice_parity.SetSelection(index)
        if self.show & SHOW_TIMEOUT:
            #set the timeout mode and value
            if self.serial.timeout is None:
                self.checkbox_timeout.SetValue(False)
                self.text_ctrl_timeout.Enable(False)
            else:
                self.checkbox_timeout.SetValue(True)
                self.text_ctrl_timeout.Enable(True)
                self.text_ctrl_timeout.SetValue(str(self.serial.timeout))
        if self.show & SHOW_FLOW:
            #set the rtscts mode
            self.checkbox_rtscts.SetValue(self.serial.rtscts)
            #set the rtscts mode
            self.checkbox_xonxoff.SetValue(self.serial.xonxoff)
        #attach the event handlers
        self.__attach_events()
Exemple #21
0
    def __init__(self, *args, **kwds):
        #grab the serial keyword and remove it from the dict
        self.serial = kwds['serial']
        del kwds['serial']

        self.show = SHOW_ALL
        if 'show' in kwds:
            self.show = kwds['show']
            del kwds['show']

        self.settings = kwds['settings']
        del kwds['settings']

        self.bot = kwds['bot']
        #self.creator = kwds['creator']
        #print 1
        del kwds['bot']

        # begin wxGlade: SerialConfigDialog.__init__
        # end wxGlade
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)

        self.sizer_main = wx.BoxSizer(wx.VERTICAL)
        #For some strange reason MacOSX require it to be defined before controls, which would added to it.
        #Otherwise they are simply disabled.
        self.sizer_basics = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Basics"), wx.VERTICAL)
        self.sizer_4 = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Input/Output"), wx.VERTICAL)
        self.sizer_nb = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Legs"), wx.VERTICAL)
        self.sizer_timeout = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Timeout"), wx.HORIZONTAL)
        self.sizer_flow = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Flow Control"), wx.HORIZONTAL)
        self.sizer_format = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Data Format"), wx.VERTICAL)
        self.sizer_9 = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Bot"), wx.VERTICAL)

        self.label_2 = wx.StaticText(self, -1, "Port")
        self.combo_box_port = wx.ComboBox(self, -1, choices=["dummy1",
                                                             "dummy2",
                                                             "dummy3",
                                                             "dummy4",
                                                             "dummy5"],
                                          style=wx.CB_DROPDOWN)
        if self.show & SHOW_BAUDRATE:
            self.label_1 = wx.StaticText(self, -1, "Baudrate")
            self.choice_baudrate = wx.Choice(self, -1, choices=["choice 1"])
        if self.show & SHOW_FORMAT:
            self.label_3 = wx.StaticText(self, -1, "Data Bits")
            self.choice_databits = wx.Choice(self, -1, choices=["choice 1"])
            self.label_4 = wx.StaticText(self, -1, "Stop Bits")
            self.choice_stopbits = wx.Choice(self, -1, choices=["choice 1"])
            self.label_5 = wx.StaticText(self, -1, "Parity")
            self.choice_parity = wx.Choice(self, -1, choices=["choice 1"])
        if self.show & SHOW_TIMEOUT:
            self.checkbox_timeout = wx.CheckBox(self, -1, "Use Timeout")
            self.text_ctrl_timeout = wx.TextCtrl(self, -1, "")
            self.label_6 = wx.StaticText(self, -1, "seconds")
        if self.show & SHOW_FLOW:
            self.checkbox_rtscts = wx.CheckBox(self, -1, "RTS/CTS")
            self.checkbox_xonxoff = wx.CheckBox(self, -1, "Xon/Xoff")
        self.button_ok = wx.Button(self, -1, "OK")
        self.button_cancel = wx.Button(self, -1, "Cancel")

        #Terminal settings
        self.checkbox_echo = wx.CheckBox(self, -1, "Local Echo")
        self.checkbox_unprintable = wx.CheckBox(self, -1, "Show unprintable characters")
        self.radio_box_newline = wx.RadioBox(self, -1, "Newline Handling", choices=["CR only", "LF only", "CR+LF"],
                                             majorDimension=0, style=wx.RA_SPECIFY_ROWS)

        #set Bot settings
        self.radio_box_protocol = wx.RadioBox(self, -1, "Protocol", choices=self.bot.protocols, majorDimension=0,
                                              style=wx.RA_SPECIFY_ROWS)
        self.nb = wx.Notebook(self, wx.ID_ANY, style=0)
        self.leg_pages = []

        self.robots = []
        for file_name in os.listdir('Robots'):
            if os.path.splitext(file_name)[1] == '.json':
                file_name = os.path.splitext(file_name)[0]
                s1 = re.sub('(.)([A-Z][a-z]+)', r'\1 \2', file_name)
                self.robots.append(s1)
        self.choice_robots = wx.Choice(self, -1, choices=self.robots)

        self.__set_properties()
        self.__do_layout()
        #fill in ports and select current setting
        index = 0
        self.combo_box_port.Clear()
        for n in range(4):
            portname = serial.device(n)
            self.combo_box_port.Append(portname)
            if self.serial.portstr == portname:
                index = n
        if self.serial.portstr is not None:
            self.combo_box_port.SetValue(str(self.serial.portstr))
        else:
            #self.combo_box_port.SetSelection(index)
            self.combo_box_port.SetSelection(2)
        if self.show & SHOW_BAUDRATE:
            #fill in badrates and select current setting
            self.choice_baudrate.Clear()
            for n, baudrate in enumerate(self.serial.BAUDRATES):
                self.choice_baudrate.Append(str(baudrate))
                if self.serial.baudrate == baudrate:
                    index = n
                    #self.choice_baudrate.SetSelection(index)
            self.choice_baudrate.SetSelection(len(self.serial.BAUDRATES) - 1)
        if self.show & SHOW_FORMAT:
            #fill in databits and select current setting
            self.choice_databits.Clear()
            for n, bytesize in enumerate(self.serial.BYTESIZES):
                self.choice_databits.Append(str(bytesize))
                if self.serial.bytesize == bytesize:
                    index = n
            self.choice_databits.SetSelection(index)
            #fill in stopbits and select current setting
            self.choice_stopbits.Clear()
            for n, stopbits in enumerate(self.serial.STOPBITS):
                self.choice_stopbits.Append(str(stopbits))
                if self.serial.stopbits == stopbits:
                    index = n
            self.choice_stopbits.SetSelection(index)
            #fill in parities and select current setting
            self.choice_parity.Clear()
            for n, parity in enumerate(self.serial.PARITIES):
                self.choice_parity.Append(str(serial.PARITY_NAMES[parity]))
                if self.serial.parity == parity:
                    index = n
            self.choice_parity.SetSelection(index)
        if self.show & SHOW_TIMEOUT:
            #set the timeout mode and value
            if self.serial.timeout is None:
                self.checkbox_timeout.SetValue(False)
                self.text_ctrl_timeout.Enable(False)
            else:
                self.checkbox_timeout.SetValue(True)
                self.text_ctrl_timeout.Enable(True)
                self.text_ctrl_timeout.SetValue(str(self.serial.timeout))
        if self.show & SHOW_FLOW:
            #set the rtscts mode
            self.checkbox_rtscts.SetValue(self.serial.rtscts)
            #set the rtscts mode
            self.checkbox_xonxoff.SetValue(self.serial.xonxoff)

        #Terminal settings
        self.checkbox_echo.SetValue(self.settings.echo)
        self.checkbox_unprintable.SetValue(self.settings.unprintable)
        self.radio_box_newline.SetSelection(self.settings.newline)

        #Bot settings
        self.radio_box_protocol.SetSelection(self.bot.protocols.index(self.bot.current_protocol))

        #attach the event handlers
        self.__attach_events()

        self.choice_robots.SetSelection(0)
Exemple #22
0
def rfid_receiver():
  global phone_sock, money_sock, rfid_serial, rfid_device, dispenser_device, \
         rfid_listener, rfid_sock, print_relogin_message
  while rfid_thread.running:

    # a real rfid scanner
    if settings.RFID_SCANNER == NORMAL:
      
      # setup serial device
      if settings.RFID_SCANNER_COMPORT: # if specified in settings, as it should be
        print "Waiting for RFID scanner"
        rfid_serial = get_serial(settings.RFID_SCANNER_COMPORT, 4,
                                 baudrate = 2400)
        rfid_device = settings.RFID_SCANNER_COMPORT
        
      else: # hopefully not used
        print "Scanning for RFID scanner"
        while not rfid_serial:
          for i in range(1, 10):
            try:
              device = serial.device(i)
              if device != dispenser_device:
                rfid_serial = serial.Serial(device)
                rfid_device = device
                break
            except serial.SerialException:
              continue

      if rfid_serial.baudrate != 2400:
        rfid_serial.close()
        rfid_serial.baudrate = 2400
        rfid_serial.open()
      
      print "Connected to RFID scanner"
    else: #emulated
      print "Waiting for RFID scanner emulator"
      rfid_sock, address = rfid_listener.accept()
      print "RFID Scanner emulator client connected from ", address
    
    while rfid_thread.running:

      if settings.RFID_SCANNER == NORMAL:
        try:
          rfid_serial.flushInput()
          rfid = rfid_serial.read(12).strip()
        except serial.SerialException:
          print "serial.SerialException"
          print "exiting"
          StopThreads()
          break
        
      else: # emulated
        try:
          rfid = rfid_sock.recv(500).strip()
          if len(rfid) == 0:
            break
        except:
          break

      #handle rfid tag
      if phone_sock:
        print "In 'if phone_sock'"
        if rfid == account_manager.rfid:
          if print_relogin_message:
            if account_manager.username == None:
              print "Trying to log in as None"
            else:
              print "Already logged in as " + account_manager.username
            print_relogin_message = False
          continue
        print "handle_rfid next line"
        handle_rfid(rfid)
      #else not connected to client
    print "Disconnected from RFID scanner."
    def __init__(self, *args, **kwds):
        #grab the serial keyword and remove it from the dict
        self.serial = kwds['serial']
        del kwds['serial']
        self.show = SHOW_ALL
        if 'show' in kwds:
            self.show = kwds['show']
            del kwds['show']
        # begin wxGlade: SerialConfigDialog.__init__
        # end wxGlade
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)
        self.label_2 = wx.StaticText(self, -1, "Port")
        self.combo_box_port = wx.ComboBox(self, -1, choices=["dummy1", "dummy2", "dummy3", "dummy4", "dummy5"], style=wx.CB_DROPDOWN)
        if self.show & SHOW_BAUDRATE:
            self.label_1 = wx.StaticText(self, -1, "Baudrate")
            self.choice_baudrate = wx.Choice(self, -1, choices=["choice 1"])
        if self.show & SHOW_FORMAT:
            self.label_3 = wx.StaticText(self, -1, "Data Bits")
            self.choice_databits = wx.Choice(self, -1, choices=["choice 1"])
            self.label_4 = wx.StaticText(self, -1, "Stop Bits")
            self.choice_stopbits = wx.Choice(self, -1, choices=["choice 1"])
            self.label_5 = wx.StaticText(self, -1, "Parity")
            self.choice_parity = wx.Choice(self, -1, choices=["choice 1"])
        if self.show & SHOW_TIMEOUT:
            self.checkbox_timeout = wx.CheckBox(self, -1, "Use Timeout")
            self.text_ctrl_timeout = wx.TextCtrl(self, -1, "")
            self.label_6 = wx.StaticText(self, -1, "seconds")
        if self.show & SHOW_FLOW:
            self.checkbox_rtscts = wx.CheckBox(self, -1, "RTS/CTS")
            self.checkbox_xonxoff = wx.CheckBox(self, -1, "Xon/Xoff")
        self.button_ok = wx.Button(self, -1, "OK")
        self.button_cancel = wx.Button(self, -1, "Cancel")

        self.__set_properties()
        self.__do_layout()
        #fill in ports and select current setting
        index = 0
        self.combo_box_port.Clear()
        for n in range(4):
            portname = serial.device(n)
            self.combo_box_port.Append(portname)
            if self.serial.portstr == portname:
                index = n
        if self.serial.portstr is not None:
            self.combo_box_port.SetValue(str(self.serial.portstr))
        else:
            self.combo_box_port.SetSelection(index)
        if self.show & SHOW_BAUDRATE:
            #fill in badrates and select current setting
            self.choice_baudrate.Clear()
            for n, baudrate in enumerate(self.serial.BAUDRATES):
                self.choice_baudrate.Append(str(baudrate))
                if self.serial.baudrate == baudrate:
                    index = n
            self.choice_baudrate.SetSelection(index)
        if self.show & SHOW_FORMAT:
            #fill in databits and select current setting
            self.choice_databits.Clear()
            for n, bytesize in enumerate(self.serial.BYTESIZES):
                self.choice_databits.Append(str(bytesize))
                if self.serial.bytesize == bytesize:
                    index = n
            self.choice_databits.SetSelection(index)
            #fill in stopbits and select current setting
            self.choice_stopbits.Clear()
            for n, stopbits in enumerate(self.serial.STOPBITS):
                self.choice_stopbits.Append(str(stopbits))
                if self.serial.stopbits == stopbits:
                    index = n
            self.choice_stopbits.SetSelection(index)
            #fill in parities and select current setting
            self.choice_parity.Clear()
            for n, parity in enumerate(self.serial.PARITIES):
                self.choice_parity.Append(str(serial.PARITY_NAMES[parity]))
                if self.serial.parity == parity:
                    index = n
            self.choice_parity.SetSelection(index)
        if self.show & SHOW_TIMEOUT:
            #set the timeout mode and value
            if self.serial.timeout is None:
                self.checkbox_timeout.SetValue(False)
                self.text_ctrl_timeout.Enable(False)
            else:
                self.checkbox_timeout.SetValue(True)
                self.text_ctrl_timeout.Enable(True)
                self.text_ctrl_timeout.SetValue(str(self.serial.timeout))
        if self.show & SHOW_FLOW:
            #set the rtscts mode
            self.checkbox_rtscts.SetValue(self.serial.rtscts)
            #set the rtscts mode
            self.checkbox_xonxoff.SetValue(self.serial.xonxoff)
        #attach the event handlers
        self.__attach_events()
    def __init__(self, *args, **kwds):
        # Configurações da serial
        self.serial = kwds['serial']
        del kwds['serial']

        # begin wxGlade: HTSerialConfig.__init__
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)
        self.sizerFluxo_staticbox = wx.StaticBox(self, -1, "Controle de Fluxo")
        self.porta = wx.Choice(self, -1, choices=[])
        self.velocidade = wx.Choice(self, -1, choices=[])
        self.dados = wx.Choice(self, -1, choices=[])
        self.paridade = wx.Choice(self, -1, choices=[])
        self.parada = wx.Choice(self, -1, choices=[])
        self.cfHardware = wx.CheckBox(self, -1, "RTS/CTS")
        self.cfSoftware = wx.CheckBox(self, -1, "Xon/Xoff")
        self.btCancelar = wx.Button(self, wx.ID_CANCEL, "")
        self.btOk = wx.Button(self, wx.ID_OK, "")

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.pressionouOK, id=wx.ID_OK)
        # end wxGlade

        # Porta
        self.porta.Clear()
        for n in range(4):
            self.porta.Append(serial.device(n))
        self.porta.SetSelection(self.serial.port)

        # Baud
        self.velocidade.Clear()
        for n, baudrate in enumerate(self.serial.BAUDRATES):
            self.velocidade.Append(str(baudrate))
            if self.serial.baudrate == baudrate:
                self.velocidade.SetSelection(n)

        # Dados
        self.dados.Clear()
        for n, dados in enumerate(self.serial.BYTESIZES):
            self.dados.Append(str(dados))
            if self.serial.bytesize == dados:
                self.dados.SetSelection(n)

        # Paridade
        self.paridade.Clear()
        NOMES = {'N': u'Nenhuma', 'O': u'Ímpar', 'E': u'Par'}
        for n,paridade in enumerate (self.serial.PARITIES):
            self.paridade.Append(NOMES[paridade])
            if self.serial.parity == paridade:
                self.paridade.SetSelection(n)

        # Parada
        self.parada.Clear()
        for n, parada in enumerate(self.serial.STOPBITS):
            self.parada.Append(str(parada))
            if self.serial.stopbits == parada:
                self.parada.SetSelection(n)

        # Controle de Fluxo
        self.cfHardware.SetValue (self.serial.rtscts);
        self.cfSoftware.SetValue (self.serial.xonxoff);
Exemple #25
0
def rfid_receiver():
  global phone_sock, money_sock, rfid_serial, rfid_device, dispenser_device, \
         rfid_listener, rfid_sock
  while True:

    # a real rfid scanner
    if settings.RFID_SCANNER == NORMAL:
      
      # setup serial device
      if settings.RFID_SCANNER_COMPORT: # if specified in settings, as it should be
        print "Waiting for RFID scanner"
        rfid_serial = get_serial(settings.RFID_SCANNER_COMPORT, 4,
                                 baudrate = 2400)
        rfid_device = settings.RFID_SCANNER_COMPORT
        
      else: # hopefully not used
        print "Scanning for RFID scanner"
        while not rfid_serial:
          for i in range(1, 10):
            try:
              device = serial.device(i)
              if device != dispenser_device:
                rfid_serial = serial.Serial(device)
                rfid_device = device
                break
            except serial.SerialException:
              continue

      if rfid_serial.baudrate != 2400:
        rfid_serial.close()
        rfid_serial.baudrate = 2400
        rfid_serial.open()
      
      print "Connected to RFID scanner"
    else: #emulated
      print "Waiting for RFID scanner emulator"
      rfid_sock, address = rfid_listener.accept()
      print "RFID Scanner emulator client connected from ", address
    
    while True:

      if settings.RFID_SCANNER == NORMAL:
        try:
          rfid_serial.flushInput()
          rfid = rfid_serial.read(12).strip()
        except serial.SerialException:
          break
        
      else: # emulated
        try:
          rfid = rfid_sock.recv(500).strip()
          if len(rfid) == 0:
            break
        except:
          break

      #handle rfid tag
      if phone_sock:
        if rfid == account_manager.rfid:
          if print_relogin_message:
            print "Already logged in as " + account_manager.username
            print_relogin_message = False
          continue
        if account_manager.log_in(rfid):
          print_relogin_message = True
          response  = {"type" : "log in",
                       "username" : account_manager.username,
                       "balance" : account_manager.balance}
          start_money()
          phone_sock.send(json.dumps(response)+"\n")
          print "Logged in as " + account_manager.username
          try:
            money_sock.send("enable\n")
          except:
            print "[ERROR] failed to enable the bill acceptor"
        #else invalid rfid tag, or currently logged in as guest
      #else not connected to client
    print "Disconnected from RFID scanner."