Lazarus
Installation => General => Topic started by: zkv on March 21, 2007, 08:35:18 pm
-
Hi all!
is there a serial port component for Lazarus?
thanks in advance,
bye
zkv
-
Have a look at <http://wiki.lazarus.freepascal.org/Hardware_Access>
-
Please, donĀ“t cross-post. I removed the other topic.
-
Hi all!
is there a serial port component for Lazarus?
thanks in advance,
bye
zkv
Yes, of course,
you can use a Synaser by Lukas Gebauer... (www.araat.cz/synapse or so...)
:D
badger
-
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.
-
Hi.
And serial interrupts, like 'data received' !?
I don't want to test all times if there's any comunication!
:roll:
Tx
-
Small corection in write data to the port:
SerWrite(MySerialHandle, bffr[1],2); //The 2 here is to send 2 characters
By Tadej
-
Hi does this work with USB-Ports as well?
-
Check this out : http://wiki.lazarus.freepascal.org/Hardware_Access#USB
-
TNX 4 the link, i've bookmarked it. andit sure will help me to transform my Gps-Application from Delphi 2 Lazarus.
-
There's a serial port component in http://wiki.lazarus.freepascal.org/5dpo
It's a visual implementation of synaser and it works in Linux and Windows.
Bye
pmalheiros
-
Hi
I am looking for a serial component/library or similar for use with a PowerPC mac
I tried the 5dpo/synaser, but the PowerPC platform has hardware differences by the looks that is causing problems with the compiling of the synaser.pas file
Does anyone know of a possible solution?
I do have a library file that is developed under c++ , using libc, and that works OK under linux and the Mac intel, but with the Mac powerpc, it locks up when the comport is tried to be opened....not sure if that is a driver install issue for the usb to serial adaptor (i.e might need a different driver for the powerpc (but it does show up ok when doing ls /de/tty.*), or its because of archeticural differences with the Power PC and a Intel PC?
Thanks!
(ps, sorry for replying to an old thread)
-
Don't know anything about Power PC but my program using synaser under Windows receives mostly gobbledygook when using a Prolific-based USB to serial adapter although it works fine talking to the same device at the same speed with a real serial port. So I'm interested in knowing if there is an alternative too, though in my case it needs to work on Windows and Linux.
Many USB to serial port adapters don't make a good emulation of a serial port but problems can often be solved by trying a different adapter with a different chipset.
-
HI
yes, I agree that some usb to serial adaptors are better than others
your problem sounds like the baud rate by need to be set correctly?
My usb to serial works OK on my Intel Mac, but the same compiled/ported code on the PowerPC (and same driver loaded), it locks up when the port is tried to open
so thats why I wanted to try out synaser.pas ,but that is not compiling on the powerpc....