DLN_OPEN_DEVICE

DLN_OPEN_DEVICE Command

Go to response

The DLN_OPEN_DEVICE command opens the specified device.

  typedef struct
   {
      DLN_MSG_HEADER header;
      uint16_t filter;
      uint32_t number;
      uint32_t hardwareType;
      uint32_t sn;
      uint32_t id;
   } __PACKED_ATTR DLN_OPEN_DEVICE_CMD;

Parameters:

header

Defines the DLN message header DLN_MSG_HEADER. The header contains several predefined fields and is used to identify and route messages. When sending the command, a user must fill the following fields

  • size - The size of the message. Must be equal to the size of the DLN_OPEN_DEVICE_CMD structure.
  • msgId - Defines the message. For the DLN_OPEN_DEVICE command it must be set to x0021. You can use the DLN_MSG_ID_OPEN_DEVICE constant.
  • echoCounter - Can be used to link the command to a response. The response will have the same echoCounter value. This field can be any numerical value from 0 to 0xFFFF (65536).
  • handle - A handle to the DLN-series adapter. For the DLN_OPEN_DEVICE command the HDLN_ALL_DEVICES value must be used.
filter

A bit field that defines how the device will be identified for opening. Each bit corresponds to a DLN-series adapter identification, namely:

Bit Identification
0 Device number
1 Hardware type
2 Device serial number
3 Device ID number

Only the identifications with corresponding mask bits set to 1 will be taken into account. The identifications with mask bits set to 0 will be ignored.

A user can set several mask bits to 1. This way only a device with all identifications matching the specified ones will be opened.

For example, if we need to open the device with the specific hardware type and ID number, we should set the filter parameter as follows:

1010

You can use the following constants:

  • DLN_DEVICE_FILTER_NUMBER - the number parameter;
  • DLN_DEVICE_FILTER_HW_TYPE - the hardwareType parameter;
  • DLN_DEVICE_FILTER_SN - the sn parameter;
  • DLN_DEVICE_FILTER_ID - the id parameter;
number
A number of the connected device. Used for DlnOpenDevice() function.
hardwareType
A type of the DLN-series adapter.
sn
A serial number of the DLN-series adapter. Used for DlnOpenDeviceBySn() function.
id
An ID number of the DLN-series adapter. Used for DlnOpenDeviceById() function.

DLN_OPEN_DEVICE Response

Go to command

The adapter sends the DLN_OPEN_DEVICE response after the command execution. The response notifies you if the device has been successfully opened.

  typedef struct
   {
      DLN_MSG_HEADER header;
      DLN_RESULT result;
      HDLN-series adapterHandle;
   } __PACKED_ATTR DLN_OPEN_DEVICE_RSP;

Parameters:

header
Defines the DLN message header DLN_MSG_HEADER. The response header contains the following fields:
  • size - The size of the message. Is equal to the size of the DLN_OPEN_DEVICE_RSP structure.
  • msgId - Defines the message. For the DLN_OPEN_DEVICE response it is set to 0x0021. The DLN_MSG_ID_CONNECT constant can be used.
  • echoCounter - Links a command to a response. The echoCounter value is copied from the respective command header.
  • handle - A handle to the DLN-series adapter.
result

Contains the result of the command execution. The following values are available:

  • DLN_RES_SUCCESS - the device was successfully opened. The deviceHandle parameter contains a valid handle.
  • DLN_RES_NOT_CONNECTED - The library was not connected to any server (See DlnConnect() function).
  • DLN_RES_MEMORY_ERROR - Not enough memory to process this command.
  • DLN_RES_HARDWARE_NOT_FOUND - The number of available devices is less than deviceNumber+1
  • DLN_RES_DEVICE_REMOVED - The device was disconnected while opening.
deviceHandle
A handle to the DLN-series adapter. For the DLN_OPEN_DEVICE response the HDLN_ALL_DEVICES value is used.