The Arduino demos are usually from the PC to the Arduino (as in the case above); I want to go the other way. In my project, I am receiving a IR protocol from a specialty gaming device that I want to convert and send up to the PC. I'd like to start with Windows and then move to the RPi.
The simplest FPC command line synaser demo receives serial mouse stream of bytes in a forever loop. Just look at the link. However, from this to a gui is a long way. You need to learn a lot. I will discuss your options at the end of this message.
http://wiki.lazarus.freepascal.org/Hardware_Access#SynaserI made some headway today, and then learned that TLazSerial won't work on the RPi.
Unfortunatelly. The link bellow confirms this. Look at other options. I have tested TDataPort and liked it a lot (but didn't test it on RPi). However, TDataPort has problems with MOXA virtual serial ports which I have to use to access some serial devices over network, so I stick to Synaser. It might be my personal preference, but for writing communication threads Synaser and Synapse have never let me down. They work rock solid on 24/7 applications that are running for months without restart. Besides, once you learn Synaser you will see that exactly same code logic can be applied to your Synapse TCP/UDP clients and servers. A win-win case.
https://forum.lazarus.freepascal.org/index.php/topic,30577.msg194646.htmlIt's funny... there are serial ports of one sort or another on virtually every PC but this isn't a component that is standardized in Lazarus.
Delphi also doesn't have a standard component for serial communication. FPC does have a unit to handle serial communication cross platform, but it has not been wrapped into a component for Lazarus. Anyway, I like Synaser so I didn't care. It's rock solid and cross platform, too. Synaser has a visual component wrapper for both serial and tcp/udp communication named Visual Synapse, but I haven't checked it lately (since for any complex task with gui applications threads are a way to go) and I have never tried Visual Synapse on RPi.
https://sourceforge.net/p/visualsynapse/wiki/Home/I will get it -- it's just frustrating being on the steep slope of the initial learning curve.
You're not alone, but you have to read a lot first and pay attention to avoid for example problems mentioned in these threads:
https://forum.lazarus.freepascal.org/index.php/topic,36885.0.htmlhttps://forum.lazarus.freepascal.org/index.php/topic,36523.0.htmlI liked your comment vis-a-vis a communication thread, especially since it comes from practical experience. Can you tell me more?
Well, I do not recommend you to start with communication thread first. Better start with something smaller, and once you are confident move forward. Otherwise it might be too much and you might give up. With serial component you have events. That is easy to work with, but if you have more then few bytes from time to time, you will soon have an application that will cause mouse moves to become erratic and which will have constant small periods of not responding to windows messages. That's because main thread which handles windows messages is blocked by your communication for small periods of time (but big enough to be irritating for your users). Since event based logic is hard to convert to communication thread later if you use another serial component, I would recommend to use the same serial lib for your event based communication that you will later use for threading. Your life will be much easier. Anyway, what are your options with Synaser? Simple Synaser example that sends a message on button click is in the wiki. However, you need to respond to a receiving message. You can do it in 2 ways with Synaser. Both need manual polling that will check if there is something in serial communication receive buffer. First is with a timer, and that's what I recommend for a start since it's quite easy. If your messages are just few bytes from time to time then you might even get away with it and find it enough for your needs. Second is with separate communication thread. It is not easy, you need to study a lot and learn about thread synchronization, atomic access to variables, train not to access gui from communication thread to avoid SIGSEGV, exceptions and leaks (well, there is a async way but not for beginners), and few more things.
You can find Synaser documentation here:
http://synapse.ararat.cz/doc/help/http://synapse.ararat.cz/doku.php/public:howtoPlease study it first if your choice will be Synaser. Have in mind that most TCP examples can be aplied to serial too. For download you should use SVN version because stable version has not been updated for a very long time. Both versions are very stable so there is nothing to fear about trunk version. Synaser has pretty liberal BSD license, and it's safe to use for commercial applications.
Short explanation why gui application might become non-responsive:
http://forum.lazarus.freepascal.org/index.php/topic,36656.msg244520.html. Application.Processmessages and Timers can help in some cases, but they are not all mighty. Communication thread is the way to go to have your application responsive even when communication messages are being sent/received.