hid_return hid_prepare_interface(HIDInterface* const hidif) { hid_return ret; if (!hid_is_opened(hidif)) { ERROR_PRINT("cannot prepare unopened HIDinterface."); return HID_RET_DEVICE_NOT_OPENED; } ret = hid_init_parser(hidif); if (ret != HID_RET_SUCCESS) { hid_close(hidif); return ret; } ret = hid_prepare_hid_descriptor(hidif); if (ret != HID_RET_SUCCESS) { hid_close(hidif); return ret; } ret = hid_prepare_report_descriptor(hidif); if (ret != HID_RET_SUCCESS) { hid_close(hidif); return ret; } ret = hid_prepare_parser(hidif); if (ret != HID_RET_SUCCESS) { hid_close(hidif); return ret; } return HID_RET_SUCCESS; }
/********************************************************** * Function set_relay_hidapi() * * Description: Set new relay state * * Parameters: portname (in) - communication port * relay (in) - relay number * relay_state (in) - current relay state * serial (in) - serial number [not used] * * Return: o - success * -1 - fail *********************************************************/ int set_relay_hidapi(char* portname, uint8_t relay, relay_state_t relay_state, char* serial) { hid_device *hid_dev; unsigned char buf[REPORT_LEN]; if (relay<FIRST_RELAY || relay>(FIRST_RELAY+g_num_relays-1)) { fprintf(stderr, "ERROR: Relay number out of range\n"); return -1; } /* Open HID API device */ if ((hid_dev = hid_open_path(portname)) == NULL) { fprintf(stderr, "unable to open HID API device %s\n", portname); return -2; } /* Write relay state by sending an output report to the device */ memset(buf, 0, sizeof(buf)); buf[REPORT_WRCMD_OFFSET] = (relay_state==ON) ? CMD_ON : CMD_OFF; buf[REPORT_WRREL_OFFSET] = relay; //printf("DBG: Write relay data %02X %02X\n", buf[REPORT_WRCMD_OFFSET], buf[REPORT_WRREL_OFFSET]); if (hid_write(hid_dev, buf, sizeof(buf)) < 0) { fprintf(stderr, "unable to write output report to device %s (%ls)\n", portname, hid_error(hid_dev)); return -3; } hid_close(hid_dev); return 0; }
int main( int argc, char* argv[] ) { unsigned char buf[2]; hid_device *handle; int res; // Space Navigator: 046d c626 handle = hid_open( 0x046d, 0xc626, NULL ); if ( handle == NULL ) { printf( "spacenav-rezero: Could not open HID device (got sudo?)\n" ); exit( EXIT_FAILURE ); } buf[0] = 0x07; // This proprietary(?) feature report will rezero the device. buf[1] = 0x00; res = hid_send_feature_report( handle, buf, sizeof(buf) ); if ( res != sizeof(buf) ) { printf( "spacenav-rezero: Write failed\n" ); exit( EXIT_FAILURE ); } hid_close( handle ); return EXIT_SUCCESS; }
/********************************************************** * Function get_relay_hidapi() * * Description: Get the current relay state * * Parameters: portname (in) - communication port * relay (in) - relay number * relay_state (out) - current relay state * serial (in) - serial number [not used] * * Return: 0 - success * -1 - fail *********************************************************/ int get_relay_hidapi(char* portname, uint8_t relay, relay_state_t* relay_state, char* serial) { hid_device *hid_dev; unsigned char buf[REPORT_LEN]; if (relay<FIRST_RELAY || relay>(FIRST_RELAY+g_num_relays-1)) { fprintf(stderr, "ERROR: Relay number out of range\n"); return -1; } /* Open HID API device */ if ((hid_dev = hid_open_path(portname)) == NULL) { fprintf(stderr, "unable to open HID API device %s\n", portname); return -2; } /* Read relay states requesting a feature report with Id 0x01 */ buf[0] = 0x01; if (hid_get_feature_report(hid_dev, buf, sizeof(buf)) != REPORT_LEN) { fprintf(stderr, "unable to read feature report from device %s (%ls)\n", portname, hid_error(hid_dev)); return -3; } //printf("DBG: Relay ID: %s\n", buf); //printf("DBG: Read relay bits %02X\n", buf[REPORT_RDDAT_OFFSET]); relay = relay-1; *relay_state = (buf[REPORT_RDDAT_OFFSET] & (0x01<<relay)) ? ON : OFF; hid_close(hid_dev); return 0; }
vrpn_HidInterface::~vrpn_HidInterface() { if (_device) { hid_close(_device); _device = NULL; } }
/* -------------------------------------------------------------------------- */ static void usbhid_close(t_usbhid *x) { if(x->debug_level) post("usbhid_close"); t_int ret; char string_buffer[STRING_BUFFER_LENGTH]; if ( hid_is_opened(x->x_hidinterface) ) { ret = get_device_string(x->x_hidinterface,string_buffer); x->x_hid_return = hid_close(x->x_hidinterface); if (x->x_hid_return == HID_RET_SUCCESS) { if (ret) post("[usbhid]: closed %s",string_buffer); else post("[usbhid]: closed device"); reset_output(x); add_float_to_output(x,0); outlet_anything(x->x_status_outlet, gensym("open"), x->output_count, x->output); } else { error("[usbhid] could not close %d, error #%d",x->x_device_number,x->x_hid_return); } } }
int USB_Close() { hid_close(DeviceHandle); USBConnected = false; return 0; }
int HidController::close() { if (!isOpen()) { qDebug() << "HID device" << getName() << "already closed"; return -1; } qDebug() << "Shutting down HID device" << getName(); // Stop the reading thread if (m_pReader == NULL) { qWarning() << "HidReader not present for" << getName() << "yet the device is open!"; } else { disconnect(m_pReader, SIGNAL(incomingData(QByteArray)), this, SLOT(receive(QByteArray))); m_pReader->stop(); hid_set_nonblocking(m_pHidDevice, 1); // Quit blocking if (debugging()) qDebug() << " Waiting on reader to finish"; m_pReader->wait(); delete m_pReader; m_pReader = NULL; } // Stop controller engine here to ensure it's done before the device is closed // incase it has any final parting messages stopEngine(); // Close device if (debugging()) { qDebug() << " Closing device"; } hid_close(m_pHidDevice); setOpen(false); return 0; }
/* * release file op */ static int hiddev_release(struct inode * inode, struct file * file) { struct hiddev_list *list = file->private_data; struct hiddev_list **listptr; lock_kernel(); listptr = &list->hiddev->list; hiddev_fasync(-1, file, 0); while (*listptr && (*listptr != list)) listptr = &((*listptr)->next); *listptr = (*listptr)->next; if (!--list->hiddev->open) { if (list->hiddev->exist) hid_close(list->hiddev->hid); else hiddev_cleanup(list->hiddev); } kfree(list); unlock_kernel(); return 0; }
// Release hPortalInstance PortalIO::~PortalIO() { ActivatePortal(0); hid_close(hPortalHandle); }
void HidDevice::close() { if(isOpen()) { hid_close(devHandle); devHandle = NULL; } }
void vmarker::condisHandler(){ if(this->connected){ //CHECK IF DISCONNECTED unsigned char *data; if(hid_read_timeout(this->vmarkerdev,data,0,200)<0){ this->connected = false; qDebug("Vmarker Disconnected"); emit(Disconnect()); hid_close(this->vmarkerdev); } }else{ //SEARCH FOR VMARKER struct hid_device_info *devs,*cur_dev; int i = 0; for(i = 0; i<numPIDlist;i++){ devs = hid_enumerate(VID,PIDlist[i]); cur_dev = devs; while(cur_dev){ qDebug(cur_dev->path); if(cur_dev->interface_number == MIlist[i]){ this->vmarkerdev = hid_open_path(cur_dev->path); if(this->vmarkerdev){ this->productID = PIDlist[i]; this->connected = true; qDebug("Vmarker Connected"); emit (Connected()); } } cur_dev = cur_dev->next; } hid_free_enumeration(devs); } } }
RadioPanel::~RadioPanel() { // perform module cleanup here hid_close(handle); }
static void close_device(ohmd_device* device) { LOGD("closing device"); rift_priv* priv = rift_priv_get(device); hid_close(priv->handle); free(priv); }
void MorpheusHMD::close() { if (USBContext->sensor_device_handle != nullptr || USBContext->usb_device_handle != nullptr) { if (USBContext->sensor_device_handle != nullptr) { SERVER_LOG_INFO("MorpheusHMD::close") << "Closing MorpheusHMD sensor interface(" << USBContext->sensor_device_path << ")"; hid_close(USBContext->sensor_device_handle); } if (USBContext->usb_device_handle != nullptr) { SERVER_LOG_INFO("MorpheusHMD::close") << "Closing MorpheusHMD command interface"; morpheus_set_headset_power(USBContext, false); morpheus_close_usb_device(USBContext); } USBContext->Reset(); InData->Reset(); } else { SERVER_LOG_INFO("MorpheusHMD::close") << "MorpheusHMD already closed. Ignoring request."; } }
QString pjrc_rawhid::getserial(int num) { hid_t *hid = get_hid(num); if (!hid) return ""; if (!hid->handle) return ""; // Should we do some "critical section" stuff here?? char temp[126]; if (!HidD_GetSerialNumberString(hid->handle, temp, sizeof(temp))) { DWORD err = GetLastError(); print_win32_err(err); if (err == ERROR_DEVICE_NOT_CONNECTED) { // the device has been unplugged hid_close(hid); emit deviceUnplugged(num); return ""; } return QString("Error"); } return QString().fromUtf16((ushort*)temp,-1); }
//----------------------------------------------------------------------------- void HIDDevice::closeDeviceOnIOError() { HIDManager->DevManager->pThread->RemoveSelectFd(this,-1); LogText("OVR::Linux::HIDDevice - Lost connection to '%s'\n", DevDesc.Path.ToCStr()); hid_close(DeviceHandle); DeviceHandle = NULL; }
void Sbs2EmocapDataReader::resetHandle() { #ifdef Q_OS_MAC hid_close(handle); hid_exit(); handle = hid_open(0x1234, 0xed02, NULL); #endif }
static void close_device (struct u2fdevice *dev) { hid_close (dev->devh); free (dev->device_path); free (dev->device_string); dev->is_alive = 0; }
void DeviceHandleHIDAPI::disconnect() { if (m_pCurrentDevice != nullptr) { hid_close(m_pCurrentDevice); m_pCurrentDevice = nullptr; } }
void UsbHid::close() { if (hidDevice != 0) { hid_close(hidDevice); hidDevice = 0; } }
void close() { if (handle_) { hid_close(handle_); handle_ = 0; } }
// rawhid_close - close a device // // Inputs: // num = device to close (zero based) // Output // (nothing) // void rawhid_close(int num) { hid_t *hid; hid = get_hid(num); if (!hid || !hid->open) return; hid_close(hid); }
int main(void){ HIDInterface* hid; hid_return ret; HIDInterfaceMatcher matcher = { VENDOR, PRODUCT, NULL, NULL, 0 }; char packet[PACKET_LEN]; hid_set_debug(HID_DEBUG_NONE); hid_set_debug_stream(stderr); hid_set_usb_debug(0); hid_init(); hid = hid_new_HIDInterface(); ret = hid_force_open(hid, 0, &matcher, 3); if (ret == HID_RET_FAIL_DETACH_DRIVER) { printf("Failed to detach Driver for Device %04x:%04x; Permission?\n", VENDOR, PRODUCT); return 1; } if (ret != HID_RET_SUCCESS) { printf("Could not open HID device %04x:%04x (ret was %d)\n", VENDOR, PRODUCT, ret); return 1; } // printf("hid_force_open ret=%d\n", ret); // hid_set_idle(hid,0,0); // Discard till first '\n' do { memset(packet,0,sizeof(packet)); ret = hid_interrupt_read(hid,0x81,packet,PACKET_LEN,1000); } while (getTheChar(packet[1]) != '\n'); while (1) { memset(packet,0,sizeof(packet)); ret = hid_interrupt_read(hid,0x81,packet,PACKET_LEN,1000); /* if (ret == HID_RET_FAIL_INT_READ) { printf("Fail hid_interrupt_read\n"); } else { printf("hid_interrupt_read ret=%d\n", ret); } */ if( ret == HID_RET_SUCCESS ) { //printPacket(packet,PACKET_LEN); showTemperature(packet); } } hid_close(hid); hid_delete_HIDInterface(&hid); hid_cleanup(); return 0; }
// close - close a device // // Inputs: // num = device to close (zero based) // Output // (nothing) // void pjrc_rawhid::close(int num) { hid_t *hid; hid = get_hid(num); if (!hid || !hid->open) return; hid_close(hid); hid->open = 0; }
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { /* Метод, вызываемый при зыкрытии формы */ if (Timer1->Enabled) Timer1->Enabled = false; else hid_close(handle_device); }
void USBInterface::HIDClose() { if(HIDisOpen) { hid_close(DeviceHandle); hid_set_nonblocking(DeviceHandle,1); HIDisOpen= false; } }
int main(int argc, char* argv[]) { int res; unsigned char buf[RELAY_COMMAND_SIZE]; hid_device *handle; unsigned char command; if (argc != 2) { fprintf(stderr, "usage: %s [on|off]\n", argv[0]); exit(1); } if (strcmp(argv[1], "on") == 0) { command = RELAY_STATE_ON; } else if (strcmp(argv[1], "off") == 0) { command = RELAY_STAT_OFF; } else if (strcmp(argv[1], "scan") == 0) { return doScan(); } else { fprintf(stderr, "usage: %s [on|off]\n", argv[0]); exit(1); } if (hid_init()) { fprintf(stderr, "can't init hid lib\n"); exit(1); } // Set up the command buffer. memset(buf,0x00,sizeof(buf)); buf[1] = command; buf[2] = RELAY_NUMBER; // Open the device using the VID, PID, // and optionally the Serial number. ////handle = hid_open(0x4d8, 0x3f, L"12345"); handle = hid_open(RELAY_VENDOR_ID, RELAY_PRODUCT_ID, NULL); if (!handle) { printf("unable to open device\n"); return 1; } res = hid_write(handle, buf, sizeof(buf)); if (res < 0) { printf("Unable to send command\n"); } hid_close(handle); /* Free static HIDAPI objects. */ hid_exit(); exit(0); }
void HID_PnP::CloseDevice() { hid_close(device); device = NULL; isConnected = false; pushbuttonStatus = false; potentiometerValue = 0; toggleLeds = 0; hid_comm_update(isConnected, pushbuttonStatus, potentiometerValue); timer->start(250); }
REALTOUCH_DECLSPEC int realtouch_close(struct realtouch* s) { if(!s->_is_open) { return E_REALTOUCH_NOT_OPENED; } hid_close(s->_dev); s->_is_open = 0; return 0; }