Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

USB-UIRT: proposal to introduce retries

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

USB-UIRT: proposal to introduce retries

Post by krambriw »

I have a problem when multiple threads are hitting the USB-UIRT at the same time. The following code (in the class TransmitIR) is a proposal to change the plug-in and to introduce handling of retries.

I have noticed that it seems to work (got already several entries in log due to retries) as I expected

Best regards, Walter

Code: Select all


    def __call__(self, code='', repeatCount=4, inactivityWaitTime=0):
        if not self.plugin.dll:
            print "dll"
            raise self.Exceptions.DeviceNotReady
        if len(code) > 5:
            start = 0
            if code[0] == "Z":
                start = 2
            if code[start+3] == "R":
                codeFormat = UUIRTDRV_IRFMT_UUIRT
            elif code[start+4] == " ":
                codeFormat = UUIRTDRV_IRFMT_PRONTO
            else:
                codeFormat = UUIRTDRV_IRFMT_LEARN_FORCESTRUC
        else:
            repeatCount = 0
            codeFormat = UUIRTDRV_IRFMT_PRONTO
            code = ""
            

### Modified by Walter Kraembring. Introduced retries
        bSuccess = False

        for i in range(0,3):
            if i>0:
               print "USB-UIRT retries: ", i
               time.sleep(0.5)
            if self.plugin.dll.UUIRTTransmitIR(
                self.plugin.hDrvHandle,    # hHandle
                c_char_p(code),     # IRCode
                codeFormat,         # codeFormat
                repeatCount,        # repeatCount
                inactivityWaitTime, # inactivityWaitTime
                0,                  # hEvent
                0,                  # reserved1
                0                   # reserved2
            ):
                bSuccess = True
                break            

        if not bSuccess:
            raise self.Exceptions.DeviceNotReady
### End modification        
        

Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Re: USB-UIRT: proposal to introduce retries

Post by Bartman »

How do you use the USB-UIRT from multiple threads?
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: USB-UIRT: proposal to introduce retries

Post by krambriw »

I use my Scheduler and SunTracker and there I have multiple threads running that creates events. Many times they are issuing events that activates the USB-UIRT for transmission. If those are with too little delay, they wont be accepted.

A little "for loop" with retries has showed that it now works on the first or second retry

Best regards, Walter
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: USB-UIRT: proposal to introduce retries

Post by krambriw »

Here is a sample from my eg log that shows the difference, with and without the above code change

Without the code change (original)

Code: Select all

23:27:01         USB-UIRT: Transmit IR
23:27:02            Device is not ready!
23:27:02   Main.SB_Bathroom_ON
23:27:03      B1_ON USB-UIRT: Transmit IR
23:27:03         USB-UIRT: Transmit IR
23:27:03   Main.Garage ON
23:27:03      B13_ON USB-UIRT: Transmit IR
23:27:03         USB-UIRT: Transmit IR
With the code modification as proposed

Code: Select all

00:57:04   Main.SB_Kitchen_ON
00:57:04      A3_ON USB-UIRT: Transmit IR
00:57:04         USB-UIRT: Transmit IR
00:57:04   Main.SB_Bathroom_ON
00:57:04      B1_ON USB-UIRT: Transmit IR
00:57:04         USB-UIRT: Transmit IR
00:57:06   Main.SB_Kitchen_ON
00:57:06      A3_ON USB-UIRT: Transmit IR
00:57:06         USB-UIRT: Transmit IR
00:57:06            USB-UIRT retries:  1
00:57:07            USB-UIRT retries:  2
00:57:09   Main.SB_Bathroom_ON
00:57:09      B1_ON USB-UIRT: Transmit IR
00:57:09         USB-UIRT: Transmit IR
00:57:09            USB-UIRT retries:  1
00:57:10            USB-UIRT retries:  2
00:57:11   Main.SB_Kitchen_ON
00:57:11      A3_ON USB-UIRT: Transmit IR
00:57:11         USB-UIRT: Transmit IR
00:57:13   Main.SB_Bathroom_ON
00:57:13      B1_ON USB-UIRT: Transmit IR
00:57:13         USB-UIRT: Transmit IR
00:57:13            USB-UIRT retries:  1
00:57:14            USB-UIRT retries:  2
Post Reply