2 * "$Id: serial.c 5099 2006-02-13 02:46:10Z 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(HTTP_URI_CODING_ALL
, cupsBackendDeviceURI(argv
),
200 method
, sizeof(method
), username
, sizeof(username
),
201 hostname
, sizeof(hostname
), &port
,
202 resource
, sizeof(resource
));
205 * See if there are any options...
208 if ((options
= strchr(resource
, '?')) != NULL
)
211 * Yup, terminate the device name string and move to the first
212 * character of the options...
219 * Open the serial port device...
224 if ((fd
= open(resource
, O_WRONLY
| O_NOCTTY
| O_EXCL
| O_NDELAY
)) == -1)
226 if (getenv("CLASS") != NULL
)
229 * If the CLASS environment variable is set, the job was submitted
230 * to a class and not to a specific queue. In this case, we want
231 * to abort immediately so that the job can be requeued on the next
232 * available printer in the class.
235 fputs("INFO: Unable to open serial port, queuing on next printer in class...\n",
239 * Sleep 5 seconds to keep the job from requeuing too rapidly...
244 return (CUPS_BACKEND_FAILED
);
249 fputs("INFO: Serial port busy; will retry in 30 seconds...\n", stderr
);
254 fprintf(stderr
, "ERROR: Unable to open serial port device file \"%s\": %s\n",
255 resource
, strerror(errno
));
256 return (CUPS_BACKEND_FAILED
);
263 * Set any options provided...
266 tcgetattr(fd
, &origopts
);
267 tcgetattr(fd
, &opts
);
269 opts
.c_lflag
&= ~(ICANON
| ECHO
| ISIG
); /* Raw mode */
270 opts
.c_oflag
&= ~OPOST
; /* Don't post-process */
272 bufsize
= 96; /* 9600 baud / 10 bits/char / 10Hz */
273 dtrdsr
= 0; /* No dtr/dsr flow control */
282 for (ptr
= name
; *options
&& *options
!= '=';)
283 if (ptr
< (name
+ sizeof(name
) - 1))
295 for (ptr
= value
; *options
&& *options
!= '+' && *options
!= '&';)
296 if (ptr
< (value
+ sizeof(value
) - 1))
307 * Process the option...
310 if (!strcasecmp(name
, "baud"))
313 * Set the baud rate...
316 bufsize
= atoi(value
) / 100;
319 cfsetispeed(&opts
, atoi(value
));
320 cfsetospeed(&opts
, atoi(value
));
325 cfsetispeed(&opts
, B1200
);
326 cfsetospeed(&opts
, B1200
);
329 cfsetispeed(&opts
, B2400
);
330 cfsetospeed(&opts
, B2400
);
333 cfsetispeed(&opts
, B4800
);
334 cfsetospeed(&opts
, B4800
);
337 cfsetispeed(&opts
, B9600
);
338 cfsetospeed(&opts
, B9600
);
341 cfsetispeed(&opts
, B19200
);
342 cfsetospeed(&opts
, B19200
);
345 cfsetispeed(&opts
, B38400
);
346 cfsetospeed(&opts
, B38400
);
350 cfsetispeed(&opts
, B57600
);
351 cfsetospeed(&opts
, B57600
);
356 cfsetispeed(&opts
, B115200
);
357 cfsetospeed(&opts
, B115200
);
359 # endif /* B115200 */
362 cfsetispeed(&opts
, B230400
);
363 cfsetospeed(&opts
, B230400
);
365 # endif /* B230400 */
367 fprintf(stderr
, "WARNING: Unsupported baud rate %s!\n", value
);
370 #endif /* B19200 == 19200 */
372 else if (!strcasecmp(name
, "bits"))
375 * Set number of data bits...
381 opts
.c_cflag
&= ~CSIZE
;
383 opts
.c_cflag
|= PARENB
;
384 opts
.c_cflag
&= ~PARODD
;
387 opts
.c_cflag
&= ~CSIZE
;
389 opts
.c_cflag
&= ~PARENB
;
393 else if (!strcasecmp(name
, "parity"))
396 * Set parity checking...
399 if (!strcasecmp(value
, "even"))
401 opts
.c_cflag
|= PARENB
;
402 opts
.c_cflag
&= ~PARODD
;
404 else if (!strcasecmp(value
, "odd"))
406 opts
.c_cflag
|= PARENB
;
407 opts
.c_cflag
|= PARODD
;
409 else if (!strcasecmp(value
, "none"))
410 opts
.c_cflag
&= ~PARENB
;
411 else if (!strcasecmp(value
, "space"))
414 * Note: we only support space parity with 7 bits per character...
417 opts
.c_cflag
&= ~CSIZE
;
419 opts
.c_cflag
&= ~PARENB
;
421 else if (!strcasecmp(value
, "mark"))
424 * Note: we only support mark parity with 7 bits per character
428 opts
.c_cflag
&= ~CSIZE
;
430 opts
.c_cflag
&= ~PARENB
;
431 opts
.c_cflag
|= CSTOPB
;
434 else if (!strcasecmp(name
, "flow"))
437 * Set flow control...
440 if (!strcasecmp(value
, "none"))
442 opts
.c_iflag
&= ~(IXON
| IXOFF
);
443 opts
.c_cflag
&= ~CRTSCTS
;
445 else if (!strcasecmp(value
, "soft"))
447 opts
.c_iflag
|= IXON
| IXOFF
;
448 opts
.c_cflag
&= ~CRTSCTS
;
450 else if (!strcasecmp(value
, "hard") ||
451 !strcasecmp(value
, "rtscts"))
453 opts
.c_iflag
&= ~(IXON
| IXOFF
);
454 opts
.c_cflag
|= CRTSCTS
;
456 else if (!strcasecmp(value
, "dtrdsr"))
458 opts
.c_iflag
&= ~(IXON
| IXOFF
);
459 opts
.c_cflag
&= ~CRTSCTS
;
464 else if (!strcasecmp(name
, "stop"))
469 opts
.c_cflag
&= ~CSTOPB
;
473 opts
.c_cflag
|= CSTOPB
;
479 tcsetattr(fd
, TCSANOW
, &opts
);
480 fcntl(fd
, F_SETFL
, 0);
483 * Now that we are "connected" to the port, ignore SIGTERM so that we
484 * can finish out any page data the driver sends (e.g. to eject the
485 * current page... Only ignore SIGTERM if we are printing data from
486 * stdin (otherwise you can't cancel raw jobs...)
491 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
492 sigset(SIGTERM
, SIG_IGN
);
493 #elif defined(HAVE_SIGACTION)
494 memset(&action
, 0, sizeof(action
));
496 sigemptyset(&action
.sa_mask
);
497 action
.sa_handler
= SIG_IGN
;
498 sigaction(SIGTERM
, &action
, NULL
);
500 signal(SIGTERM
, SIG_IGN
);
501 #endif /* HAVE_SIGSET */
505 * Finally, send the print file...
508 if (bufsize
> sizeof(buffer
))
509 bufsize
= sizeof(buffer
);
519 fputs("PAGE: 1 1\n", stderr
);
520 lseek(fp
, 0, SEEK_SET
);
526 * Check the port and sleep until DSR is set...
532 if (!ioctl(fd
, TIOCMGET
, &status
))
533 if (!(status
& TIOCM_DSR
))
536 * Wait for DSR to go high...
539 fputs("DEBUG: DSR is low; waiting for device...\n", stderr
);
544 if (ioctl(fd
, TIOCMGET
, &status
))
547 while (!(status
& TIOCM_DSR
));
549 fputs("DEBUG: DSR is high; writing to device...\n", stderr
);
554 while ((nbytes
= read(fp
, buffer
, bufsize
)) > 0)
557 * Write the print data to the printer...
566 * See if we are ready to read or write...
576 while (select(fd
+ 1, &input
, &output
, NULL
, NULL
) < 0);
578 if (FD_ISSET(fd
, &input
))
581 * Read backchannel data...
584 if ((rbytes
= read(fd
, resource
, sizeof(resource
))) > 0)
586 fprintf(stderr
, "DEBUG: Received %d bytes of back-channel data!\n",
588 cupsBackChannelWrite(resource
, rbytes
, 1.0);
592 if (FD_ISSET(fd
, &output
))
595 * Write print data...
598 if ((wbytes
= write(fd
, bufptr
, nbytes
)) < 0)
600 wbytes
= write(fd
, bufptr
, nbytes
);
605 * Check for retryable errors...
608 if (errno
!= EAGAIN
&& errno
!= EINTR
)
610 perror("ERROR: Unable to send print file to printer");
617 * Update count and pointer...
630 fprintf(stderr
, "INFO: Sending print file, %lu bytes...\n",
631 (unsigned long)tbytes
);
636 * Close the serial port and input file and return...
639 tcsetattr(fd
, TCSADRAIN
, &origopts
);
645 return (wbytes
< 0 ? CUPS_BACKEND_FAILED
: CUPS_BACKEND_OK
);
650 * 'list_devices()' - List all serial devices.
656 #if defined(__hpux) || defined(__sgi) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__)
657 static char *funky_hex
= "0123456789abcdefghijklmnopqrstuvwxyz";
658 /* Funky hex numbering used for some devices */
659 #endif /* __hpux || __sgi || __sun || __FreeBSD__ || __OpenBSD__ */
661 #if defined(__linux) || defined(linux) || defined(__linux__)
662 int i
; /* Looping var */
663 int fd
; /* File descriptor */
664 char device
[255]; /* Device filename */
667 for (i
= 0; i
< 100; i
++)
669 sprintf(device
, "/dev/ttyS%d", i
);
670 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
673 # if defined(_ARCH_PPC) || defined(powerpc) || defined(__powerpc)
674 printf("serial serial:%s?baud=230400 \"Unknown\" \"Serial Port #%d\"\n",
677 printf("serial serial:%s?baud=115200 \"Unknown\" \"Serial Port #%d\"\n",
679 # endif /* _ARCH_PPC || powerpc || __powerpc */
683 for (i
= 0; i
< 16; i
++)
685 sprintf(device
, "/dev/usb/ttyUSB%d", i
);
686 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
689 printf("serial serial:%s?baud=230400 \"Unknown\" \"USB Serial Port #%d\"\n",
694 int i
, j
, n
; /* Looping vars */
695 char device
[255]; /* Device filename */
696 inventory_t
*inv
; /* Hardware inventory info */
700 * IRIX maintains a hardware inventory of most devices...
705 while ((inv
= getinvent()) != NULL
)
707 if (inv
->inv_class
== INV_SERIAL
)
710 * Some sort of serial port...
713 if (inv
->inv_type
== INV_CDSIO
|| inv
->inv_type
== INV_CDSIO_E
)
719 for (n
= 0; n
< 6; n
++)
720 printf("serial serial:/dev/ttyd%d?baud=38400 \"Unknown\" \"CDSIO Board %d Serial Port #%d\"\n",
721 n
+ 5 + 8 * inv
->inv_controller
, inv
->inv_controller
, n
+ 1);
723 else if (inv
->inv_type
== INV_EPC_SERIAL
)
726 * Everest serial port...
729 if (inv
->inv_unit
== 0)
732 i
= 41 + 4 * (int)inv
->inv_controller
;
734 for (n
= 0; n
< (int)inv
->inv_state
; n
++)
735 printf("serial serial:/dev/ttyd%d?baud=38400 \"Unknown\" \"EPC Serial Port %d, Ebus slot %d\"\n",
736 n
+ i
, n
+ 1, (int)inv
->inv_controller
);
738 else if (inv
->inv_state
> 1)
741 * Standard serial port under IRIX 6.4 and earlier...
744 for (n
= 0; n
< (int)inv
->inv_state
; n
++)
745 printf("serial serial:/dev/ttyd%d?baud=38400 \"Unknown\" \"Onboard Serial Port %d\"\n",
746 n
+ (int)inv
->inv_unit
+ 1, n
+ (int)inv
->inv_unit
+ 1);
751 * Standard serial port under IRIX 6.5 and beyond...
754 printf("serial serial:/dev/ttyd%d?baud=115200 \"Unknown\" \"Onboard Serial Port %d\"\n",
755 (int)inv
->inv_controller
, (int)inv
->inv_controller
);
763 * Central Data makes serial and parallel "servers" that can be
764 * connected in a number of ways. Look for ports...
767 for (i
= 0; i
< 10; i
++)
768 for (j
= 0; j
< 8; j
++)
769 for (n
= 0; n
< 32; n
++)
771 if (i
== 8) /* EtherLite */
772 sprintf(device
, "/dev/ttydn%d%c", j
, funky_hex
[n
]);
773 else if (i
== 9) /* PCI */
774 sprintf(device
, "/dev/ttydp%d%c", j
, funky_hex
[n
]);
776 sprintf(device
, "/dev/ttyd%d%d%c", i
, j
, funky_hex
[n
]);
778 if (access(device
, 0) == 0)
781 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data EtherLite Serial Port, ID %d, port %d\"\n",
784 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data PCI Serial Port, ID %d, port %d\"\n",
787 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data SCSI Serial Port, logical bus %d, ID %d, port %d\"\n",
792 int i
, j
, n
; /* Looping vars */
793 char device
[255]; /* Device filename */
797 * Standard serial ports...
800 for (i
= 0; i
< 26; i
++)
802 sprintf(device
, "/dev/cua/%c", 'a' + i
);
803 if (access(device
, 0) == 0)
805 printf("serial serial:%s?baud=115200 \"Unknown\" \"Serial Port #%d\"\n",
808 printf("serial serial:%s?baud=38400 \"Unknown\" \"Serial Port #%d\"\n",
814 * MAGMA serial ports...
817 for (i
= 0; i
< 40; i
++)
819 sprintf(device
, "/dev/term/%02d", i
);
820 if (access(device
, 0) == 0)
821 printf("serial serial:%s?baud=38400 \"Unknown\" \"MAGMA Serial Board #%d Port #%d\"\n",
822 device
, (i
/ 10) + 1, (i
% 10) + 1);
826 * Central Data serial ports...
829 for (i
= 0; i
< 9; i
++)
830 for (j
= 0; j
< 8; j
++)
831 for (n
= 0; n
< 32; n
++)
833 if (i
== 8) /* EtherLite */
834 sprintf(device
, "/dev/sts/ttyN%d%c", j
, funky_hex
[n
]);
836 sprintf(device
, "/dev/sts/tty%c%d%c", i
+ 'C', j
,
839 if (access(device
, 0) == 0)
842 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data EtherLite Serial Port, ID %d, port %d\"\n",
845 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data SCSI Serial Port, logical bus %d, ID %d, port %d\"\n",
849 #elif defined(__hpux)
850 int i
, j
, n
; /* Looping vars */
851 char device
[255]; /* Device filename */
855 * Standard serial ports...
858 for (i
= 0; i
< 10; i
++)
860 sprintf(device
, "/dev/tty%dp0", i
);
861 if (access(device
, 0) == 0)
862 printf("serial serial:%s?baud=38400 \"Unknown\" \"Serial Port #%d\"\n",
867 * Central Data serial ports...
870 for (i
= 0; i
< 9; i
++)
871 for (j
= 0; j
< 8; j
++)
872 for (n
= 0; n
< 32; n
++)
874 if (i
== 8) /* EtherLite */
875 sprintf(device
, "/dev/ttyN%d%c", j
, funky_hex
[n
]);
877 sprintf(device
, "/dev/tty%c%d%c", i
+ 'C', j
,
880 if (access(device
, 0) == 0)
883 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data EtherLite Serial Port, ID %d, port %d\"\n",
886 printf("serial serial:%s?baud=38400 \"Unknown\" \"Central Data SCSI Serial Port, logical bus %d, ID %d, port %d\"\n",
890 #elif defined(__osf__)
891 int i
; /* Looping var */
892 char device
[255]; /* Device filename */
896 * Standard serial ports...
899 for (i
= 0; i
< 100; i
++)
901 sprintf(device
, "/dev/tty%02d", i
);
902 if (access(device
, 0) == 0)
903 printf("serial serial:%s?baud=38400 \"Unknown\" \"Serial Port #%d\"\n",
906 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
907 int i
, j
; /* Looping vars */
908 int fd
; /* File descriptor */
909 char device
[255]; /* Device filename */
916 for (i
= 0; i
< 32; i
++)
918 sprintf(device
, "/dev/ttyd%c", funky_hex
[i
]);
919 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
922 printf("serial serial:%s?baud=115200 \"Unknown\" \"Standard Serial Port #%d\"\n",
931 for (i
= 0; i
< 16; i
++) /* Should be up to 65536 boards... */
932 for (j
= 0; j
< 32; j
++)
934 sprintf(device
, "/dev/ttyc%d%c", i
, funky_hex
[j
]);
935 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
938 printf("serial serial:%s?baud=115200 \"Unknown\" \"Cyclades #%d Serial Port #%d\"\n",
942 sprintf(device
, "/dev/ttyC%d%c", i
, funky_hex
[j
]);
943 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
946 printf("serial serial:%s?baud=115200 \"Unknown\" \"Cyclades #%d Serial Port #%d\"\n",
955 for (i
= 0; i
< 16; i
++) /* Should be up to 65536 boards... */
956 for (j
= 0; j
< 32; j
++)
958 sprintf(device
, "/dev/ttyD%d%c", i
, funky_hex
[j
]);
959 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
962 printf("serial serial:%s?baud=115200 \"Unknown\" \"Digiboard #%d Serial Port #%d\"\n",
971 for (i
= 0; i
< 32; i
++)
973 sprintf(device
, "/dev/ttyE%c", funky_hex
[i
]);
974 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
977 printf("serial serial:%s?baud=115200 \"Unknown\" \"Stallion Serial Port #%d\"\n",
986 for (i
= 0; i
< 128; i
++)
988 sprintf(device
, "/dev/ttyA%d", i
+ 1);
989 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
992 printf("serial serial:%s?baud=115200 \"Unknown\" \"SX Serial Port #%d\"\n",
996 #elif defined(__NetBSD__)
997 int i
, j
; /* Looping vars */
998 int fd
; /* File descriptor */
999 char device
[255]; /* Device filename */
1003 * Standard serial ports...
1006 for (i
= 0; i
< 4; i
++)
1008 sprintf(device
, "/dev/tty%02d", i
);
1009 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
1012 printf("serial serial:%s?baud=115200 \"Unknown\" \"Serial Port #%d\"\n",
1018 * Cyclades-Z ports...
1021 for (i
= 0; i
< 16; i
++) /* Should be up to 65536 boards... */
1022 for (j
= 0; j
< 64; j
++)
1024 sprintf(device
, "/dev/ttyCZ%02d%02d", i
, j
);
1025 if ((fd
= open(device
, O_WRONLY
| O_NOCTTY
| O_NDELAY
)) >= 0)
1028 printf("serial serial:%s?baud=115200 \"Unknown\" \"Cyclades #%d Serial Prt #%d\"\n",
1032 #elif defined(__APPLE__)
1034 * Standard serial ports on MacOS X...
1037 kern_return_t kernResult
;
1038 mach_port_t masterPort
;
1039 io_iterator_t serialPortIterator
;
1040 CFMutableDictionaryRef classesToMatch
;
1041 io_object_t serialService
;
1043 printf("serial serial \"Unknown\" \"Serial Printer (serial)\"\n");
1045 kernResult
= IOMasterPort(MACH_PORT_NULL
, &masterPort
);
1046 if (KERN_SUCCESS
!= kernResult
)
1050 * Serial devices are instances of class IOSerialBSDClient.
1053 classesToMatch
= IOServiceMatching(kIOSerialBSDServiceValue
);
1054 if (classesToMatch
!= NULL
)
1056 CFDictionarySetValue(classesToMatch
, CFSTR(kIOSerialBSDTypeKey
),
1057 CFSTR(kIOSerialBSDRS232Type
));
1059 kernResult
= IOServiceGetMatchingServices(masterPort
, classesToMatch
,
1060 &serialPortIterator
);
1061 if (kernResult
== KERN_SUCCESS
)
1063 while ((serialService
= IOIteratorNext(serialPortIterator
)))
1065 CFTypeRef serialNameAsCFString
;
1066 CFTypeRef bsdPathAsCFString
;
1067 char serialName
[128];
1072 serialNameAsCFString
=
1073 IORegistryEntryCreateCFProperty(serialService
,
1074 CFSTR(kIOTTYDeviceKey
),
1075 kCFAllocatorDefault
, 0);
1076 if (serialNameAsCFString
)
1078 result
= CFStringGetCString(serialNameAsCFString
, serialName
,
1080 kCFStringEncodingASCII
);
1081 CFRelease(serialNameAsCFString
);
1086 IORegistryEntryCreateCFProperty(serialService
,
1087 CFSTR(kIOCalloutDeviceKey
),
1088 kCFAllocatorDefault
, 0);
1089 if (bsdPathAsCFString
)
1091 result
= CFStringGetCString(bsdPathAsCFString
, bsdPath
,
1093 kCFStringEncodingASCII
);
1094 CFRelease(bsdPathAsCFString
);
1097 printf("serial serial:%s?baud=115200 \"Unknown\" \"%s\"\n", bsdPath
,
1103 IOObjectRelease(serialService
);
1106 IOObjectRelease(serialPortIterator
); /* Release the iterator. */
1114 * End of "$Id: serial.c 5099 2006-02-13 02:46:10Z mike $".