Sign in Join

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

Mailing lists / fpc-pascal / 2007-12

help with serial.pp unit please

6 messages · 4 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'm trying to write a Phone Dialer feature in my application. I managed to do this a long time ago in a Delphi app using Windows API calls, but now I need it for Linux and Windows. Unfortunately the serial.pp unit is not documented and searching the FPC src directory didn't yield any examples either.

So the code below is a shot in the dark. Could anybody familiar with the serial.pp unit comment please. If I get this working, maybe it can serve as a simple example of using the serial.pp unit?

A few notes and questions:

1. ComPortToString will create a string containing the selected com port of the OS. eg Linux = '/dev/tty0' or under Windows = 'COM1'

2. What status codes does SerWrite() return? What are valid/invalid codes?

3. Does my 'hangup the phone' string look correct?

---------------------[ Start ]----------------------------------
    try
      s := ComPortToString;
      serialhandle := SerOpen(s);
      s := 'ATDT' + FNumberToDial + #13+#10;   //Create a string to
send to modem.
      writecount := 0;
      status := SerWrite(serialhandle, s, writecount);
      // The next line is for debugging only!
      writeln('status: ', status, '   writecount: ', writecount);
      if status > 0 then  // What am I supposed to test for???
      begin
        //Hide;
        ShowMessage('Pick up the phone.' + #13 + 'Click OK after
dialing has completed.');
        s := 'ATH^M^J';
        status := SerWrite(serialhandle, s, writecount);
      end
      else
        ShowMessage('Unable to dial number.');
    finally
      SerClose(serialhandle);
    end;
---------------------[ END ]----------------------------------

Regards,
- Graeme -

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

Reply by email

Graeme Geldenhuys
to Marco van de Voort
Marco van de Voort wrote
> s := 'ATH^M^J'; Shouldn't you use the relevant #xxx chars here?

Oops! You are right.

I also noticed that I was using SerWrite() wrong. The third parameter is not a 'out' parameter as I assumed!

     status := SerWrite(serialhandle, s, writecount);

had to change to

     status := SerWrite(serialhandle, s, Length(s));

Regards,
- Graeme -

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

Reply by email

Marc Santhoff
to Graeme Geldenhuys: I'm trying to write a Phone Dialer feature in my application. I managed to do this a…
Graeme Geldenhuys wrote 19 lines
Hi, I'm trying to write a Phone Dialer feature in my application. I managed to do this a long time ago in a Delphi app using Windows API calls, but now I need it for Linux and Windows. Unfortunately the serial.pp unit is not documented and searching the FPC src directory didn't yield any examples either. So the code below is a shot in the dark. Could anybody familiar with the serial.pp unit comment please. If I get this working, maybe it can serve as a simple example of using the serial.pp unit? A few notes and questions: 1. ComPortToString will create a string containing the selected com port of the OS. eg Linux = '/dev/tty0' or under Windows = 'COM1' 2. What status codes does SerWrite() return? What are valid/invalid codes?

On Unix SerWrite and SerRead return the count of bytes written or read. On Windows you've got to check yourself ...

So sth. like:

	status := SerWrite(serialhandle, s, Length(s));
	if (status  Length(s)) then bark;

should be appropriate.

HTH,
Marc

Reply by email

Musan Antal
//Hide; ShowMessage('Pick up the phone.' + #13 + 'Click OK after dialing has completed.'); s := 'ATH^M^J';
I think you'll better use
           s:='ATH'^M^J;

Reply by email