Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!sri-unix!hplabs!hp-sdd!ucsdhub!sdcsvax!nosc!cod!bmarsh From: bmarsh@cod.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: Need help with MS-DOS 3.1 and COM1 device Message-ID: <476@cod.UUCP> Date: Thu, 29-Jan-87 11:12:42 EST Article-I.D.: cod.476 Posted: Thu Jan 29 11:12:42 1987 Date-Received: Sat, 31-Jan-87 04:25:05 EST References: <3281@hplabs.hplabs.UUCP> Organization: Naval Ocean Systems Center, San Diego Lines: 78 Summary: Here is how to set binary mode... In article <3281@hplabs.hplabs.UUCP> drichard@hplabs.UUCP (Dave Richards) writes: > >I have written a DVI to HP LaserJet+ Driver that runs under both Unix >and MS/PC-DOS. Unfortunately, I have discovered a problem either in the >Aztec C Run-time support, (which they deny), or a problem with MS-DOS, >(a misunderstanding, no doubt). > > It sounds like the handle must be placed in raw mode, or >something synonymous. Unfortunately, I do not know how to do this, and >the programmer's manual for MS-DOS is not too helpful. > > Dave Richards at Hewlett-Packard Labs (drichard@hplabs) Whenever a device is opened, it is opened in ASCII mode, and not BINARY mode. A normal disk file is opened in BINARY mode. This is why, when your program had it's output redirected, everything worked properly. To set the file handle to BINARY an IOCTL call (DOS call 44H) must be used. A simple example (in microsoft C, unfortunatly) is shown below. Hope this helps out. ------------ #include main() { blah(); blah(); blah(); /* Note that the file handle should be opened in C's binary mode so LF's don't get mapped to CR-LF's */ fd = fopen("COM1", "wb"); /* or any device... */ setraw(fileno(fd)); blah(); setcooked(fileno(fd)); blah(); blah(); } setraw(handle) int handle; { union REGS regs; regs.x.ax = 0x4400; /* IOCTL get parameters */ regs.x.bx = handle; /* file handle */ intdos(®s, ®s); /* get the current set up */ regs.h.dh = 0; /* DH must be cleared */ regs.h.dl |= 0x20; /* Turn on binary bit */ regs.x.ax = 0x4401; /* IOCTL set parameters */ intdos(®s, ®s); /* Set the parameters */ } setcooked(handle) int handle; { union REGS regs; regs.x.ax = 0x4400; /* IOCTL get parameters */ regs.x.bx = handle; /* file handle */ intdos(®s, ®s); /* get the current set up */ regs.x.dl &= 0xdf; /* Turn off binary bit (clead dh) */ regs.x.ax = 0x4401; /* IOCTL set parameters */ intdos(®s, ®s); /* Set the parameters */ } --------- Bill Marsh, Naval Ocean Systems Center, San Diego, CA {arpa,mil}net: bmarsh@nosc uucp: {ihnp4,akgua,decvax,dcdwest,ucbvax}!sdcsvax!noscvax!bmarsh "If everything seems to be coming your way, you're probably in the wrong lane."