Exemplo n.º 1
0
    def setUp(self):
        xl.OpenDriver()

        self.appName = bytes("pyxldrv".encode())
        self.appChannel = 0
        self.pHwType = [xl.XL_HWTYPE_VIRTUAL]
        self.pHwIndex = [0]
        self.pHwChannel = [0]
        self.busType = xl.XL_BUS_TYPE_CAN

        xl.SetApplConfig(self.appName, self.appChannel, self.pHwType,
                         self.pHwIndex, self.pHwChannel, self.busType)
        xl.GetApplConfig(self.appName, self.appChannel, self.pHwType,
                         self.pHwIndex, self.pHwChannel, self.busType)

        self.accessMask = xl.GetChannelMask(self.pHwType[0], self.pHwIndex[0],
                                            self.pHwChannel[0])

        self.portHandle = [0]
        self.permissionMask = [self.accessMask]
        self.rxQueueSize = 2 ^ 10
        self.xlInterfaceVersion = xl.XL_INTERFACE_VERSION
        xl.OpenPort(self.portHandle, self.appName, self.accessMask,
                    self.permissionMask, self.rxQueueSize,
                    self.xlInterfaceVersion, self.busType)
Exemplo n.º 2
0
    def test_opendriver_close_driver(self):
        print(inspect.getframeinfo(inspect.currentframe())[2])

        status = xl.OpenDriver()
        self.assertEqual(status, xl.XL_SUCCESS)

        status = xl.CloseDriver()
        self.assertEqual(status, xl.XL_SUCCESS)
Exemplo n.º 3
0
    def setUp(self):
        xl.OpenDriver()

        self.appName = bytes("pyxldrv".encode())
        self.appChannel = 0
        self.pHwType = [xl.XL_HWTYPE_VIRTUAL]
        self.pHwIndex = [0]
        self.pHwChannel = [0]
        self.busType = xl.XL_BUS_TYPE_CAN

        xl.SetApplConfig(self.appName, self.appChannel, self.pHwType,
                         self.pHwIndex, self.pHwChannel, self.busType)
        xl.GetApplConfig(self.appName, self.appChannel, self.pHwType,
                         self.pHwIndex, self.pHwChannel, self.busType)
Exemplo n.º 4
0
 def setUp(self):
     xl.OpenDriver()
Exemplo n.º 5
0
    def __init__(self,
                 *,
                 appName="pyxldrv",
                 appChannel=0,
                 HwType=xl.XL_HWTYPE_VIRTUAL,
                 HwIndex=0,
                 HwChannel=0,
                 rxQueueSize=2**10,
                 busType=xl.XL_BUS_TYPE_CAN,
                 flags=xl.XL_ACTIVATE_RESET_CLOCK,
                 queueLevel=1,
                 logger=logger):
        self.log = logger
        self.log.debug(
            f"[{self.__class__.__name__:8}][{self.__init__.__name__:8}] new instance.  appName:{appName}, appChannel:{appChannel}, HwType:{HwType}, HwIndex:{HwIndex}, HwChannel:{HwChannel}, rxQueueSize:{rxQueueSize}, busType:{busType}, flags:{flags}"
        )

        # set by param
        self.appName = appName
        self.pHwType = [HwType]
        self.pHwIndex = [HwIndex]
        self.pHwChannel = [HwChannel]
        self.busType = busType
        self.rxQueueSize = rxQueueSize
        self.flags = flags
        self.appChannel = appChannel
        self.queueLevel = queueLevel

        # internal use
        self.accessMask = 0
        self.portHandle = [0]
        self.permissionMask = [self.accessMask]
        self.xlInterfaceVersion = xl.XL_INTERFACE_VERSION
        self.xlHandle = [0]

        # internal use for error
        self.last_error = xl.XL_SUCCESS

        #
        # Setup Driver. see 4.2 Flowchart in "XL Driver Library - Description.pdf"
        #
        status = xl.OpenDriver()
        if status != xl.XL_SUCCESS:
            self.log.error(
                f"[{self.appName:8}][{self.__init__.__name__:8}] !! OpenDriver() returned {status} !!"
            )

        status = xl.SetApplConfig(bytes(self.appName.encode()),
                                  self.appChannel, self.pHwType, self.pHwIndex,
                                  self.pHwChannel, self.busType)
        if status != xl.XL_SUCCESS:
            self.log.debug(
                f"[{self.appName:8}][{self.__init__.__name__:8}] SetApplConfig returned {status}.  appName:{self.appName}, appChannel:{self.appChannel}, pHwType:{self.pHwType}, pHwIndex:{self.pHwIndex}, pHwChannel:{self.pHwChannel}, busType:{self.busType}"
            )

        status = xl.GetApplConfig(bytes(self.appName.encode()),
                                  self.appChannel, self.pHwType, self.pHwIndex,
                                  self.pHwChannel, self.busType)
        if status != xl.XL_SUCCESS:
            self.log.debug(
                f"[{self.appName:8}][{self.__init__.__name__:8}] GetApplConfig returned {status}.  appName:{self.appName}, appChannel:{self.appChannel}, pHwType:{self.pHwType}, pHwIndex:{self.pHwIndex}, pHwChannel:{self.pHwChannel}, busType:{self.busType}"
            )

        # accessMask should be OR(|=), if multi-HwChannels are used. (In this case, OR(|=) has little meaning.)
        self.accessMask |= xl.GetChannelMask(self.pHwType[0], self.pHwIndex[0],
                                             self.pHwChannel[0])
        if self.accessMask == 0:
            self.log.error(
                f"[{self.appName:8}][{self.__init__.__name__:8}]!! GetChannelMask returned accessMask={self.accessMask}!!  pHwType:{self.pHwType}, pHwIndex:{self.pHwIndex}, pHwChannel:{self.pHwChannel}"
            )

        # permissionMask should be same as accessMask at when OpenPort timing.
        self.permissionMask = [self.accessMask]
        status = xl.OpenPort(self.portHandle, bytes(self.appName.encode()),
                             self.accessMask, self.permissionMask,
                             self.rxQueueSize, self.xlInterfaceVersion,
                             self.busType)
        if status != xl.XL_SUCCESS:
            self.log.error(
                f"[{self.appName:8}][{self.__init__.__name__:8}]!! OpenPort returned {status} !!  portHandle:{self.portHandle}, appName:{self.appName}, accessMask:{self.accessMask}, permissionMask:{self.permissionMask}, rxQueueSize:{self.rxQueueSize}, xlInterfaceVersion:{self.xlInterfaceVersion}, busType:{self.busType}"
            )

        # check permissionMask for logging. see 3.2.9 xlOpenPort in "XL Driver Library - Description.pdf"
        if self.permissionMask[0] == 0:
            self.log.debug(
                f"[{self.appName:8}][{self.__init__.__name__:8}] permissionMask({self.permissionMask[0]}) is 0. If this is not init access for CANs, this is no issue."
            )

        # check portHandle for logging.
        if self.portHandle[0] == xl.XL_INVALID_PORTHANDLE:
            self.log.error(
                f"[{self.appName:8}][{self.__init__.__name__:8}]!! portHandle({self.portHandle[0]}) is XL_INVALID_PORTHANDLE !!"
            )

        status = xl.ActivateChannel(self.portHandle[0], self.accessMask,
                                    self.busType, self.flags)
        if status != xl.XL_SUCCESS:
            self.log.debug(
                f"[{self.appName:8}][{self.__init__.__name__:8}] ActivateChannel returned {status}.  portHandle:{self.portHandle}, accessMask:{self.accessMask}, busType:{self.busType}, flags:{self.flags}"
            )

        status = xl.SetNotification(self.portHandle[0], self.xlHandle,
                                    self.queueLevel)
        if status != xl.XL_SUCCESS:
            self.log.debug(
                f"[{self.appName:8}][{self.__init__.__name__:8}] SetNotification returned {status}.  portHandle:{self.portHandle}, xlHandle:{self.xlHandle}, queueLevel:{self.queueLevel}"
            )