Modem Routines

new topic     » topic index » view thread      » older message » newer message

Somebody was wanting modem routines. Here is a few that I have written
for accessing the modem and sending data. I do not have any routines
written to read serial data from the ports as this requires an
interrupt handler at speeds over 9600 and my machine coding is rather
rusty. These routines should init a modem to speeds up to 115200 bps
and have been tested on COM2 and COM4 using standard
IRQs. To use these routines you need round.e (Lucius L Hilley III), Jacques
Deschanes routines (ports.e and delay.e) and Euphoria version 1.5.
Released to the public domain.

-----------------------------------------------------------------------
--serial.e
--By Greg Harris 1997
--Released to the public domain
--Give credit where credit is due please.

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
---------------------------------------------------------------------------

--dial.ex Example program

--Sample program to dial a pager
--Change all 5555555 numbers to real phone numbers before running!!!
--delay might need to be changed for different services. this works
--for me Use at own risk. Not responsible for any damage caused by this
--program
--Greg Harris 1997

include d:\programs\include\serial.e

COMPORT=COM2
--Init the modem --
init_ports(38400, W_8BIT, P_NONE, S_1BIT)
enable_ports()
--Send Init String --
StringToPort("ATZ",1)
delay(3)
--Dial pager number --
StringToPort("ATDT5555555;",1)
delay(9)
--Tell pager who called--
StringToPort("ATDT5555555;",1)
delay(3)
--Hang up the modem --
StringToPort("+++ATH0",1)
delay(3)
--Disable the modem
disable_ports()

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu