Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-01

serial.pp - I can't talk to modem

18 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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/

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 15 lines
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. begin serialhandle := SerOpen('/dev/ttyS0'); // COM1 under Linux // SerSetParams(serialhandle, 2400, 8, NoneParity, 1, []);

Shouldn't you set at least RtsCtsFlowControl ?
As far as I know, you must at least set some options, such as the baud rate and so on, sersetparams seems to do most of the needed actions ?

Michael.

Michael Van Canneyt
to Graeme Geldenhuys: Even if I uncomment the 'SerSetParams(...)' line shown above, it makes no difference. :-(
Graeme Geldenhuys wrote 12 lines
On 02/01/2008, Michael Van Canneyt wrote: > > begin > > serialhandle := SerOpen('/dev/ttyS0'); // COM1 under Linux > > // SerSetParams(serialhandle, 2400, 8, NoneParity, 1, []); > > Shouldn't you set at least RtsCtsFlowControl ? > As far as I know, you must at least set some options, such as the baud rate > and so on, sersetparams seems to do most of the needed actions ? Even if I uncomment the 'SerSetParams(...)' line shown above, it makes no difference. :-(

Yes, but it should be

SerSetParams(serialhandle, 2400, 8, NoneParity, 1, [RtsCtsFlowControl]);

No ?

Also, 2400 baud seems very slow ?

Michael.

Graeme Geldenhuys
to Michael Van Canneyt: Shouldn't you set at least RtsCtsFlowControl ? As far as I know, you must at least set…
Michael Van Canneyt wrote 7 lines
> begin > serialhandle := SerOpen('/dev/ttyS0'); // COM1 under Linux > // SerSetParams(serialhandle, 2400, 8, NoneParity, 1, []); Shouldn't you set at least RtsCtsFlowControl ? As far as I know, you must at least set some options, such as the baud rate and so on, sersetparams seems to do most of the needed actions ?

Even if I uncomment the 'SerSetParams(...)' line shown above, it makes no difference. :-(

I'm busy reading through the article mentioned below to try and see what I'm doing wrong. So far I found no hints as to the cause of the problem. The article does mention a CR (#13) must be sent as the last character in each command. I appended #13 to my dial string, but still nothing.

http://www.easysw.com/~mike/serial/serial.html

Regards,
- Graeme -

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

Frank McCormick
to Graeme Geldenhuys

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Show quoted text 13 lines
On 02/01/2008, Michael Van Canneyt wrote: > > begin > > serialhandle := SerOpen('/dev/ttyS0'); // COM1 under Linux > > // SerSetParams(serialhandle, 2400, 8, NoneParity, 1, []); > > Shouldn't you set at least RtsCtsFlowControl ? > As far as I know, you must at least set some options, such as the > baud rate and so on, sersetparams seems to do most of the needed > actions ? Even if I uncomment the 'SerSetParams(...)' line shown above, it makes no difference. :-(

What are the permissions on /dev/ttyS0 ? Have you tried running it as root ?

- --
Cheers
Frank
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHe5rkzWG7ldLG6fIRAop1AJ9LpSzKnUTbs7remMdw2Onum9RTmgCgkc/q uikrl+oEokCZMRQzMNezWpM=
=EcYK
-----END PGP SIGNATURE-----

Graeme Geldenhuys
to Michael Van Canneyt: Yes, but it should be SerSetParams(serialhandle, 2400, 8, NoneParity, 1,…
Michael Van Canneyt wrote 6 lines
Yes, but it should be SerSetParams(serialhandle, 2400, 8, NoneParity, 1, [RtsCtsFlowControl]); No ?

I have no idea! :-)

OK, I changed the code to the following... I it should do, is take the modem off the hook... nothing happens. :-(

-------------------------
  serialhandle := SerOpen('/dev/ttyS0');  // COM1 under Linux
  if serialhandle = -1 then
    writeln('Failed to open port');
  SerSetParams(serialhandle, 2400, 8, NoneParity, 1, [RtsCtsFlowControl]);
  s := 'ATH1' + #13;
  SerWrite(serialhandle, s, Length(s));
-------------------------
Also, 2400 baud seems very slow ?

That should not be a issue. All that the code is supposed to do is dial the phone, nothing else (hence the reason I didn't even bother with the SerSetParams call in the beginning). The end result should allow the user to click a button next to a phone number and the modem dials the number for the user. No other communication happens. Anyway, I tried 19200 speed as well, but as expected, no change. This has been driving me insane for a few days now. Grey hairs popping up all over the place! :-)

Regards,
- Graeme -

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

Graeme Geldenhuys
to Frank McCormick: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, 02 Jan 2008 15:49:47 +0200 What are…
Frank McCormick wrote
What are the permissions on /dev/ttyS0 ? Have you tried running it as root ?

The first thing I checked! The user is part of the 'dialout' group which has access to the modem. 'minicom' was a test of this and works. I also ran my program under root, but still no change.

Does anybody have Linux and a modem to give the application a try? This should eliminate a PC specific issue, but then again 'minicom' works just fine on my computer.

Regards,
- Graeme -

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

Marco van de Voort
to Graeme Geldenhuys: The first thing I checked! The user is part of the 'dialout' group which has access to…
Show quoted text 12 lines
On 02/01/2008, Frank McCormick wrote: > > What are the permissions on /dev/ttyS0 ? Have you tried running it > as root ? The first thing I checked! The user is part of the 'dialout' group which has access to the modem. 'minicom' was a test of this and works. I also ran my program under root, but still no change. Does anybody have Linux and a modem to give the application a try? This should eliminate a PC specific issue, but then again 'minicom' works just fine on my computer.

Note that there is a serial related bug in Mantis, with respect to setting baudrates.

I'm waiting till I have a serial device to test. (must have a cable soldered at work first)

Graeme Geldenhuys
to John Coppens: On Wed, 2 Jan 2008 16:15:33 +0200 Hi... I seem to recall (vaguely) that modem comms were…
John Coppens wrote 6 lines
I seem to recall (vaguely) that modem comms were (by default) Even parity, and 7 bits. Can't recall default speed though. Could that be the reason? From my days of running a BBS, before the Internet, it was 99% of the

time 8N1. When I startup minicom it also sets the modem to 115200 & 8N1. But as I mentioned, all I want to do is dial the phone with the modem. The speed should be irrelevant for that (I think).

Regards,
- Graeme -

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

Graeme Geldenhuys
to Marco van de Voort: Note that there is a serial related bug in Mantis, with respect to setting baudrates. I'm…
Marco van de Voort wrote
I'm waiting till I have a serial device to test. (must have a cable soldered at work first)

I had to search for my cable and Courier modem in the attic! :) [I still remember paying a small fortune for the damn modem - years ago]

Regards,
- Graeme -

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

Graeme Geldenhuys
to Michael Müller
Michael Müller wrote
Why not adding an overloaded SerWrite() that simply expects a string?

Funny you mention that. I was actually thinking the same thing - adding a helper method which takes a string parameter and auto adds the CR (#13) character to the end of the string, if it doesn't exist.

Regards,
- Graeme -

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