IOWarriorLib.h
Discussion
The IOWarrior Library provides convinience funtions to access the IOWarrior under Mac OS X 10.2.3 or later. It simplifies the process of finding and accessing IOWarrior devices .
You will need to link your software against the IOKit.framework in order to use this source code.
Make sure you are calling IOWarriorInit before calling any of the other functions.
If you are running Mac OS X 10.2.3, make sure you have updated your Developer Tools at least to the December 2002 version.
Binaries compiled on Mac OS X 10.3 using this version of the IOWarrior Library will not work on earlier systems. However, binaries on 10.2.3 should also work on 10.2.3 or later. If you are using 10.3 and want to develop appplicaton that run on 10.2.x, too, select the 10.2.7 Cross Development SDK in XCode targets inspector. You have to install the additional SDK when installing the Mac OS X Developer Tools.
$Id: IOWarriorLib.h,v 1.2 2003/11/19 19:57:54 ilja Exp $
Functions
Returns the number of interfaces connected to this system.
Result: The number of IOWarrior interfaces.
int IOWarriorCountInterfaces (void);
Returns the first IOWarrior interface of type inInterfaceType.
Parameters
Name | Description |
inInterfaceType | The type of the interface to be returned. |
Result: Returns an interface object if found, NULL otherwise.
IOWarriorHIDDeviceInterface** IOWarriorFirstInterfaceOfType (
int inInterfaceType
);
Use this function to get the first discovered interface of a certain type. See the Constants definitions for a list of supported IOWarrior interface types. The result of this function can be used as paramter for IOWarriorWriteToInterface or IOWarriorReadFromInterface. Returns NULL if no interface matching inInterfaceType could be found.
Initializes the IOWarrior library. Call this before calling any other functions.
Result: Returns 0 if successfull, otherwise return value is different from 0.
int IOWarriorInit (void);
Returns the list node element at index inIndex.
Parameters
Name | Description |
inIndex | The index of the desired list node. First list node has index 0. |
Result: A pointer to a structure of type IOWarriorListNode. NULL if index is out of bounds.
IOWarriorListNode* IOWarriorInterfaceListNodeAtIndex (
int inIndex
);
Use this function to obtain more information (serial number, device type) about an interface of an IOWarrior device.
Use this function to too see of an IOWarrior device is present.
Result: Returns 1 if at least one IOWarrior is connected to this system. Returns 0 if no IOWarrior device could be discovered.
int IOWarriorIsPresent (void);
Reads data from a specific interface.
Parameters
Name | Description |
inInterface | The interface the data should be read from. Pass the ioWarriorHIDInterface member of an IOWarriorListNode struct. This function will not get you the data sent in interrupt mode from interface 1. Instead you will receive a copy of the last HID report sent in interrupt mode. Use IOWarriorSetInterruptCallback to receive data received in interrupt mode. |
inReportID | The report ID of the request. See the IO Warrior Datasheet for the appropriate values. |
inSize | The size of the data to be read. |
inData | A pointer to a buffer thats at least inSize bytes long. Read data will be stored here. |
Result: Returns 0 if read operation was successful, returns an error code different from 0 otherwise.
int IOWarriorReadFromInterface (
IOWarriorHIDDeviceInterface** inInterface,
int inReportID,
int inSize,
void* outData
);
Use this function to read a certain amount of data associated with a certain reportID to a specific interface.
Reads 4 byte (32 bit) from interface 0 of the first IOWarrior 40 device connected to this system using a GetOutputReport request.
Parameters
Name | Description |
outData | A pointer to a buffer where the data should be stored. Buffer has to be at least 4 bytes long |
Result: Returns 0 if reading operation was successfull. Returns a value different from 0 otherwise.
int IOWarriorReadInterface0 (
void *outData
);
Reads a 7 byte output report from interface 1 of the first IOWarrior 40 device connected to this system.
This function won't work for interfaces 1 of an IOWarrior 40 on Mac OS X 10.2.x.
Parameters
Name | Description |
inReportID | The report ID of the request. See the IO Warrior Datasheet for the appropriate values. |
outData | A pointer to a buffer where the data should be stored. Buffer has to be at least 7 bytes long |
Result: Returns 0 if reading operation was successfull. Returns a value different from 0 otherwise.
int IOWarriorReadInterface1 (
int inReportID,
void *outData
);
Use this function to obtain data from the IOWarrior when in special mode. See the IOWarrior datasheet for details.
Sets the function to be called when IOWarrior devices ar added or removed.
void IOWarriorSetDeviceCallback (
IOWarriorDeviceCallbackFunctionPtr inCallbackPtr,
void* inRefCon
);
Use this function to install a custom callback function. You function will be called whenever IOWarrior devices are added or removed from the system. You should invalidate any references to IOWarriorListNode structures you might have saved when your callback functions gets called. Be sure to call IOWarriorCountInterfaces at least once after you callback function was invoked before calling any other functions from the IOWarrior Library.
Sets the function to be called when a report data is received on inInterface.
Parameters
Name | Description |
inInterface | The interface where your data arrives |
inBuffer | A buffer provided by the caller. |
inBufferSize | The size of inBuffer. |
inCallbackPtr | A pointer to your callback function. See IOHIDLib.h for more info. |
inRefCon | A reference value passed to your callback on invocation. |
int IOWarriorSetInterruptCallback (
IOWarriorHIDDeviceInterface** inInterface,
void* inBuffer,
UInt32 inBufferSize,
IOHIDReportCallbackFunction inCallbackPtr,
void* inRefCon
);
Use this function to install a custom callback routine that gets invoked when data is received on interface inInterface. This function will only work when your application was compiled on Mac OS 10.3 or later and is running on Mac OS 10.3 or later. For earlier systems the implementation of the function is hidden from the compiler using preprocessor commands, because the system does not implement the required API calls.
Writes a 4 byte buffer (32 bit) to interface 0 of the first IOWarrior 40 devices using a SetOutputReport request.
Parameters
Name | Description |
inData | A pointer to the data being written. Should be at least 4 bytes long. |
Result: Returns 0 if writing operation was successfull. Returns a value different from 0 otherwise.
int IOWarriorWriteInterface0 (
void *inData
);
The first byte of the passed buffer becomes mapped to the pins of port 0, the second byte to the pins of port 1 and so on.
Writes a 7 byte output report to interface 1 of the first IOWarrior 40 device connected to this system.
Parameters
Name | Description |
inReportID | The report ID of the request. See the IO Warrior Datasheet for the appropriate values. |
inData | A pointer to the data being written. Should be at least 7 bytes long. |
Result: Returns 0 if writing operation was successfull. Returns a value different from 0 otherwise.
int IOWarriorWriteInterface1 (
int inReportID,
void *inData
);
Use the function to control IOWarrior special modes (like IIC and LCD mode) of the IOWarrior. See the IOWarrior datasheet for details.
Writes data to a specific interface.
Parameters
Name | Description |
inInterface | The interface the data should be written to. Pass the ioWarriorHIDInterface member of an IOWarriorListNode struct obtained earlier. |
inSize | The size of the data to be written. |
inData | A pointer to the data to be written. First byte is report id. |
Result: Returns 0 if write operation was successful, returns an error code different from 0 otherwise.
int IOWarriorWriteToInterface (
IOWarriorHIDDeviceInterface** inInterface,
int inSize,
void* inData
);
Use this function to write to a certain amount of data associated with a certain reportID to a specific interface.
Typedefs
A function pointer type for IOWarriors callback function.
typedef void (*IOWarriorDeviceCallbackFunctionPtr) (
void* inRefCon
);
A function pointer type for IOWarriors callback function, that gets called whenever an IOWarrior device is added or removed. You can install you own callback function using the IOWarriorSetCallback fucntion.
Structs
IONotificationPortRef GetNotificationPort ();
struct IOWarriorListNodeStruct {
IONotificationPortRef GetNotificationPort ();
struct IOWarriorListNodeStruct
IOWarriorHIDDeviceInterface** ioWarriorHIDInterface; // IOKits interface object
struct IOWarriorListNodeStruct* nextNode; // pointer to the next interface
int serialNumber; // the device serial number
int interfaceType; // the type of the interface
;
} ;
A structure implementing a linked list node. Used to keep track of all IOWarrior Interfaces
connected to the system. You can use IOWarriorCountInterfaces and IOWarriorInterfaceListNodeAtIndex to iterate trough all interfaces.
Fields
Name | Description |
ioWarriorHIDInterface | Interface object for the systems IOKit |
nextNode | Pointer to the node in the interface list. |
serialNumber | The serial number of the interface. |
interfaceType | The type of the interface (kIOWarrior40Interface0, kIOWarrior40Interface1, ..) . |
#defines
#define kIOWarrior24Interface0 2
Interface type indentifier for an interface 0 of an IOWarrior 24.
#define kIOWarrior24Interface1 3
Interface type indentifier for an interface 0 of an IOWarrior 24.
#define kIOWarrior40Interface0 0
Interface type indentifier for an interface 0 of an IOWarrior 40.
#define kIOWarrior40Interface1 1
Interface type indentifier for an interface 1 of an IOWarrior 40.
(Last Updated 11/28/2003)