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

2008-01-03 Thread Michael Müller


Am 02.01.2008 um 15:39 schrieb Bernd Mueller:


Graeme Geldenhuys wrote:


  SerWrite(serialhandle, s, Length(s));


SerWrite(serialhandle, s[1], Length(s));


Why not adding an overloaded SerWrite() that simply expects a string?

procedure SerWrite(handle, string);
begin
  SerWrite(handle, string[1], Length(string));
end;

This s[1] vs. s issue is popular with blockread/write too.

Regards

Michael
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-03 Thread Graeme Geldenhuys
On 03/01/2008, Michael Müller [EMAIL PROTECTED] 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/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread 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/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Michael Van Canneyt


On Wed, 2 Jan 2008, Graeme Geldenhuys wrote:

 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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Graeme Geldenhuys
On 02/01/2008, Michael Van Canneyt [EMAIL PROTECTED] 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.  :-(

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/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Michael Van Canneyt


On Wed, 2 Jan 2008, Graeme Geldenhuys wrote:

 On 02/01/2008, Michael Van Canneyt [EMAIL PROTECTED] 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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Frank McCormick
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Wed, 02 Jan 2008 15:49:47 +0200
Graeme Geldenhuys [EMAIL PROTECTED] wrote:

 On 02/01/2008, Michael Van Canneyt [EMAIL PROTECTED] 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-
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Graeme Geldenhuys
On 02/01/2008, Michael Van Canneyt [EMAIL PROTECTED] wrote:

 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/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Graeme Geldenhuys
On 02/01/2008, Frank McCormick [EMAIL PROTECTED] 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/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread John Coppens
On Wed, 2 Jan 2008 16:15:33 +0200
Graeme Geldenhuys [EMAIL PROTECTED] wrote:

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

Hi...

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?

How is your minicom configed? 

John
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Marco van de Voort
 On 02/01/2008, Frank McCormick [EMAIL PROTECTED] 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)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Bernd Mueller

Graeme Geldenhuys wrote:


  SerWrite(serialhandle, s, Length(s));


SerWrite(serialhandle, s[1], Length(s));

Regards, Bernd.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Graeme Geldenhuys
On 02/01/2008, John Coppens [EMAIL PROTECTED] wrote:

 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/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Michael Van Canneyt


On Wed, 2 Jan 2008, Bernd Mueller wrote:

 Graeme Geldenhuys wrote:
 
SerWrite(serialhandle, s, Length(s));
 
 SerWrite(serialhandle, s[1], Length(s));

Duh ! We all should have spotted that one !! :(

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Graeme Geldenhuys
On 02/01/2008, Bernd Mueller [EMAIL PROTECTED] wrote:
 Graeme Geldenhuys wrote:

SerWrite(serialhandle, s, Length(s));

 SerWrite(serialhandle, s[1], Length(s));


Uh, it works!!!   Thanks a million Bernd.  If you ever come to South
Africa, look me up, I owe you a beer.  :)


Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Graeme Geldenhuys
On 02/01/2008, Michael Van Canneyt [EMAIL PROTECTED] wrote:
 
  SerWrite(serialhandle, s[1], Length(s));

 Duh ! We all should have spotted that one !! :(


Tell me about it!!

Thanks again to everybody that tried to help.  I have a few extra grey
hairs, but I'll live. ;-)


Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Graeme Geldenhuys
On 02/01/2008, Marco van de Voort [EMAIL PROTECTED] 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/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2008-01-02 Thread Bernd Mueller

Graeme Geldenhuys wrote:

Uh, it works!!!   Thanks a million Bernd.  If you ever come to South
Africa, look me up, I owe you a beer.  :)


thanks four your invitation, unfortunately I am not living around the 
corner (Germany). So don't expect me in the next couple of days ;-))


Regards, Bernd.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal