1. Modem for windows?
- Posted by Some Slacker <some_slacker at yahoo.com> Feb 07, 2006
- 464 views
- Last edited Feb 08, 2006
----------------------------------------------------------------------- --serial.e --By Greg Harris 1997 --Released to the public domain --Give credit where credit is due please. --include misc.e include round.e --Credit: Lucius Hilley III include delay.e --Credit: Jacques Deschanes global integer COMPORT -- constants global constant S_1BIT = 0, --Stop bits S_2BIT = 4, W_5BIT = 0, --Word Length W_6BIT = 1, W_7BIT = 2, W_8BIT = 3, P_NONE=0, --Parity P_ODD=16, P_EVEN=24 global constant COM1=#03F8, COM2=#02F8, COM3=#03E8, COM4=#02E8 global constant IER = 1, -- control register offsets LCR = 3, MCR = 4, LSR = 5, MDMMSR = 6 global constant ENABLE_READY = 1, MDMMOD = 11, MDMCD = 128, INTCTLR = #21 type bit_rate (integer i) sequence valid_rates valid_rates = {150,300,1200,2400,4800,9600,19200,38400,57600,115200} if find(i,valid_rates) then return i end if end type global procedure init_ports(bit_rate bitrate, integer wordlen, integer parity, integer stopbits) integer brd, msb, lsb, setbyte atom byte brd = int_div(1843200, (16 * bitrate)) msb = int_div(brd,256) lsb = and_bits(brd,255) byte = or_bits(Input((COMPORT+LCR)), 128) Output(byte, COMPORT+LCR) Output(msb, COMPORT+IER) Output(lsb, COMPORT) byte = and_bits(Input((COMPORT+LCR)),127) Output(byte, COMPORT+LCR) setbyte = wordlen+parity+stopbits Output(setbyte, (COMPORT+3)) end procedure global procedure enable_ports() integer a a = Input(INTCTLR) a = and_bits(a,239) Output(a,INTCTLR) a = Input(COMPORT+LCR) a = and_bits(a,127) Output(a,COMPORT+LCR) Output(ENABLE_READY, COMPORT+IER) Output(or_bits(8,MDMMOD), COMPORT+MCR) Output(MDMCD, COMPORT+MDMMSR) Output(32,20) end procedure global procedure sendchar(integer b) while and_bits(Input(COMPORT+LSR),32) != 32 do end while Output(b,COMPORT) delay(.01) puts(1,b) --comment out if you don't want local echo end procedure global procedure StringToPort(sequence s, integer b) integer a for i = 1 to length(s) do a = s[i] sendchar(a) end for sendchar(13) if b then sendchar(10) end if end procedure global procedure disable_ports() integer b StringToPort("ATC0",0) b = Input(INTCTLR) b = or_bits(b,16) Output(b, INTCTLR) b = Input(COMPORT+LCR) b = and_bits(b,122) Output(b,COMPORT+LCR) Output(0,COMPORT+IER) Output(0,COMPORT+MCR) Output(0,32) end procedure --------------------------------------------------------------------------- --Sniff for caller ID data from the phone company... --Excerpted (hacked) from dial.ex by --Greg Harris 1997 , and hacked at by Some Slacker -------------------------------------------------------------------------------- -- VARIABLE DECLARATION con't -------------------------------------------------------------------------------- sequence s, word, pn, ac, da, ti, keep integer x ,ox, y, RING, k x=10 ox=x y=0 RING=0 s={} word={} pn={} ac={} da={} ti={} keep={} include serial.e COMPORT=COM3 -- my modem is connected to comport3 your may be different ***ATTENTION*** --Init the modem -- init_ports(38400, W_8BIT, P_NONE, S_1BIT) enable_ports() --Send Init String -- StringToPort("AT+VCID=2",1) --this sets the modem to receive caller id data (2 signifies in nonformatted mode) delay(3) while get_key()=-1 do x=GetSerialByte(3) --this gets the next byte of data from the stream (only -1 and 10 until the phone rings) if x != -1 and x != 10 then s=append(s,x) -- add the next byte to our sequence s as long as its NOT -1 or 10 end if if RING=1 then if length(pn)=10 then if length(ac)>=12 then for i = 2 to length(ac) do keep=append(ac,pn) end for ac=keep else ac=append(ac,pn) end if pn={} end if RING=0 end if -- 'my dumb code' --I think can be replaced by: k = match("\rRING\r",s) --first caller id sends RING followed in 1/2 sec by ... if k then RING = 1 s = s[k+6..$] end if if length(s) >=50 and length(pn)<10 then k = match("\rMESG = 04123",s) -- MESG = 04123 and then the date/time/number with a 3{51} in between each element -- so the stream may look like (after MESG = 04123) 0302303631323030353535353535353535353 if k then s=s[k+14..$] end if --thanks to pete lomax for i= 1 to length(s) by 2 do if i<9 then da &= s[i] elsif i<17 then ti &= s[i] elsif i<39 then pn &= s[i] end if end for s={} position(4,1) printf(1,"%s%s/%s%s %s%s:%s%s %s", {da[1],da[2],da[3],da[4],ti[1],ti[2],ti[3],ti[4],pn}) end if position(6,1) ?s position(10,1) if length(ac)>0 and compare(ac,"")!=0 then for i = 1 to length(ac) do position(9+i,1) puts(1,ac[i]) end for end if end while --Hang up the modem -- StringToPort("+++ATH0",1) delay(3) --Disable the modem disable_ports() while get_key() = -1 do end while
Although the above code seems to work fine, I can't seem to figure how to use it with windoze, when I simply try to include the w32lib there seems to be an error... "An privileged instruction was executed at address 000dd8e7" perhaps someone knows where the error is happening? Im at a complete loss :(
2. Re: Modem for windows?
- Posted by ags <eu at 531pi.co.nz> Feb 07, 2006
- 428 views
- Last edited Feb 08, 2006
Some Slacker wrote: >Although the above code seems to work fine, I can't seem to figure >how to use it with windoze, when I simply try to include the w32lib >there seems to be an error... >"An privileged instruction was executed at address 000dd8e7" >perhaps someone knows where the error is happening? Im at a complete loss :( You are trying to access the serial port hardware in a protected mode environment. To get to the serial port you must go through Windows. Try searching for 'serial' in the Archive with only 'WIN' checked. Gary