New topic: 

IOKit question

<http://forums.realsoftware.com/viewtopic.php?t=30619>

       Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic         Author  
Message       trs           Post subject: IOKit questionPosted: Fri Oct 23, 
2009 7:19 am                        
Joined: Thu May 03, 2007 2:33 pm
Posts: 7              Hi

Any help greatly appreciated. I am working to a deadline and after hours of 
searching google I have hit a brick wall.

I am attempting to hook up to a USB device (a plotter) for which there is no 
Mac OS X driver.

Running the USBSimple XCode example project I am able to detect the plotter and 
successfully send data to it.

I am therefore attempting to port the USBSimple code to RealBasic. 
Unfortunately my ported code trips up early on, appearing to receive an 
incorrect value from IOIteratorNext;

Here is a snippet from the working code I am trying to port:
Code:
err = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator);
matchingDictionary = 0;   // this was consumed by the above call

while ( (usbDeviceRef = IOIteratorNext(iterator)) )
  {
  printf("Found device %d\n", usbDeviceRef);  // When plotter is connected, 
this prints 4355
  dealWithDevice(usbDeviceRef);
  IOObjectRelease(usbDeviceRef);   // no longer need this reference
  }
  
  IOObjectRelease(iterator);
  iterator = 0;
  



Here is the same snippet from my RealBasic port, which as yet does not work:
  Code:
declare function IOServiceGetMatchingServices lib IOKit (masterPort as 
integer,matchingDictionary as integer,byRef iterator as integer) as integer
declare function IOIteratorNext lib IOKit (iterator as integer) as integer
declare sub IOObjectRelease lib IOKit (obj as integer)

dim iterator as integer
err=IOServiceGetMatchingServices(masterPort,matchingDictionary,iterator)
matchingDictionary=0 // this was consumed by the above call

dim usbDeviceRef as integer
do
  usbDeviceRef=IOIteratorNext(iterator)
  if usbDeviceRef<>0 then
  msgbox"Found device "+str(usbdeviceRef)  // when plotter is connected, this 
prints (approx) 17000
  DealWithDevice usbDeviceRef
  IOObjectRelease usbDeviceRef
  end if
loop until usbDeviceRef=0
IOObjectRelease iterator
iterator=0



In the XCode program, IOIteratorNext returns 0 if the plotter is not connected, 
and 4355 if connected. It is the same every run.

In my RealBasic code, IOIteratorNext returns 0 if the plotter is not connected 
(correct), and an apparently arbitrary value (normally approx 16-17000) when 
the plotter is connected.

Inside DealWithDevice, the value of usbDevice is passed to 
IOCreatePlugInInterfaceForService which comes back with an error.

If it's any help, the relevant declarations in IOKitLib.h are:
Code:
io_object_t
IOIteratorNext(
io_iterator_t iterator );

kern_return_t
IOServiceGetMatchingServices(
mach_port_t masterPort,
CFDictionaryRef matching,
io_iterator_t * existing );



Perhaps I am specifying something wrongly in one of the declare function lines?

I uploaded the full code in question in case it helps:
USBSimple (the XCode code which works): 
http://www.aspexsoftware.com/codesample/main.c
RealBasic port of this code so far: 
http://www.aspexsoftware.com/codesample/USBMac.rbp

Can anyone shed any light on this?

Thank you

Tom   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to