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

« back to all changes in this revision

Viewing changes to spectro/unixio.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:
42
42
#include "icoms.h"
43
43
#include "conv.h"
44
44
#include "usbio.h"
 
45
#include "hidio.h"
45
46
 
46
47
#undef DEBUG
47
48
 
113
114
                p->paths = NULL;
114
115
        }
115
116
 
 
117
        hid_get_paths(p);
116
118
        usb_get_paths(p);
117
 
        hid_get_paths(p);
118
119
        usbend = p->npaths;
119
120
 
120
121
#ifdef ENABLE_SERIAL
135
136
                /* Set value to match to RS232 type serial */
136
137
        CFDictionarySetValue(sdict, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDRS232Type));
137
138
 
138
 
                /* Init itterator to find matching types */
 
139
                /* Init itterator to find matching types. Consumes sdict reference */
139
140
                if ((kstat = IOServiceGetMatchingServices(kIOMasterPortDefault, sdict, &mit))
140
141
                                                                                     != KERN_SUCCESS) 
141
142
                error("IOServiceGetMatchingServices returned %d\n", kstat);
191
192
                    IOObjectRelease(ioob);              /* Release found object */
192
193
                }
193
194
            IOObjectRelease(mit);                       /* Release the itterator */
194
 
                /* Don't have to release sdict ? */
195
195
        }
196
196
#else
197
197
        /* Other UNIX like systems */
212
212
                6: uart:unknown port:00000000 irq:0
213
213
                7: uart:unknown port:00000000 irq:0
214
214
 
 
215
                but the permissions don't allow looking at this.
215
216
         */
216
217
        /* (This info is similar to what is returned by "setserial -g /dev/ttyS*", */
217
218
        /*  and "setserial -gb /dev/ttyS*" returns just the real ports.) */
282
283
                        strcpy(dpath, dirn);
283
284
                        strcat(dpath, de->d_name);
284
285
 
285
 
                        if ((fd = open(dpath, O_RDWR | O_NOCTTY | O_NONBLOCK )) < 0) {
286
 
                                if (p->debug) fprintf(errout,"failed to open serial \"%s\"\n",dpath);
287
 
                                free(dpath);
288
 
                                continue;
289
 
                        }
290
 
                        /* On linux we could do a 
291
 
                                struct serial_struct serinfo;
292
 
 
293
 
                                serinfo.reserved_char[0] = 0;
294
 
 
295
 
                                if (ioctl(fd, TIOCGSERIAL, &serinfo) < 0
296
 
                                        || serinfo.type == PORT_UNKNOWN) {
 
286
                        /* See if the serial port is real */
 
287
                        if (strncmp(de->d_name, "ttyUSB", 5) != 0) {
 
288
 
 
289
                                /* Hmm. This is probably a bad idea - it can upset other */
 
290
                                /* programs that use the serial ports ? */
 
291
                                if ((fd = open(dpath, O_RDONLY | O_NOCTTY | O_NONBLOCK)) < 0) {
 
292
                                        if (p->debug) fprintf(errout,"failed to open serial \"%s\"\n",dpath);
297
293
                                        free(dpath);
298
294
                                        continue;
299
295
                                }
300
 
 
301
 
                         */
302
 
                        close(fd);
 
296
                                /* On linux we could do a 
 
297
                                        struct serial_struct serinfo;
 
298
        
 
299
                                        serinfo.reserved_char[0] = 0;
 
300
        
 
301
                                        if (ioctl(fd, TIOCGSERIAL, &serinfo) < 0
 
302
                                                || serinfo.type == PORT_UNKNOWN) {
 
303
                                                free(dpath);
 
304
                                                continue;
 
305
                                        }
 
306
        
 
307
                                 */
 
308
                                close(fd);
 
309
                        }
303
310
                        if (p->debug) fprintf(errout,"managed to open serial \"%s\"\n",dpath);
304
311
 
305
312
                        /* Add the path to the list */
352
359
 
353
360
 
354
361
/* Close the port */
355
 
void icoms_close_port(icoms *p) {
 
362
static void icoms_close_port(icoms *p) {
356
363
        if (p->is_open) {
357
364
                if (p->is_usb) {
358
365
                        usb_close_port(p);
396
403
 
397
404
        if (port >= 1) {
398
405
                if (p->is_open && port != p->port) {    /* If port number changes */
399
 
                        icoms_close_port(p);
 
406
                        p->close_port(p);
400
407
                }
401
408
        }
402
409
 
838
845
        if (p->debug) fprintf(stderr,"icoms: delete called\n");
839
846
        if (p->is_open) {
840
847
                if (p->debug) fprintf(stderr,"icoms: closing port\n");
841
 
                icoms_close_port(p);
 
848
                p->close_port(p);
842
849
        }
843
850
        if (p->paths != NULL) {
844
851
                int i;
880
887
        p->wl = length_nc;
881
888
        p->debug = 0;
882
889
        
 
890
        p->close_port = icoms_close_port;
 
891
 
883
892
        p->port_type = icoms_port_type;
884
893
        p->get_paths = icoms_get_paths;
885
894
        p->set_ser_port = icoms_set_ser_port;