Device Create Functions

You can use a datapoint create callback function to respond to a device create request from IDL to a custom driver.  A device create request originates from an IAP/MQ device create request to a custom driver.  The IAP/MQ device create request is typically the result of a device create request from an IAP/MQ client.  In response to an IAP/MQ device create request to IDL, IDL call the OnDevCreate callback function that was registered during the custom driver init process.

Device Create Callback Function

OnDevCreate

IdlErrorCodes OnDevCreate(int callback_index, IdlDev *dev, char *args, char *xif_dp_array);

callback_index is a callback identifier used by IDL.  The custom driver must pass it back to IDL when calling IdlDevCreateResult.

dev is the IDL device object for the device to be created.  The custom driver must pass it back to ID when calling IdlDevCreateResult.

args is the stringifiedargs” JSON object that is received in the IAP/MQ device create request, which contains some or all the following fields:

  • unid  the unique ID of the device to be created.  The custom driver must verify the unique ID for correctness and uniqueness.  For example, in Modbus RTU the following identifiers all represent the same unique ID: "01:05”, "1:05", and “01:5”.
  • type  the program ID of the device to be created. The custom driver must verify the validity of the specified value.
  • <other> – protocol-specific arguments such as implementation or routing.  IDL ignores these values and forwards them to the custom driver.

xif_dp_array is set to NULL.  This argument is reserved for future use to contain the stringified JSON array of the datapoints obtained after parsing the XIF file. This will contain protocol specific information for the datapoints that IDL did not interpret. The custom driver process will be responsible to parse this array and link the information to the main device and datapoint structures.

When IDL calls the device create callback function, the custom driver performs any protocol specific actions required to create a device. If there is any protocol specific device data that needs to be linked to the IDL device structure, it can be linked to void *idiDevData within IdlDev. It can also link any protocol specific datapoint data to individual datapoints to void *idiDpData within IdlDatapoint.

Upon completion, the custom driver must call IdlDevCreateResult().

Device Create Related Functions

IdlDevCreateCallbackSet

void IdlDevCreateCallbackSet(Idl *idl, int (*OnDevCreate)(int, IdlDev *, char *, char *));

Must be called by the custom driver prior to calling IdlInit.

IdlDevCreateResult

void IdlDevCreateResult(int callback_Index, IdlDev *dev, int idlError);

Must be called at the end of the device create callback function before exiting.

callback_index is the callback identifier received in the OnDevCreate callback.

dev is the IDL device object for the device received in the OnDevCreate callback.

idlError is an error code as described in Error Codes.