Re: getc() hangs with COM ports
- Posted by Igor Kachan <kinz at peterlink.ru> May 04, 2001
- 443 views
Ýòî ñîîáùåíèå â ôîðìàòå MIME ñîñòîèò èç íåñêîëüêèõ ÷àñòåé. ------=_NextPart_000_01C0D4D2.53970240 Hi Andy, > I'm still trying to get something that will drive COM ports - without > trashing the port for all future use by Windows or DOS as my current > system does. > If I fn=open("COM1","ub") then I can write to the port nicely with > wprintf(). But calling getc(fn) then it should (apparently) return -1 if > there's nothing there, but it always hangs around waiting and doesn't > return if the port is quiet. Which doesn't help time out loss of data > too much. get_bytes() does the same. > Does anyone know a way to use this method of reading the port without > the thing hanging? I can just to repeate for you my old mails to Florian. See below and in the attachment. Hi Florian, >Is there any routine or anything else to > know with wich parameters a COM port is open. Try program from attachment (-: *AS IS* On my machine, there are 4 COM-ports, 1- mouse, 2-modem, so I have tried COM4. If I open("COM4","rb") --- fn = 3, but machine *HANGS UP*, when getc(fn). If I ** open("COM4 96","rb") ** --- fn = 3 and getc(fn) gives 123 49 44 50 125 -1 -1 -1 If I open("COM4 48","rb") --- fn = - 1 So, I think, open() function opens COM-port at 96, (9600 baud), but this speed must *be* in the command. My machine run Win95 and hangs up both on plain DOS and Win95. All my actions are non-documented, remember please, this area is among BIOS interruptions and Win95 drivers. This is the very rare thing. ------------------- And the next one mail Hi Florian, >on my computer (2 COM-ports), the open("COM1or2","rb") >function return -1 each time I try to specify the speed >(9600, 4800, 2400, 1200 or 600 bauds) but works correctly >without speed specification. >Is there any rule or to know what must be filled in? In this case, there is only one productive way to program these things -- link two machines on one table with the cable and run the serial port program on both machines. Any other rules will be abstract or speculative. Try *DOS* manual, *mode* command, my DR DOS 6.0 manual was useful to add 96 -- for me, fn=open("COM4 96","rb") works well -- then getc(fn) reads the COM4 port. But for you, doesn't work. I don't know why. Is your ports *free*? COM1 - mouse, COM2 - modem, I think, you *must* release ports - uninstall your mouse and modem - Win95 keeps loaded drivers. Try *BIOS* manual, I think, Eu docs doesn't have detailed instructions because of this reason -- dependence of the success on too many factors, and you need 2 machines or 2 free linked ports. I tried this programming in QB on linked 286 and 386 in the past, but now, my 386 machines are adjusted for another work, and are linked on LPT1,2. Thing is simple enough when you have 2 machines, *well connected* Hope this helps. Regards, Igor Kachan kinz at peterlink.ru ------=_NextPart_000_01C0D4D2.53970240 Content-Type: application/octet-stream; name="Md.ex" Content-Transfer-Encoding: 7bit Content-Description: Md.ex (EX ) Content-Disposition: attachment; filename="Md.ex" integer fn,a fn=open("COM4 96","rb") ?fn a= system_exec("mode COM4 /status",1) for i=1 to 8 do ? getc(fn) end for close(fn) -- "CON" - the console (screen) -- "AUX" - the serial auxiliary port -- "COM1" - serial port 1 -- "COM2" - serial port 2 -- "PRN" - the printer on the parallel port -- "NUL" - a non-existent device "black hole" ------=_NextPart_000_01C0D4D2.53970240--