~ubuntu-branches/ubuntu/saucy/argyll/saucy

« back to all changes in this revision

Viewing changes to spectro/hidio.c

  • Committer: Package Import Robot
  • Author(s): Christian Marillat
  • Date: 2012-04-25 07:46:07 UTC
  • mfrom: (1.2.2) (13.1.15 sid)
  • Revision ID: package-import@ubuntu.com-20120425074607-yjqadetw8kum9skc
Tags: 1.4.0-4
Should Build-Depends on libusb-dev (Closes: #670329).

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
                PSP_DEVICE_INTERFACE_DETAIL_DATA pdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)buf;
134
134
                SP_DEVINFO_DATA dinfod;
135
135
                int i;
136
 
                HANDLE fh;
137
 
                HIDD_ATTRIBUTES attr;
 
136
                unsigned short VendorID = 0, ProductID = 0;
138
137
        
139
138
                /* Make sure we've dynamically linked */
140
139
                if (setup_dyn_calls() == 0) {
153
152
                did.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
154
153
                pdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)buf;  
155
154
                pdidd->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
156
 
                attr.Size = sizeof(HIDD_ATTRIBUTES);
157
155
                dinfod.cbSize = sizeof(SP_DEVINFO_DATA);
158
156
                for (i = 0; ; i++) {
 
157
                        instType itype;
 
158
 
159
159
                        if (SetupDiEnumDeviceInterfaces(hdinfo, NULL, &HidGuid, i, &did) == 0) {
160
160
                                if (GetLastError() == ERROR_NO_MORE_ITEMS) {
161
161
                                        break;
165
165
                        if (SetupDiGetDeviceInterfaceDetail(hdinfo, &did, pdidd, DIDD_BUFSIZE, NULL, &dinfod)
166
166
                                                                                                        == 0)
167
167
                                error("SetupDiGetDeviceInterfaceDetail failed");
168
 
//printf("~1 found HID device '%s', inst %d\n",pdidd->DevicePath, dinfod.DevInst);
169
 
 
170
 
                        /* Retriev its vid and pid by querying the device */
171
 
                        if ((fh = CreateFile(pdidd->DevicePath, 0, 0, NULL, OPEN_EXISTING, 
172
 
                              0, NULL)) != INVALID_HANDLE_VALUE) {
173
 
                                instType itype;
174
 
 
175
 
                                if ((*pHidD_GetAttributes)(fh, &attr) == 0) {
176
 
                                        DBG((stderr,"HidD_GetAttributes failed for device %d",i))
177
 
                                        CloseHandle(fh);
 
168
 
 
169
                        /* Extract the vid and pid from the device path */
 
170
                        {
 
171
                                int gotid;
 
172
                                char *cp, buf[20];
 
173
 
 
174
                                for(gotid = 0;;) {
 
175
                                        if ((cp = strchr(pdidd->DevicePath, 'v')) == NULL)
 
176
                                                break;
 
177
                                        if (strlen(cp) < 8)
 
178
                                                break;
 
179
                                        if (cp[1] != 'i' || cp[2] != 'd' || cp[3] != '_')
 
180
                                                break;
 
181
                                        memcpy(buf, cp + 4, 4);
 
182
                                        buf[4] = '\000';
 
183
                                        if (sscanf(buf, "%hx", &VendorID) != 1)
 
184
                                                break;
 
185
                                        if ((cp = strchr(pdidd->DevicePath, 'p')) == NULL)
 
186
                                                break;
 
187
                                        if (strlen(cp) < 8)
 
188
                                                break;
 
189
                                        if (cp[1] != 'i' || cp[2] != 'd' || cp[3] != '_')
 
190
                                                break;
 
191
                                        memcpy(buf, cp + 4, 4);
 
192
                                        buf[4] = '\000';
 
193
                                        if (sscanf(buf, "%hx", &ProductID) != 1)
 
194
                                                break;
 
195
                                        gotid = 1;
 
196
                                        break;
 
197
                                }
 
198
                                if (!gotid) {
 
199
                                        if (p->debug) fprintf(stderr,"found HID device '%s', inst %d but unable get PID and VID\n",pdidd->DevicePath, dinfod.DevInst);
178
200
                                        continue;
179
201
                                }
180
 
 
181
 
                                /* If it's a device we're looking for */
182
 
                                if ((itype = inst_usb_match(attr.VendorID, attr.ProductID)) != instUnknown) {
183
 
                                        char pname[400];
184
 
                        
185
 
                                        /* Create human readable path/identification */
186
 
                                        sprintf(pname,"hid:/%d (%s)", dinfod.DevInst, inst_name(itype));
187
 
                        
188
 
                                        /* Add the path to the list */
189
 
                                        if (p->paths == NULL) {
190
 
                                                if ((p->paths = (icompath **)calloc(sizeof(icompath *), 1 + 1)) == NULL)
191
 
                                                        error("icoms: calloc failed!");
192
 
                                        } else {
193
 
                                                if ((p->paths = (icompath **)realloc(p->paths,
194
 
                                                                     sizeof(icompath *) * (p->npaths + 2))) == NULL)
195
 
                                                        error("icoms: realloc failed!");
196
 
                                                p->paths[p->npaths+1] = NULL;
197
 
                                        }
198
 
                                        if ((p->paths[p->npaths] = calloc(sizeof(icompath), 1)) == NULL)
199
 
                                                error("icoms: calloc failed!");
200
 
                                        p->paths[p->npaths]->vid = attr.VendorID;
201
 
                                        p->paths[p->npaths]->pid = attr.ProductID;
202
 
                                        p->paths[p->npaths]->dev = NULL;                /* Make sure it's NULL */
203
 
                                        if ((p->paths[p->npaths]->hev = (hid_device *)calloc(sizeof(hid_device), 1))
204
 
                                                                                                             == NULL)
205
 
                                                error("icoms: calloc failed!");
206
 
                                        if ((p->paths[p->npaths]->hev->dpath = strdup(pdidd->DevicePath)) == NULL)
207
 
                                                error("icoms: calloc failed!");
208
 
                                        p->paths[p->npaths]->itype = itype;
209
 
                                        if ((p->paths[p->npaths]->path = strdup(pname)) == NULL)
210
 
                                                error("icoms: strdup failed!");
211
 
                                        p->npaths++;
212
 
                                        p->paths[p->npaths] = NULL;
 
202
                        }
 
203
 
 
204
                        /* If it's a device we're looking for */
 
205
                        if ((itype = inst_usb_match(VendorID, ProductID)) != instUnknown) {
 
206
                                char pname[400];
 
207
                
 
208
                                if (p->debug) fprintf(stderr,"found HID device '%s', inst %d that we're looking for\n",pdidd->DevicePath, dinfod.DevInst);
 
209
 
 
210
                                /* Create human readable path/identification */
 
211
                                sprintf(pname,"hid:/%d (%s)", dinfod.DevInst, inst_name(itype));
 
212
                
 
213
                                /* Add the path to the list */
 
214
                                if (p->paths == NULL) {
 
215
                                        if ((p->paths = (icompath **)calloc(sizeof(icompath *), 1 + 1)) == NULL)
 
216
                                                error("icoms: calloc failed!");
 
217
                                } else {
 
218
                                        if ((p->paths = (icompath **)realloc(p->paths,
 
219
                                                             sizeof(icompath *) * (p->npaths + 2))) == NULL)
 
220
                                                error("icoms: realloc failed!");
 
221
                                        p->paths[p->npaths+1] = NULL;
213
222
                                }
214
 
                                CloseHandle(fh);
 
223
                                if ((p->paths[p->npaths] = calloc(sizeof(icompath), 1)) == NULL)
 
224
                                        error("icoms: calloc failed!");
 
225
                                p->paths[p->npaths]->vid = VendorID;
 
226
                                p->paths[p->npaths]->pid = ProductID;
 
227
                                p->paths[p->npaths]->dev = NULL;                /* Make sure it's NULL */
 
228
                                if ((p->paths[p->npaths]->hev = (hid_device *)calloc(sizeof(hid_device), 1))
 
229
                                                                                                     == NULL)
 
230
                                        error("icoms: calloc failed!");
 
231
                                if ((p->paths[p->npaths]->hev->dpath = strdup(pdidd->DevicePath)) == NULL)
 
232
                                        error("icoms: calloc failed!");
 
233
                                p->paths[p->npaths]->itype = itype;
 
234
                                if ((p->paths[p->npaths]->path = strdup(pname)) == NULL)
 
235
                                        error("icoms: strdup failed!");
 
236
                                p->npaths++;
 
237
                                p->paths[p->npaths] = NULL;
 
238
                        } else {
 
239
                                if (p->debug) fprintf(stderr,"found HID device '%s', inst %d but not one we're looking for\n",pdidd->DevicePath, dinfod.DevInst);
215
240
                        }
216
241
                }
217
242
 
223
248
#endif /* NT */
224
249
 
225
250
#ifdef __APPLE__
226
 
        /* On OS X the general USB driver will locate the HID devices, but */
227
 
        /* not be able to claim the interfaces without using a kext to stop */
228
 
        /* the HID driver grabing the interfaces. We switch them from libusb */
229
 
        /* access to OS X HID driver access to avoid the problem. */
230
251
        {
231
252
            kern_return_t kstat; 
232
253
            CFMutableDictionaryRef sdict;               /* HID Device  dictionary */
237
258
                warning("IOServiceMatching returned a NULL dictionary");
238
259
                }
239
260
 
240
 
                /* Init itterator to find matching types */
 
261
                /* Init itterator to find matching types. Consumes sdict reference */
241
262
                if ((kstat = IOServiceGetMatchingServices(kIOMasterPortDefault, sdict, &mit))
242
263
                                                                                  != KERN_SUCCESS) 
243
264
                error("IOServiceGetMatchingServices returned %d", kstat);
245
266
                /* Find all the matching HID devices */
246
267
                for (;;) {
247
268
                        io_object_t ioob;                                               /* HID object found */
248
 
                    CFMutableDictionaryRef hidprops = 0;        /* HID Device properties */
249
 
                        CFNumberRef vref, pref;
 
269
                        CFNumberRef vref, pref;                                 /* HID Vendor and Product ID propeties */
250
270
                        unsigned int vid = 0, pid = 0;
 
271
                        instType itype;
251
272
 
252
273
                    if ((ioob = IOIteratorNext(mit)) == 0)
253
274
                                break;
254
275
 
255
 
                        /* Get the devices vid and pid */
256
 
                        if (IORegistryEntryCreateCFProperties(ioob, &hidprops,
257
 
                                        kCFAllocatorDefault, kNilOptions) != KERN_SUCCESS || hidprops == 0)
258
 
                                goto continue1;
259
 
 
260
 
                        if ((vref = CFDictionaryGetValue(hidprops, CFSTR(kIOHIDVendorIDKey))) != 0) {
 
276
                        /* Get the two properies we need. [ Doing IORegistryEntryCreateCFProperty() is much faster */
 
277
                        /* than IORegistryEntryCreateCFProperties() in some cases.] */
 
278
                        if ((vref = IORegistryEntryCreateCFProperty(ioob, CFSTR(kIOHIDVendorIDKey),
 
279
                                                                 kCFAllocatorDefault,kNilOptions)) != 0) {
261
280
                                CFNumberGetValue(vref, kCFNumberIntType, &vid);
262
 
                                CFRelease(vref);
 
281
                            CFRelease(vref);
263
282
                        }
264
 
                        if ((pref = CFDictionaryGetValue(hidprops, CFSTR(kIOHIDProductIDKey))) != 0) {
 
283
                        if ((pref = IORegistryEntryCreateCFProperty(ioob, CFSTR(kIOHIDProductIDKey),
 
284
                                                                 kCFAllocatorDefault,kNilOptions)) != 0) {
265
285
                                CFNumberGetValue(pref, kCFNumberIntType, &pid);
266
 
                                CFRelease(pref);
 
286
                            CFRelease(pref);
267
287
                        }
268
 
// ~~999
269
 
//                      CFRelease(hidprops);            // Crashes !!
270
 
                        hidprops = NULL;
271
288
 
272
289
                        /* If it's a device we're looking for */
273
 
                        if (inst_usb_match(vid, pid) != instUnknown) {
274
 
                                int i;
275
 
                                for (i = 0; i < p->npaths; i++) {       /* Locate it in the current list */
276
 
                                        if (p->paths[i]->dev != NULL
277
 
                                         && p->paths[i]->vid == vid && p->paths[i]->pid == pid) {
278
 
 
279
 
                                                if ((p->paths[i]->hev = (hid_device *)calloc(sizeof(hid_device), 1)) == NULL)
280
 
                                                        error("icoms: calloc failed!");
281
 
 
282
 
                                                p->paths[i]->hev->ioob = ioob;
283
 
                                                usb_del_usb_device(p->paths[i]->dev);   /* Done with this */
284
 
                                                p->paths[i]->dev = NULL;        /* (Points to libusb allocation) */
285
 
                                                ioob = 0;
286
 
                                                break;
287
 
                                        }
 
290
                        if ((itype = inst_usb_match(vid, pid)) != instUnknown) {
 
291
                                char pname[400];
 
292
                                if (p->debug) fprintf(stderr,"found HID device '%s' that we're looking for\n",inst_name(itype));
 
293
 
 
294
                                /* Create human readable path/identification */
 
295
                                /* (There seems to be no easy way of creating an interface no, without */
 
296
                                /*  heroic efforts looking through the IO registry, so don't try.) */
 
297
                                sprintf(pname,"hid: (%s)", inst_name(itype));
 
298
                
 
299
                                /* Add the path to the list */
 
300
                                if (p->paths == NULL) {
 
301
                                        if ((p->paths = (icompath **)calloc(sizeof(icompath *), 1 + 1)) == NULL)
 
302
                                                error("icoms: calloc failed!");
 
303
                                } else {
 
304
                                        if ((p->paths = (icompath **)realloc(p->paths,
 
305
                                                             sizeof(icompath *) * (p->npaths + 2))) == NULL)
 
306
                                                error("icoms: realloc failed!");
 
307
                                        p->paths[p->npaths+1] = NULL;
288
308
                                }
 
309
                                if ((p->paths[p->npaths] = calloc(sizeof(icompath), 1)) == NULL)
 
310
                                        error("icoms: calloc failed!");
 
311
                                p->paths[p->npaths]->vid = vid;
 
312
                                p->paths[p->npaths]->pid = pid;
 
313
                                p->paths[p->npaths]->dev = NULL;                /* Make sure it's NULL */
 
314
                                if ((p->paths[p->npaths]->hev = (hid_device *)calloc(sizeof(hid_device), 1))
 
315
                                                                                                     == NULL)
 
316
                                        error("icoms: calloc failed!");
 
317
                                p->paths[p->npaths]->hev->ioob = ioob;
 
318
                                ioob = 0;                       /* Don't release it */
 
319
                                p->paths[p->npaths]->itype = itype;
 
320
                                if ((p->paths[p->npaths]->path = strdup(pname)) == NULL)
 
321
                                        error("icoms: strdup failed!");
 
322
                                p->npaths++;
 
323
                                p->paths[p->npaths] = NULL;
289
324
                        }
290
 
                continue1:
291
 
                        if (ioob != 0)
 
325
                        if (ioob != 0)          /* If we haven't kept it */
292
326
                            IOObjectRelease(ioob);              /* Release found object */
293
327
                }
294
328
            IOObjectRelease(mit);                       /* Release the itterator */
412
446
            IOObjectRelease(p->hidd->port);
413
447
                p->hidd->port = 0;
414
448
 
415
 
                CFRunLoopRemoveSource(p->hidd->rlr, p->hidd->evsrc, kCFRunLoopDefaultMode);
416
 
 
417
449
                CFRelease(p->hidd->evsrc);
418
450
                p->hidd->evsrc = NULL;
419
451
 
448
480
/* Open an HID port for all our uses. */
449
481
static void hid_open_port(
450
482
icoms *p,
451
 
int    port,            /* USB com port, 1 - N, 0 for no change. */
452
 
icomuflags hidflags     /* Any special handling flags */
 
483
int    port,                    /* USB com port, 1 - N, 0 for no change. */
 
484
icomuflags hidflags,    /* Any special handling flags */
 
485
int retries,                    /* > 0 if we should retry set_configuration (100msec) */
 
486
char **pnames                   /* List of process names to try and kill before opening */
453
487
) {
454
488
        if (p->debug) fprintf(stderr,"icoms: About to open the USB port\n");
455
489
 
456
490
        if (port >= 1) {
457
491
                if (p->is_open && port != p->port) {    /* If port number changes */
458
 
                        icoms_close_port(p);
 
492
                        p->close_port(p);
459
493
                }
460
494
        }
461
495
 
494
528
 
495
529
#if defined(NT) 
496
530
                {
497
 
                        /* Open the device */
498
 
                        if ((p->hidd->fh = CreateFile(p->hidd->dpath, GENERIC_READ|GENERIC_WRITE,
499
 
                              0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL))
500
 
                                                                                   == INVALID_HANDLE_VALUE)
 
531
                        int tries = 0;
 
532
 
 
533
                        for (tries = 0; retries >= 0; retries--, tries++) {
 
534
                                /* Open the device */
 
535
                                if ((p->hidd->fh = CreateFile(p->hidd->dpath, GENERIC_READ|GENERIC_WRITE,
 
536
                                      0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL))
 
537
                                                                              != INVALID_HANDLE_VALUE) {
 
538
                                        memset(&p->hidd->ols,0,sizeof(OVERLAPPED));
 
539
                                        if ((p->hidd->ols.hEvent = CreateEvent(NULL, 0, 0, NULL)) == NULL)
 
540
                                                error("Failed to create HID Event'\n");
 
541
                                        break;
 
542
                                }
 
543
                                if (tries > 0 && pnames != NULL) {
 
544
                                        /* Open failed. This could be the i1ProfileTray.exe */
 
545
                                        kill_nprocess(pnames, p->debug);
 
546
                                        msec_sleep(100);
 
547
                                }
 
548
                        }
 
549
                        if (p->hidd->fh == INVALID_HANDLE_VALUE)
501
550
                                error("Failed to open HID device '%s'\n",p->ppath->path);
502
 
                        
503
 
                        memset(&p->hidd->ols,0,sizeof(OVERLAPPED));
504
 
                        if ((p->hidd->ols.hEvent = CreateEvent(NULL, 0, 0, NULL)) == NULL)
505
 
                                error("Failed to create HID Event'\n");
506
551
                }
507
552
#endif /* NT */
508
553
 
510
555
                {
511
556
                        IOCFPlugInInterface **piif = NULL;
512
557
                        IOReturn result;
513
 
                        SInt32 dumy;
 
558
                        SInt32 score;
514
559
 
515
560
                        if ((result = IOCreatePlugInInterfaceForService(p->hidd->ioob, kIOHIDDeviceUserClientTypeID,
516
 
                            kIOCFPlugInInterfaceID, &piif, &dumy) != kIOReturnSuccess || piif == NULL))
 
561
                            kIOCFPlugInInterfaceID, &piif, &score) != kIOReturnSuccess || piif == NULL))
517
562
                                error("Failed to open HID device '%s', result 0x%x, piif 0x%x\n",p->ppath->path,result,piif);
518
563
        
519
564
                        p->hidd->device = NULL;
523
568
                                error("Getting HID device '%s' failed",p->ppath->path);
524
569
                        (*piif)->Release(piif);         /* delete intermediate object */
525
570
 
526
 
                        if ((*p->hidd->device)->open(p->hidd->device, 0) != kIOReturnSuccess)
 
571
                        if ((*p->hidd->device)->open(p->hidd->device, kIOHIDOptionsTypeSeizeDevice)
 
572
                                                                               != kIOReturnSuccess)
527
573
                                error("Opening HID device '%s' failed",p->ppath->path);
528
574
 
529
575
                        /* Setup to handle interrupt read callbacks */
537
583
                                != kIOReturnSuccess || p->hidd->evsrc == NULL)
538
584
                                error("Creating event source on HID device '%s' failed",p->ppath->path);
539
585
 
540
 
//                      p->hidd->rlr = CFRetain(CFRunLoopGetCurrent());
541
 
                        p->hidd->rlr = CFRunLoopGetCurrent();
542
 
 
543
 
                        CFRunLoopAddSource(p->hidd->rlr, p->hidd->evsrc, kCFRunLoopDefaultMode);
544
 
 
545
586
                }
546
587
#endif /* __APPLE__ */
547
588
 
565
606
IOReturn result,
566
607
void *refcon,
567
608
void *sender,
568
 
UInt32 size) {
 
609
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
 
610
uint32_t size
 
611
#else
 
612
UInt32 size
 
613
#endif
 
614
) {
569
615
        icoms *p = (icoms *)target;
570
616
 
571
617
//printf("\n~1 callback called with size %d, result 0x%x\n",size,result);
603
649
 
604
650
                /* Create a copy of the data recieved with one more byte */
605
651
                if ((rbuf2 = malloc(bsize + 1)) == NULL)
606
 
                        error("icoms_hid_write, malloc failed");
 
652
                        error("icoms_hid_read, malloc failed");
607
653
                rbuf2[0] = 0;
608
654
                if (ReadFile(p->hidd->fh, rbuf2, bsize+1, (LPDWORD)&bread, &p->hidd->ols) == 0)  {
609
655
                        if (GetLastError() != ERROR_IO_PENDING) {
643
689
                        error("Setting callback handler for HID '%s' failed", p->ppath->path);
644
690
                if ((*(p->hidd->device))->startAllQueues(p->hidd->device) != kIOReturnSuccess)
645
691
                        error("Starting queues for HID '%s' failed", p->ppath->path);
 
692
 
646
693
                /* Call runloop, but exit after handling one callback */
 
694
                p->hidd->rlr = CFRunLoopGetCurrent();
 
695
                CFRunLoopAddSource(p->hidd->rlr, p->hidd->evsrc, kCFRunLoopDefaultMode);
647
696
                result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, tout, false);
648
697
                if ((*(p->hidd->device))->stopAllQueues(p->hidd->device) != kIOReturnSuccess)
649
698
                        error("Stopping queues for HID '%s' failed", p->ppath->path);
652
701
                } else if (result != kCFRunLoopRunStopped) {
653
702
                        lerr = ICOM_USBR; 
654
703
                }
 
704
                CFRunLoopRemoveSource(p->hidd->rlr, p->hidd->evsrc, kCFRunLoopDefaultMode);
 
705
 
655
706
                if (p->hidd->result == -1) {            /* Callback wasn't called */
656
707
                        lerr = ICOM_TO; 
657
708
                } else if (p->hidd->result != kIOReturnSuccess) {
728
779
                if ((wbuf2 = malloc(bsize + 1)) == NULL)
729
780
                        error("icoms_hid_write, malloc failed");
730
781
                memmove(wbuf2+1,wbuf,bsize);
731
 
                wbuf2[0] = 0;           /* Extra report ID byte */
 
782
                wbuf2[0] = 0;           /* Extra report ID byte (why ?) */
732
783
                if (WriteFile(p->hidd->fh, wbuf2, bsize+1, (LPDWORD)&bwritten, &p->hidd->ols) == 0) { 
733
784
                        if (GetLastError() != ERROR_IO_PENDING) {
734
785
                                lerr = ICOM_USBW; 
736
787
                                int res;
737
788
                                res = WaitForSingleObject(p->hidd->ols.hEvent, (int)(tout * 1000.0 + 0.5));
738
789
                                if (res == WAIT_FAILED)
739
 
                                        error("HID wait on read failed");
 
790
                                        error("HID wait on write failed");
740
791
                                else if (res == WAIT_TIMEOUT) {
741
792
                                        CancelIo(p->hidd->fh);
742
793
                                        lerr = ICOM_TO; 
817
868
static void
818
869
icoms_set_hid_port(
819
870
icoms *p, 
820
 
int    port,            /* HID com port, 1 - N, 0 for no change. */
821
 
icomuflags hidflags     /* Any special handling flags */
 
871
int    port,                    /* HID com port, 1 - N, 0 for no change. */
 
872
icomuflags hidflags,    /* Any special handling flags */
 
873
int retries,                    /* > 0 if we should retry set_configuration (100msec) */
 
874
char **pnames                   /* List of process names to try and kill before opening */
822
875
) {
823
876
        if (p->debug) fprintf(stderr,"icoms: About to set hid port characteristics\n");
824
877
 
825
878
        if (p->is_open) 
826
 
                icoms_close_port(p);
 
879
                p->close_port(p);
827
880
 
828
881
        if (p->is_hid_portno(p, port) != instUnknown) {
829
882
 
830
 
                hid_open_port(p, port, hidflags);
 
883
                hid_open_port(p, port, hidflags, retries, pnames);
831
884
 
832
885
                p->write = NULL;
833
886
                p->read = NULL;
847
900
) {
848
901
        p->is_hid_portno  = hid_is_hid_portno;
849
902
        p->set_hid_port   = icoms_set_hid_port;
 
903
        p->hid_read_th    = icoms_hid_read_th;
 
904
        p->hid_write_th   = icoms_hid_write_th;
850
905
        p->hid_read       = icoms_hid_read;
851
906
        p->hid_write      = icoms_hid_write;
852
907