zanac / pyHPSU

Python Script to read and send commands to a Rotex HPSU
29 stars 21 forks source link

canpi.py - rendere retry configurabili #5

Open EmilianoMaina opened 7 years ago

EmilianoMaina commented 7 years ago

Estrapolare dal codice e rendere configurabili:

Grazie !

    while notTimeout:
        i += 1
        timeout = self.timeout
        rcBUS = None
        try:
            rcBUS = self.bus.recv(timeout)
        except Exception:
            self.hpsu.printd('exception', 'Error recv')                    

        if rcBUS:
            if (msg_data[2] == 0xfa and msg_data[3] == rcBUS.data[3] and msg_data[4] == rcBUS.data[4]) or (msg_data[2] != 0xfa and msg_data[2] == rcBUS.data[2]):
                rc = "%02X %02X %02X %02X %02X %02X %02X" % (rcBUS.data[0], rcBUS.data[1], rcBUS.data[2], rcBUS.data[3], rcBUS.data[4], rcBUS.data[5], rcBUS.data[6])
                notTimeout = False

        if notTimeout:
            self.hpsu.printd('warning', 'msg not sync, retry: %s' % i)
            **if i >= 15:**
                self.hpsu.printd('error', 'msg not sync, timeout')
                notTimeout = False
                rc = "KO"