Hi,
I struggled for ages trying to find a way to easily use the serial port. I could not get Synaser to work, ever - all in all a very frustrating few months.
Then I discovered that all along, the tools I needed where right there under the Lazarus/FPC bonnet!!
To get the serial (Comm) or in Linux ttyS0 to work very easily, simply add to the 'Uses' clauses 'Serial' (without the quotes of course).
Remember: ttyS0 = CommPort #1; ttyS1 = CommPort #2 and so on.
To set the port parameters:
In the FormCreate procedure ---
MySerial := SerOpen('/dev/ttyS0');
SerSetParams(MySerialHandle, 9600,8,EvenParity,1,[]);
To write data to the port:
eg: Write the following two characters YU
Declare a string variable - bffr
bffr := 'YU';
SerWrite(MySerialHandle, bffr,2); //The 2 here is to send 2 characters
To read data from the port:
Place a Timer on the form and set its interval to 200. This will cause the port to be polled every 200mSec.
SerRead(MySerialHandle,bffr,1); // The 1 here is to read 1 character
if bffr = 'S' then
begin
"do stuff here depending on character received etc...."
end
Also use SerFlush(MySerialHandle); to flush the buffer if necessary.
Then of course, by default the serial port on a Linux box is inactive. So you need to activate it before you can get any comms going. This is a fairly simple matter of setting permissions.
As super user (or sudo, administrator or whatever) you can do:
1) chmod 666 ttyS0 from within the /dev directory.
However this permission setting will last only as long as your session. Rebooting will revert back to inactive ttyS0.
2) Permanently enabling the serial port.
In Fedora Core 5 for example:
Select the file /etc/udev/rules.d/50-udev.rules
Change the existing line that starts with KERNEL == "tty" to the following:
KERNEL=="tty[A-Z]*",NAME="%k",GROUP="MYGROUP", MODE="666";
I noticed on a box running SuSE 9.1 that doing a chmod 666 ttys0 set the permissions permanently. Also SuSE does not use the same diectory as depicted above for Fedora 5.
You will need to find out how to permanently enable the serial port for the type of distro you are running.
Hope this info of of use.