Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// # set proper configuration
// self.device.set_configuration(self.cfg)
// claim interface
if (this.iface.isKernelDriverActive()) {
this.iface.detachKernelDriver();
}
this.iface.claim();
// don't need to set altsetting - USBTMC devices have 1 altsetting as per the spec
// find endpoints
for (let i = 0; i < this.iface.endpoints.length; i++) {
if (this.iface.endpoints[i].transferType === usb.LIBUSB_TRANSFER_TYPE_BULK) {
if (this.iface.endpoints[i] instanceof usb.InEndpoint) {
this.bulk_in_ep = this.iface.endpoints[i] as usb.InEndpoint;
} else {
this.bulk_out_ep = this.iface.endpoints[i] as usb.OutEndpoint;
}
} else if (
this.iface.endpoints[i].transferType === usb.LIBUSB_TRANSFER_TYPE_INTERRUPT
) {
if (this.iface.endpoints[i] instanceof usb.InEndpoint) {
this.interrupt_in_ep = this.iface.endpoints[i] as usb.InEndpoint;
}
}
}
if (!this.bulk_in_ep || !this.bulk_out_ep) {
throw new UsbtmcException("Invalid endpoint configuration", "init");
}
const endpointDesc: usb.EndpointDescriptor = new usb.EndpointDescriptor();
endpointDesc.bLength = 1;
endpointDesc.bDescriptorType = 1;
endpointDesc.bEndpointAddress = 1;
endpointDesc.bmAttributes = 1;
endpointDesc.wMaxPacketSize = 1;
endpointDesc.bInterval = 1;
endpointDesc.bRefresh = 1;
endpointDesc.bSynchAddress = 1;
const ifaceInEndpoint: usb.Endpoint = iface.endpoint(1) as usb.InEndpoint;
const ifaceOutEndpoint: usb.Endpoint = iface.endpoint(1) as usb.OutEndpoint;
const inEndpoint: usb.InEndpoint = new usb.InEndpoint(device, endpointDesc);
inEndpoint.direction = "in";
inEndpoint.transferType = 1;
inEndpoint.timeout = 1;
inEndpoint.descriptor = endpointDesc;
const xferInEndpoint: usb.InEndpoint = inEndpoint.transfer(1, (error: string, data: Buffer) => inEndpoint);
inEndpoint.startPoll(1, 1);
inEndpoint.stopPoll(() => null);
const outEndpoint: usb.OutEndpoint = new usb.OutEndpoint(device, endpointDesc);
outEndpoint.direction = "out";
outEndpoint.transferType = 1;
outEndpoint.timeout = 1;
outEndpoint.descriptor = endpointDesc;
const xferOutEndpoint: usb.OutEndpoint = outEndpoint.transfer(new Buffer([]), (error: string) => null);
outEndpoint.transferWithZLP(new Buffer([]), (error: string) => null);