# Path: pyilper/pilrs232.py
# class Rs232Error(Exception):
#    def __init__(self,value):
#       self.value=value
#    def __str__(self):
#       return repr(self.value)
# 
# class cls_rs232:
#  
#    def __init__(self,parent=None):
#       self.__device__= None
#       self.__isOpen__= False
#       self.__timeout__=0
# 
# #
# #  Windows needs much time to reconfigure the timeout value of the serial
# #  device, so alter the device settings only if necessary. Give the device
# #  some time to settle.
# #
#    def __settimeout__(self,timeout):
#       if timeout != self.__timeout__:
#          try:
#             self.__ser__.timeout= timeout
#          except:
#             raise Rs232Error('cannot set timeout value of serial device')
#          self.__timeout__=timeout
# 
#    def isOpen(self):
#       return self.__isOpen__
# 
# 
#    def open(self,device,baudrate):
# #
# #     use Windows device naming (hint by cg)
# #
#       if isWINDOWS():
#          self.__device__="\\\\.\\"+device
#       else:
#          self.__device__= device
# 
#       self.__device__= device
#       try:
#          self.__ser__= serial.Serial(port=device,baudrate=baudrate,timeout=0.10)
#          self.__isOpen__= True
#          time.sleep(0.5)
#       except:
#           self.__device__=""
#           raise Rs232Error('cannot open serial device')
#    def close(self):
#       try:
#          self.__ser__.close()
#          self.__isOpen__=False
#       except:
#          raise Rs232Error('cannot close serial device')
#       self.__device__=""
# 
#    def snd(self,buf):
#       try:
#          self.__ser__.write(buf)
#       except:
#          raise Rs232Error('cannot write to serial device')
# 
#    def rcv(self,timeout):
#       self.__settimeout__(timeout)
#       try:
#          c= self.__ser__.read(1)
#       except:
#          raise Rs232Error('cannot read from serial device')
#       return c
# 
#    def flushInput(self):
#       try:
#          self.__ser__.flushInput()
#       except:
#          raise Rs232Error('cannot reset serial device')
# 
#    def setBaudrate(self,baudrate):
#       try:
#          self.__ser__.baudrate= baudrate
#       except:
#          raise Rs232Error('cannot set baudrate')


from .pilrs232 import Rs232Error, cls_rs232
from .pilcore import *
# 13.10.2016 jsi
# - remove unregister function
# - store tab name if device is registered
# 30.10.2016 jsi
# - getDevices added (removed by mistake)
# 07.10.2017 jsi
# - refactoring: moved process(), sendFrame() and device list handling code to
#   thread object
#
# PIL-Box Commands
#
COFF= 0x497   # initialize in controller off mode
TDIS= 0x494   # disconnect
COFI= 0x495   # switch PIL-Box to transmit real IDY frames


class PilBoxError(Exception):
   def __init__(self,msg,add_msg=None):
      self.msg=msg
      if add_msg is None:
         self.add_msg=""
      else:
         self.add_msg= add_msg


class cls_pilbox:

   def __init__(self,ttydevice,baudrate,idyframe):
      self.__baudrate__= baudrate  # baudrate of connection or 0 for autodetect
      self.__idyframe__= idyframe  # switch box to send idy frames

# Path: pyilper/pilrs232.py
# class Rs232Error(Exception):
#    def __init__(self,value):
#       self.value=value
#    def __str__(self):
#       return repr(self.value)
# 
# class cls_rs232:
#  
#    def __init__(self,parent=None):
#       self.__device__= None
#       self.__isOpen__= False
#       self.__timeout__=0
# 
# #
# #  Windows needs much time to reconfigure the timeout value of the serial
# #  device, so alter the device settings only if necessary. Give the device
# #  some time to settle.
# #
#    def __settimeout__(self,timeout):
#       if timeout != self.__timeout__:
#          try:
#             self.__ser__.timeout= timeout
#          except:
#             raise Rs232Error('cannot set timeout value of serial device')
#          self.__timeout__=timeout
# 
#    def isOpen(self):
#       return self.__isOpen__
# 
# 
#    def open(self,device,baudrate):
# #
# #     use Windows device naming (hint by cg)
# #
#       if isWINDOWS():
#          self.__device__="\\\\.\\"+device
#       else:
#          self.__device__= device
# 
#       self.__device__= device
#       try:
#          self.__ser__= serial.Serial(port=device,baudrate=baudrate,timeout=0.10)
#          self.__isOpen__= True
#          time.sleep(0.5)
#       except:
#           self.__device__=""
#           raise Rs232Error('cannot open serial device')
#    def close(self):
#       try:
#          self.__ser__.close()
#          self.__isOpen__=False
#       except:
#          raise Rs232Error('cannot close serial device')
#       self.__device__=""
# 
#    def snd(self,buf):
#       try:
#          self.__ser__.write(buf)
#       except:
#          raise Rs232Error('cannot write to serial device')
# 
#    def rcv(self,timeout):
#       self.__settimeout__(timeout)
#       try:
#          c= self.__ser__.read(1)
#       except:
#          raise Rs232Error('cannot read from serial device')
#       return c
# 
#    def flushInput(self):
#       try:
#          self.__ser__.flushInput()
#       except:
#          raise Rs232Error('cannot reset serial device')
# 
#    def setBaudrate(self,baudrate):
#       try:
#          self.__ser__.baudrate= baudrate
#       except:
#          raise Rs232Error('cannot set baudrate')


# Path: pyilper/pilbox.py
from .pilrs232 import Rs232Error, cls_rs232
from .pilcore import *

# 13.10.2016 jsi
# - remove unregister function
# - store tab name if device is registered
# 30.10.2016 jsi
# - getDevices added (removed by mistake)
# 07.10.2017 jsi
# - refactoring: moved process(), sendFrame() and device list handling code to
#   thread object
#
# PIL-Box Commands
#
COFF= 0x497   # initialize in controller off mode
TDIS= 0x494   # disconnect
COFI= 0x495   # switch PIL-Box to transmit real IDY frames


class PilBoxError(Exception):
   def __init__(self,msg,add_msg=None):
      self.msg=msg
      if add_msg is None:
         self.add_msg=""
      else:
         self.add_msg= add_msg


class cls_pilbox:

   def __init__(self,ttydevice,baudrate,idyframe):
      self.__baudrate__= baudrate  # baudrate of connection or 0 for autodetect
      self.__idyframe__= idyframe  # switch box to send idy frames

      self.__tty__= cls_rs232()    # serial device object