Page 1 of 1

Multiple USB-IRTs using USB-IRTJ

PostPosted: Thu Feb 14, 2008 8:40 pm
by tomgiam
Has anybody modified the USB-IRTJ java code to connect multiple USB-IRTs?

I need to do that and would welcome any help or suggestions.

This is the information I received from Jon Rhees:

"You will need to make the appropriate changes to the java wrapper to support this. Supporting multiple USB-UIRT's involves two things: a) renaming the USB-UIRT's to unique ID numbers, and b) using the OpenEX() function which allows the unique names to be specified and obtaining a different handle to each USB-UIRT. If the java wrapper currently stores the handle obtained from Open() internally, then you will likely need to change the wrapper's API to expose the handle up to your app."

Thanks
Tom

PostPosted: Fri Feb 15, 2008 1:57 pm
by avalanche333
This should help:

http://65.36.202.170/phpBB2/viewtopic.p ... db47a17532


I have tried to to this same thing but after adding in the OpenEx function I am still getting a handle to all connected UIRT blasters even though I specify the name of the one I want to blast to. But try it out and let me know if it works for you, I may just be doing something wrong. I'll be posting about this issue in a minute and see if anyone know's whats going on.

Thanks,

PostPosted: Fri Feb 15, 2008 3:04 pm
by tomgiam
Here is some more information that I received from Peter Ghosh, who wrote the USB-UIRTJ code:

"The handle is stored locally internally in util_USBUIRT.cpp on line 79 and declared on line 20 and is used in each of the action methods.
This will have to be modified to allow for multiple devices. One approach would be to return the handle from the open method and then
pass it to each of the methods that need it. Or store it in the cpp itself and reference them by some index. I think the index might
work better (you're serializing the handle from C to Java with each call)."

Tom

PostPosted: Fri Feb 15, 2008 3:51 pm
by avalanche333
Whoops I did not notice you are using different files then me. I am using uuirtdrv.h and uuirtdrv_wrap.h

Currently I am getting the handle then using it...

Code: Select all
JNIEXPORT jboolean JNICALL Java_com_tvworks_tools_PersonalKeyserver_IR_USBUIRTCommunicator_transmitIREx( JNIEnv *env, jobject obj, jstring irCode, jstring deviceName )
{
   jboolean      retVal= JNI_FALSE;
   if (hinstLib != NULL)
   {
      /* Convert to a usable C string */
      char *pIRCode = (char*) (*env).GetStringUTFChars( irCode, 0 );
      char *pDeviceName = (char*) (*env).GetStringUTFChars( deviceName, 0 );
      if( pIRCode != NULL ) {
         HUUHANDLE handle = fnUUIRTOpenEx(pDeviceName, 0, NULL, NULL);
         BOOL bTransmitOK = fn_UUIRTTransmitIR(handle, pIRCode, UUIRTDRV_IRFMT_PRONTO, 1, 0, NULL, NULL, NULL);
         if (bTransmitOK) {
            retVal = JNI_TRUE;                                                 
         }
         fnUUIRTClose(handle);
      }                                                                           

      /* Free as a bird.... */                                               
      (*env).ReleaseStringUTFChars( irCode, pIRCode );
      (*env).ReleaseStringUTFChars( deviceName, pDeviceName);
   }                                                                             
   return retVal;                                                               
}
[/code]

PostPosted: Fri Feb 15, 2008 4:06 pm
by avalanche333
My bad, this does actually work. Because the IR blasters were so close to each other, one blaster was picking up the signal of the other and flashing. Once I moved them far enough apart I could see it working properly.

PostPosted: Fri Feb 15, 2008 4:31 pm
by tomgiam
You must be using different code then USB-UIRTJ since I don't have the uuirtdrv_wrap.h file you mentioned. The code in util_USBUIRT.cpp looks like this:

Code: Select all
JNIEXPORT jboolean JNICALL Java_util_USBUIRT_open
  (JNIEnv *je, jclass jc){
    hDrvHandle = fnUUIRTOpen();
   if (hDrvHandle == INVALID_HANDLE_VALUE){
      DWORD err = GetLastError();
      jclass cl = je->FindClass("util/USBUIRT$UIRTException");
      if (err == UUIRTDRV_ERR_NO_DLL)
         cl = je->FindClass("util/USBUIRT$NoDLLException");
      else if (err == UUIRTDRV_ERR_NO_DEVICE)
         cl = je->FindClass("util/USBUIRT$NoDeviceException");
      else if (err == UUIRTDRV_ERR_NO_RESP)
         cl = je->FindClass("util/USBUIRT$NoResponseException");
      else if (err == UUIRTDRV_ERR_VERSION)
         cl = je->FindClass("util/USBUIRT$VersionException");
      hDrvHandle = NULL;
      je->ThrowNew(cl, "");
      return FALSE;
   }
   fn_UUIRTSetReceiveCallback(hDrvHandle, &IRReceiveCallback, (void *)0xA5A5A5A5);
    return TRUE;
}


Your code looks like it should work. If you'r always getting a handle that points to the same device irregardless of the device name then it may be either a configuration issue or a question for Jon Rhees or someone that has working code in C, C++, VB or C# with multiple USB-UIRT devices.


Tom