open

Top  Previous  Next

Opens a device to allow reading and writing of data to endpoints or to get or set feature reports.

Definition

hidDevice, err = hid.open( vendorId, productId, serial )

hidDevice, err = hid.open( path )

Parameters

Name

Type

Description

vendorId

number

The vendor id or 0 for all vendors.

productId

number

The product id or 0 for all products.

path

string

The path to the hid device from enumeration.

hidDevice

Hid Device Object

Hid Device or nil

err

string

Descriptive error if hidDevice is nil

Example

The PIR-1 exposes two interface. The first is a keyboard the second is the IR generic hid device. To be able to open the second device we'll need to first use enumerate and try to open interface with id 0. On Linux interfaceNumber is not specified so just try to open both and use the one that actually opens.

 

function openFirstPIR1() 

 

    local pir1Devices = hid.enumerate(0x20a0, 0x413f)

    table.print(pir1Devices)

    

    for idx, pir1Device in ipairs(pir1Devices) do

    

      if pir1Device.interfaceNumber == -1 or pir1Device.interfaceNumber == 0 then

        local hidDev, err = hid.open(pir1Device.path)

        if hidDev then

            return hidDev

        else

            print(err)

        end

              

     end

    

    end

    

end

 

hidDev = openFirstPIR1()

print(hidDev)