[fpc-pascal] serial.pp - I can't talk to modem

Graeme Geldenhuys graemeg.lists at gmail.com
Wed Jan 2 14:14:03 CET 2008


Hi,

I've created a simple console application for Linux and Windows. It's
a port of older Win32 API code I wrote years ago.  All I'm trying to
do is dial a phone number and then later hang-up the phone.

I've got a external USRobotics Courier V.Everything V.90 X2 connected
to COM1 (/dev/ttyS0).  The modem works perfectly in 'minicom' (a modem
terminal application).  But for some reason I can't get anything out
of the modem using the serial.pp unit.  I can see the RD and SD lights
flicker briefly on the modem, but nothing else.

I even tried to simply take the modem off the hook (ATH1 command) and
even that doesn't work, but again in minicom it works fine.

Can anybody please look at the following code and tell me what I am
doing wrong.  Thanks in advance.

I'm using FPC 2.2.0 under Linux (Ubuntu 7.10) and Windows 2000.  I
made sure my user under Linux has access to the /dev/ttyS0 device. I
even tried to run it as root. No difference.

------------------------[ mydialer.pas ]-----------------------------
program mydialer;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  ,serial;

var
  s: string;
  serialhandle: TSerialHandle;
  FNumberToDial: string;
  status: integer;

begin
  serialhandle := SerOpen('/dev/ttyS0');  // COM1 under Linux
//  SerSetParams(serialhandle, 2400, 8, NoneParity, 1, []);

  // construct dial string. X0 ignores dialtone.
  FNumberToDial := '123456789';
  s := 'ATX0DT' + FNumberToDial;

  writeln('DEBUG: string count: ', Length(s));
  status := SerWrite(serialhandle, s, Length(s));
  writeln('DEBUG: bytes written: ', status);

  if status = Length(s) then
  begin
    write('Pick up the phone. ');
    writeln('Press ENTER after dialing has completed.');

    s := 'ATH0' + #13#10;
    ReadLn;
    status := SerWrite(serialhandle, s, Length(s));
  end
  else
  begin
    writeln('Failed to dial the number');
  end;
  SerClose(serialhandle);
end.

----------------------------[ end ]----------------------------------



Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list