# Path: basil/TL/TransferLayer.py
# class TransferLayer(Base):
#     '''Transfer Layer implements minimum API needed access to hardware.
#     On error ``raise IOError``.
#     '''
# 
#     def __init__(self, conf):
#         super(TransferLayer, self).__init__(conf)
# 
#     def init(self):
#         '''Initialize and connect to hardware.
#         '''
#         super(TransferLayer, self).init()
# 
#     def read(self):
#         '''Read access.
# 
#         :rtype: None
#         '''
#         raise NotImplementedError("read() not implemented")
# 
#     def write(self, data):
#         '''Write access.
# 
#         :param data: array/list of bytes
#         :type data: iterable
#         :rtype: None
# 
#         '''
#         raise NotImplementedError("write() not implemented")


import logging
import array
import serial
from struct import pack
from time import sleep
from basil.TL.TransferLayer import TransferLayer
logger = logging.getLogger(__name__)


class SiUart(TransferLayer):
    _ser = None

    def __init__(self, conf):
        super(SiUart, self).__init__(conf)

    def init(self):
        super(SiUart, self).init()
        self._init.setdefault('board_id', None)
        self._init.setdefault('avoid_download', False)
        if self._init['board_id'] and int(self._init['board_id']) >= 0:
            self._ser = serial.Serial()
            if 'port' in self._init.keys():
                self._ser.setPort(self._init['port'])
            if 'baudrate' in self._init.keys():
                self._ser.setBaudrate(self._init['baudrate'])
            if 'parity' in self._init.keys() and self._init["parity"] == 0:
                self._ser.setParity(serial.PARITY_NONE)
            if 'stopbits' in self._init.keys():
                self._ser.setStopbits(self._init['stopbits'])
            if 'bytesize' in self._init.keys():
                self._ser.setByteSize(self._init['bytesize'])
            if 'timeout' in self._init.keys():
                self._ser.setTimeout(self._init['timeout'])

            self._ser.open()
            if not self._ser.isOpen():

# Path: basil/TL/TransferLayer.py
# class TransferLayer(Base):
#     '''Transfer Layer implements minimum API needed access to hardware.
#     On error ``raise IOError``.
#     '''
# 
#     def __init__(self, conf):
#         super(TransferLayer, self).__init__(conf)
# 
#     def init(self):
#         '''Initialize and connect to hardware.
#         '''
#         super(TransferLayer, self).init()
# 
#     def read(self):
#         '''Read access.
# 
#         :rtype: None
#         '''
#         raise NotImplementedError("read() not implemented")
# 
#     def write(self, data):
#         '''Write access.
# 
#         :param data: array/list of bytes
#         :type data: iterable
#         :rtype: None
# 
#         '''
#         raise NotImplementedError("write() not implemented")


# Path: basil/TL/SiUart.py
import logging
import array
import serial
from struct import pack
from time import sleep
from basil.TL.TransferLayer import TransferLayer

logger = logging.getLogger(__name__)


class SiUart(TransferLayer):
    _ser = None

    def __init__(self, conf):
        super(SiUart, self).__init__(conf)

    def init(self):
        super(SiUart, self).init()
        self._init.setdefault('board_id', None)
        self._init.setdefault('avoid_download', False)
        if self._init['board_id'] and int(self._init['board_id']) >= 0:
            self._ser = serial.Serial()
            if 'port' in self._init.keys():
                self._ser.setPort(self._init['port'])
            if 'baudrate' in self._init.keys():
                self._ser.setBaudrate(self._init['baudrate'])
            if 'parity' in self._init.keys() and self._init["parity"] == 0:
                self._ser.setParity(serial.PARITY_NONE)
            if 'stopbits' in self._init.keys():
                self._ser.setStopbits(self._init['stopbits'])
            if 'bytesize' in self._init.keys():
                self._ser.setByteSize(self._init['bytesize'])
            if 'timeout' in self._init.keys():
                self._ser.setTimeout(self._init['timeout'])

            self._ser.open()
            if not self._ser.isOpen():

                raise IOError("Port at %s not open" % self._ser.port)