2 * "$Id: serial.c 4906 2006-01-10 20:53:28Z mike $"
4 * Serial port backend for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * main() - Send a file to the printer or server.
29 * list_devices() - List all serial devices.
33 * Include necessary headers.
36 #include <cups/backend.h>
37 #include <cups/cups.h>
41 #include <cups/string.h>
45 # include <sys/modem.h>
54 # include <sys/select.h>
55 # ifdef HAVE_SYS_IOCTL_H
56 # include <sys/ioctl.h>
57 # endif /* HAVE_SYS_IOCTL_H */
62 # ifndef INV_EPP_ECP_PLP
63 # define INV_EPP_ECP_PLP 6 /* From 6.3/6.4/6.5 sys/invent.h */
64 # define INV_ASO_SERIAL 14 /* serial portion of SGI ASO board */
65 # define INV_IOC3_DMA 16 /* DMA mode IOC3 serial */
66 # define INV_IOC3_PIO 17 /* PIO mode IOC3 serial */
67 # define INV_ISA_DMA 19 /* DMA mode ISA serial -- O2 */
68 # endif /* !INV_EPP_ECP_PLP */
73 # define CRTSCTS CNEW_RTSCTS
76 # endif /* CNEW_RTSCTS */
79 #if defined(__APPLE__)
80 # include <CoreFoundation/CoreFoundation.h>
81 # include <IOKit/IOKitLib.h>
82 # include <IOKit/serial/IOSerialKeys.h>
83 # include <IOKit/IOBSD.h>
84 #endif /* __APPLE__ */
91 void list_devices(void);
95 * 'main()' - Send a file to the printer or server.
99 * printer-uri job-id user title copies options [file]
102 int /* O - Exit status */
103 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
104 char *argv
[]) /* I - Command-line arguments */
106 char method
[255], /* Method in URI */
107 hostname
[1024], /* Hostname */
108 username
[255], /* Username info (not used) */
109 resource
[1024], /* Resource info (device and options) */
110 *options
, /* Pointer to options */
111 name
[255], /* Name of option */
112 value
[255], /* Value of option */
113 *ptr
; /* Pointer into name or value */
114 int port
; /* Port number (not used) */
115 int fp
; /* Print file */
116 int copies
; /* Number of copies to print */
117 int fd
; /* Parallel device */
118 int rbytes
; /* Number of bytes read */
119 int wbytes
; /* Number of bytes written */
120 size_t nbytes
, /* Number of bytes read */
121 tbytes
; /* Total number of bytes written */
122 int dtrdsr
; /* Do dtr/dsr flow control? */
123 int bufsize
; /* Size of output buffer for writes */
124 char buffer
[8192], /* Output buffer */
125 *bufptr
; /* Pointer into buffer */
126 struct termios opts
; /* Serial port options */
127 struct termios origopts
; /* Original port options */
128 fd_set input
, /* Input set for select() */
129 output
; /* Output set for select() */
130 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
131 struct sigaction action
; /* Actions for POSIX signals */
132 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
136 * Make sure status messages are not buffered...
139 setbuf(stderr
, NULL
);
142 * Ignore SIGPIPE signals...
146 sigset(SIGPIPE
, SIG_IGN
);
147 #elif defined(HAVE_SIGACTION)
148 memset(&action
, 0, sizeof(action
));
149 action
.sa_handler
= SIG_IGN
;
150 sigaction(SIGPIPE
, &action
, NULL
);
152 signal(SIGPIPE
, SIG_IGN
);
153 #endif /* HAVE_SIGSET */
156 * Check command-line...
162 return (CUPS_BACKEND_OK
);
164 else if (argc
< 6 || argc
> 7)
166 fputs("Usage: serial job-id user title copies options [file]\n", stderr
);
167 return (CUPS_BACKEND_FAILED
);
171 * If we have 7 arguments, print the file named on the command-line.
172 * Otherwise, send stdin instead...
183 * Try to open the print file...
186 if ((fp
= open(argv
[6], O_RDONLY
)) < 0)
188 perror("ERROR: unable to open print file");
189 return (CUPS_BACKEND_FAILED
);
192 copies
= atoi(argv
[4]);
196 * Extract the device name and options from the URI...
199 httpSeparateURI(argv
[0], method
, sizeof(method
), username
, sizeof(username
),
200 hostname
, sizeof(hostname
), &port
,
201 resource
, sizeof(resource
));
204 * See if there are any options...
207 if ((options
= strchr(resource
, '?')) != NULL
)
210 * Yup, terminate the device name string and move to the first
211 * character of the options...
218 * Open the serial port device...
223 if ((fd
= open(resource
, O_WRONLY
| O_NOCTTY
| O_EXCL
| O_NDELAY
)) == -1)
225 if (getenv("CLASS") != NULL
)
228 * If the CLASS environment variable is set, the job was submitted
229 * to a class and not to a specific queue. In this case, we want
230 * to abort immediately so that the job can be requeued on the next
231 * available printer in the class.
234 fputs("INFO: Unable to open serial port, queuing on next printer in class...\n",
238 * Sleep 5 seconds to keep the job from requeuing too rapidly...
243 return (CUPS_BACKEND_FAILED
);
248 fputs("INFO: Serial port busy; will retry in 30 seconds...\n", stderr
);
253 fprintf(stderr
, "ERROR: Unable to open serial port device file \"%s\": %s\n",
254 resource
, strerror(errno
));
255 return (CUPS_BACKEND_FAILED
);
262 * Set any options provided...
265 tcgetattr(fd
, &origopts
);
266 tcgetattr(fd
, &opts
);
268 opts
.c_lflag
&= ~(ICANON
| ECHO
| ISIG
); /* Raw mode */
269 opts
.c_oflag
&= ~OPOST
; /* Don't post-process */
271 bufsize
= 96; /* 9600 baud / 10 bits/char / 10Hz */
272 dtrdsr
= 0; /* No dtr/dsr flow control */
281 for (ptr
= name
; *options
&& *options
!= '=';)
282 if (ptr
< (name
+ sizeof(name
) - 1))
294 for (ptr
= value
; *options
&& *options
!= '+' && *options
!= '&';)
295 if (ptr
< (value
+ sizeof(value
) - 1))
306 * Process the option...
309 if (!strcasecmp(name
, "baud"))
312 * Set the baud rate...
315 bufsize
= atoi(value
) / 100;
318 cfsetispeed(&opts
, atoi(value
));
319 cfsetospeed(&opts
, atoi(value
));
324 cfsetispeed(&opts
, B1200
);
325 cfsetospeed(&opts
, B1200
);
328 cfsetispeed(&opts
, B2400
);
329 cfsetospeed(&opts
, B2400
);
332 cfsetispeed(&opts
, B4800
);
333 cfsetospeed(&opts
, B4800
);
336 cfsetispeed(&opts
, B9600
);
337 cfsetospeed(&opts
, B9600
);
340 cfsetispeed(&opts
, B19200
);
341 cfsetospeed(&opts
, B19200
);
344 cfsetispeed(&opts
, B38400
);
345 cfsetospeed(&opts
, B38400
);
349 cfsetispeed(&opts
, B57600
);
350 cfsetospeed(&opts
, B57600
);
355 cfsetispeed(&opts
, B115200
);
356 cfsetospeed(&opts
, B115200
);
358 # endif /* B115200 */
361 cfsetispeed(&opts
, B230400
);
362 cfsetospeed(&opts
, B230400
);
364 # endif /* B230400 */
366 fprintf(stderr
, "WARNING: Unsupported baud rate %s!\n", value
);
369 #endif /* B19200 == 19200 */
371 else if (!strcasecmp(name
, "bits"))
374 * Set number of data bits...
380 opts
.c_cflag
&= ~CSIZE
;
382 opts
.c_cflag
|= PARENB
;
383 opts
.c_cflag
&= ~PARODD
;
386 opts
.c_cflag
&= ~CSIZE
;
388 opts
.c_cflag
&= ~PARENB
;
392 else if (!strcasecmp(name
, "parity"))
395 * Set parity checking...
398 if (!strcasecmp(value
, "even"))
400 opts
.c_cflag
|= PARENB
;
401 opts
.c_cflag
&= ~PARODD
;
403 else if (!strcasecmp(value
, "odd"))
405 opts
.c_cflag
|= PARENB
;
406 opts
.c_cflag
|= PARODD
;
408 else if (!strcasecmp(value
, "none"))
409 opts
.c_cflag
&= ~PARENB
;
410 else if (!strcasecmp(value
, "space"))
413 * Note: we only support space parity with 7 bits per character...
416 opts
.c_cflag
&= ~CSIZE
;
418 opts
.c_cflag
&= ~PARENB
;
420 else if (!strcasecmp(value
, "mark"))
423 * Note: we only support mark parity with 7 bits per character
427 opts
.c_cflag
&= ~CSIZE
;
429 opts
.c_cflag
&= ~PARENB
;
430 opts
.c_cflag
|= CSTOPB
;
433 else if (!strcasecmp(name
, "flow"))
436 * Set flow control...
439 if (!strcasecmp(value
, "none"))
441 opts
.c_iflag
&= ~(IXON
| IXOFF
);
442 opts
.c_cflag
&= ~CRTSCTS
;
444 else if (!strcasecmp(value
, "soft"))
446 opts
.c_iflag
|= IXON
| IXOFF
;
447 opts
.c_cflag
&= ~CRTSCTS
;
449 else if (!strcasecmp(value
, "hard") ||
450 !strcasecmp(value
, "rtscts"))
452 opts
.c_iflag
&= ~(IXON
| IXOFF
);
453 opts
.c_cflag
|= CRTSCTS
;
455 else if (!strcasecmp(value
, "dtrdsr"))
457 opts
.c_iflag
&= ~(IXON
| IXOFF
);
458 opts
.c_cflag
&= ~CRTSCTS
;
463 else if (!strcasecmp(name
, "stop"))
468 opts
.c_cflag
&= ~CSTOPB
;
472 opts
.c_cflag
|= CSTOPB
;
478 tcsetattr(fd
, TCSANOW
, &opts
);
479 fcntl(fd
, F_SETFL
, 0);
482 * Now that we are "connected" to the port, ignore SIGTERM so that we
483 * can finish out any page data the driver sends (e.g. to eject the
484 * current page... Only ignore SIGTERM if we are printing data from
485 * stdin (otherwise you can't cancel raw jobs...)
490 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
491 sigset(SIGTERM
, SIG_IGN
);
492 #elif defined(HAVE_SIGACTION)
493 memset(&action
, 0, sizeof(action
));
495 sigemptyset(&action
.sa_mask
);
496 action
.sa_handler
= SIG_IGN
;
497 sigaction(SIGTERM
, &action
, NULL
);
499 signal(SIGTERM
, SIG_IGN
);
500 #endif /* HAVE_SIGSET */
504 * Finally, send the print file...
507 if (bufsize
> sizeof(buffer
))
508 bufsize
= sizeof(buffer
);
518 fputs("PAGE: 1 1\n", stderr
);
519 lseek(fp
, 0, SEEK_SET
);
525 * Check the port and sleep until DSR is set...
531 if (!ioctl(fd
, TIOCMGET
, &status
))
532 if (!(status
& TIOCM_DSR
))
535 * Wait for DSR to go high...
538 fputs("DEBUG: DSR is low; waiting for device...\n", stderr
);
543 if (ioctl(fd
, TIOCMGET
, &status
))
546 while (!(status
& TIOCM_DSR
));
548 fputs("DEBUG: DSR is high; writing to device...\n", stderr
);
553 while ((nbytes
= read(fp
, buffer
, bufsize
)) > 0)
556 * Write the print data to the printer...
565 * See if we are ready to read or write...
575 while (select(fd
+ 1, &input
, &output
, NULL
, NULL
) < 0);
577 if (FD_ISSET(fd
, &input
))
580 * Read backchannel data...
583 if ((rbytes
= read(fd
, resource
, sizeof(resource
))) > 0)
585 fprintf(stderr
, "DEBUG: Received %d bytes of back-channel data!\n",
587 cupsBackchannelWrite(resource
, rbytes
, 1.0);
591 if (FD_ISSET(fd
, &output
))
594 * Write print data...
597 if ((wbytes
= write(fd
, bufptr
, nbytes
)) < 0)
599 wbytes
= write(fd
, bufptr
, nbytes
);
604 * Check for retryable errors...
607 if (errno
!= EAGAIN
&& errno
!= EINTR
)
609 perror("ERROR: Unable to send print file to printer");
616 * Update count and pointer...
629 fprintf(stderr
, "INFO: Sending print file, %lu bytes...\n",
630 (unsigned long)tbytes
);
635 * Close the serial port and input file and return...
638 tcsetattr(fd
, TCSADRAIN
, &origopts
);
644 return (wbytes
< 0 ? CUPS_BACKEND_FAILED
: CUPS_BACKEND_OK
);
649 * 'list_devices()' - List all serial devices.
655 #if defined(__hpux) || defined(__sgi) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__)
656 static char *funky_hex
= "0123456789abcdefghijklmnopqrstuvwxyz";
657 /* Funky hex numbering used for some devices */
658 #endif /* __hpux || __sgi || __sun || __FreeBSD__ || __OpenBSD__ */
660 #if defined(__linux) || defined(linux) || defined(__linux__)
661 int i
; /* Looping var */
662 int fd
; /* File descriptor */
663 char device
[255]; /* Device filename */
666 for (i
= 0; i
< 100; i
++)
668 sprintf(device
, "/dev/ttyS%d", i
);
669 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
672 # if defined(_ARCH_PPC) || defined(powerpc) || defined(__powerpc)
673 printf("serial serial:%s?baud=230400 \"Unknown\" \"Serial Port #%d\"\n",
676 printf("serial serial:%s?baud=115200 \"Unknown\" \"Serial Port #%d\"\n",
678 # endif /* _ARCH_PPC || powerpc || __powerpc */
682 for (i
= 0; i
< 16; i
++)
684 sprintf(device
, "/dev/usb/ttyUSB%d", i
);
685 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
688 printf("serial serial:%s?baud=230400 \"Unknown\" \"USB Serial Port #%d\"\n",
693 int i
, j
, n
; /* Looping vars */
694 char device
[255]; /* Device filename */
695 inventory_t
*inv
; /* Hardware inventory info */
699 * IRIX maintains a hardware inventory of most devices...
704 while ((inv
= getinvent()) != NULL
)
706 if (inv
->inv_class
== INV_SERIAL
)
709 * Some sort of serial port...
712 if (inv
->inv_type
== INV_CDSIO
|| inv
->inv_type
== INV_CDSIO_E
)
718 for (n
= 0; n
< 6; n
++)
719 printf("serial serial:/dev/ttyd%d?baud=38400 \"Unknown\" \"CDSIO Board %d Serial Port #%d\"\n",
720 n
+ 5 + 8 * inv
->inv_controller
, inv
->inv_controller
, n
+ 1);
722 else if (inv
->inv_type
== INV_EPC_SERIAL
)
725 * Everest serial port...
728 if (inv
->inv_unit
== 0)
731 i
= 41 + 4 * (int)inv
->inv_controller
;
733 for (n
= 0; n
< (int)inv
->inv_state
; n
++)
734 printf("serial serial:/dev/ttyd%d?baud=38400 \"Unknown\" \"EPC Serial Port %d, Ebus slot %d\"\n",
735 n
+ i
, n
+ 1, (int)inv
->inv_controller
);
737 else if (inv
->inv_state
> 1)
740 * Standard serial port under IRIX 6.4 and earlier...
743 for (n
= 0; n
< (int)inv
->inv_state
; n
++)
744 printf("serial serial:/dev/ttyd%d?baud=38400 \"Unknown\" \"Onboard Serial Port %d\"\n",
745 n
+ (int)inv
->inv_unit
+ 1, n
+ (int)inv
->inv_unit
+ 1);
750 * Standard serial port under IRIX 6.5 and beyond...
753 printf("serial serial:/dev/ttyd%d?baud=115200 \"Unknown\" \"Onboard Serial Port %d\"\n",
754 (int)inv
->inv_controller
, (int)inv
->inv_controller
);
762 * Central Data makes serial and parallel "servers" that can be
763 * connected in a number of ways. Look for ports...
766 for (i
= 0; i
< 10; i
++)
767 for (j
= 0; j
< 8; j
++)
768 for (n
= 0; n
< 32; n
++)
770 if (i
== 8) /* EtherLite */
771 sprintf(device
, "/dev/ttydn%d%c", j
, funky_hex
[n
]);
772 else if (i
== 9) /* PCI */
773 sprintf(device
, "/dev/ttydp%d%c", j
, funky_hex
[n
]);
775 sprintf(device
, "/dev/ttyd%d%d%c", i
, j
, funky_hex
[n
]);
777 if (access(device
, 0) == 0)
780 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data EtherLite Serial Port, ID %d, port %d\"\n",
783 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data PCI Serial Port, ID %d, port %d\"\n",
786 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data SCSI Serial Port, logical bus %d, ID %d, port %d\"\n",
791 int i
, j
, n
; /* Looping vars */
792 char device
[255]; /* Device filename */
796 * Standard serial ports...
799 for (i
= 0; i
< 26; i
++)
801 sprintf(device
, "/dev/cua/%c", 'a' + i
);
802 if (access(device
, 0) == 0)
804 printf("serial serial:%s?baud=115200 \"Unknown\" \"Serial Port #%d\"\n",
807 printf("serial serial:%s?baud=38400 \"Unknown\" \"Serial Port #%d\"\n",
813 * MAGMA serial ports...
816 for (i
= 0; i
< 40; i
++)
818 sprintf(device
, "/dev/term/%02d", i
);
819 if (access(device
, 0) == 0)
820 printf("serial serial:%s?baud=38400 \"Unknown\" \"MAGMA Serial Board #%d Port #%d\"\n",
821 device
, (i
/ 10) + 1, (i
% 10) + 1);
825 * Central Data serial ports...
828 for (i
= 0; i
< 9; i
++)
829 for (j
= 0; j
< 8; j
++)
830 for (n
= 0; n
< 32; n
++)
832 if (i
== 8) /* EtherLite */
833 sprintf(device
, "/dev/sts/ttyN%d%c", j
, funky_hex
[n
]);
835 sprintf(device
, "/dev/sts/tty%c%d%c", i
+ 'C', j
,
838 if (access(device
, 0) == 0)
841 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data EtherLite Serial Port, ID %d, port %d\"\n",
844 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data SCSI Serial Port, logical bus %d, ID %d, port %d\"\n",
848 #elif defined(__hpux)
849 int i
, j
, n
; /* Looping vars */
850 char device
[255]; /* Device filename */
854 * Standard serial ports...
857 for (i
= 0; i
< 10; i
++)
859 sprintf(device
, "/dev/tty%dp0", i
);
860 if (access(device
, 0) == 0)
861 printf("serial serial:%s?baud=38400 \"Unknown\" \"Serial Port #%d\"\n",
866 * Central Data serial ports...
869 for (i
= 0; i
< 9; i
++)
870 for (j
= 0; j
< 8; j
++)
871 for (n
= 0; n
< 32; n
++)
873 if (i
== 8) /* EtherLite */
874 sprintf(device
, "/dev/ttyN%d%c", j
, funky_hex
[n
]);
876 sprintf(device
, "/dev/tty%c%d%c", i
+ 'C', j
,
879 if (access(device
, 0) == 0)
882 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data EtherLite Serial Port, ID %d, port %d\"\n",
885 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data SCSI Serial Port, logical bus %d, ID %d, port %d\"\n",
889 #elif defined(__osf__)
890 int i
; /* Looping var */
891 char device
[255]; /* Device filename */
895 * Standard serial ports...
898 for (i
= 0; i
< 100; i
++)
900 sprintf(device
, "/dev/tty%02d", i
);
901 if (access(device
, 0) == 0)
902 printf("serial serial:%s?baud=38400 \"Unknown\" \"Serial Port #%d\"\n",
905 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
906 int i
, j
; /* Looping vars */
907 int fd
; /* File descriptor */
908 char device
[255]; /* Device filename */
915 for (i
= 0; i
< 32; i
++)
917 sprintf(device
, "/dev/ttyd%c", funky_hex
[i
]);
918 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
921 printf("serial serial:%s?baud=115200 \"Unknown\" \"Standard Serial Port #%d\"\n",
930 for (i
= 0; i
< 16; i
++) /* Should be up to 65536 boards... */
931 for (j
= 0; j
< 32; j
++)
933 sprintf(device
, "/dev/ttyc%d%c", i
, funky_hex
[j
]);
934 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
937 printf("serial serial:%s?baud=115200 \"Unknown\" \"Cyclades #%d Serial Port #%d\"\n",
941 sprintf(device
, "/dev/ttyC%d%c", i
, funky_hex
[j
]);
942 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
945 printf("serial serial:%s?baud=115200 \"Unknown\" \"Cyclades #%d Serial Port #%d\"\n",
954 for (i
= 0; i
< 16; i
++) /* Should be up to 65536 boards... */
955 for (j
= 0; j
< 32; j
++)
957 sprintf(device
, "/dev/ttyD%d%c", i
, funky_hex
[j
]);
958 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
961 printf("serial serial:%s?baud=115200 \"Unknown\" \"Digiboard #%d Serial Port #%d\"\n",
970 for (i
= 0; i
< 32; i
++)
972 sprintf(device
, "/dev/ttyE%c", funky_hex
[i
]);
973 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
976 printf("serial serial:%s?baud=115200 \"Unknown\" \"Stallion Serial Port #%d\"\n",
985 for (i
= 0; i
< 128; i
++)
987 sprintf(device
, "/dev/ttyA%d", i
+ 1);
988 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
991 printf("serial serial:%s?baud=115200 \"Unknown\" \"SX Serial Port #%d\"\n",
995 #elif defined(__NetBSD__)
996 int i
, j
; /* Looping vars */
997 int fd
; /* File descriptor */
998 char device
[255]; /* Device filename */
1002 * Standard serial ports...
1005 for (i
= 0; i
< 4; i
++)
1007 sprintf(device
, "/dev/tty%02d", i
);
1008 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
1011 printf("serial serial:%s?baud=115200 \"Unknown\" \"Serial Port #%d\"\n",
1017 * Cyclades-Z ports...
1020 for (i
= 0; i
< 16; i
++) /* Should be up to 65536 boards... */
1021 for (j
= 0; j
< 64; j
++)
1023 sprintf(device
, "/dev/ttyCZ%02d%02d", i
, j
);
1024 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
1027 printf("serial serial:%s?baud=115200 \"Unknown\" \"Cyclades #%d Serial Prt #%d\"\n",
1031 #elif defined(__APPLE__)
1033 * Standard serial ports on MacOS X...
1036 kern_return_t kernResult
;
1037 mach_port_t masterPort
;
1038 io_iterator_t serialPortIterator
;
1039 CFMutableDictionaryRef classesToMatch
;
1040 io_object_t serialService
;
1042 printf("serial serial \"Unknown\" \"Serial Printer (serial)\"\n");
1044 kernResult
= IOMasterPort(MACH_PORT_NULL
, &masterPort
);
1045 if (KERN_SUCCESS
!= kernResult
)
1049 * Serial devices are instances of class IOSerialBSDClient.
1052 classesToMatch
= IOServiceMatching(kIOSerialBSDServiceValue
);
1053 if (classesToMatch
!= NULL
)
1055 CFDictionarySetValue(classesToMatch
, CFSTR(kIOSerialBSDTypeKey
),
1056 CFSTR(kIOSerialBSDRS232Type
));
1058 kernResult
= IOServiceGetMatchingServices(masterPort
, classesToMatch
,
1059 &serialPortIterator
);
1060 if (kernResult
== KERN_SUCCESS
)
1062 while ((serialService
= IOIteratorNext(serialPortIterator
)))
1064 CFTypeRef serialNameAsCFString
;
1065 CFTypeRef bsdPathAsCFString
;
1066 char serialName
[128];
1071 serialNameAsCFString
=
1072 IORegistryEntryCreateCFProperty(serialService
,
1073 CFSTR(kIOTTYDeviceKey
),
1074 kCFAllocatorDefault
, 0);
1075 if (serialNameAsCFString
)
1077 result
= CFStringGetCString(serialNameAsCFString
, serialName
,
1079 kCFStringEncodingASCII
);
1080 CFRelease(serialNameAsCFString
);
1085 IORegistryEntryCreateCFProperty(serialService
,
1086 CFSTR(kIOCalloutDeviceKey
),
1087 kCFAllocatorDefault
, 0);
1088 if (bsdPathAsCFString
)
1090 result
= CFStringGetCString(bsdPathAsCFString
, bsdPath
,
1092 kCFStringEncodingASCII
);
1093 CFRelease(bsdPathAsCFString
);
1096 printf("serial serial:%s?baud=115200 \"Unknown\" \"%s\"\n", bsdPath
,
1102 IOObjectRelease(serialService
);
1105 IOObjectRelease(serialPortIterator
); /* Release the iterator. */
1113 * End of "$Id: serial.c 4906 2006-01-10 20:53:28Z mike $".