Serial Port Component For Lazarus Pit

0 views
Skip to first unread message
Message has been deleted

Rapheal Charlton

unread,
Jul 17, 2024, 2:09:21 AM7/17/24
to mertsupphidtoo

I'm thinking in code interfaces on it, but I am not much familiar with them. What I would like to know is: What are the implementation nuances from Delphi and Lazarus interfaces? There is something that I should be specially aware? Will I have to code really different things?

Serial Port Component For Lazarus Pit


Download File https://tinourl.com/2yLYrn



Background explanation:I think the components could benefit from interfaces, or at least, I will learn more from them. For example, one of the components make communication to many different hardwares using serial port. But user should use only our component to create the application. So we have the component and one class to each of this hardware that descendant from a base class. At run-time we create the specific class inside the component.

In Free Pascal, the interface type depends on mode. Basically there is mode COM or CORBA . COM is default and roughly compatible with Delphi. CORBA is a more simpler case without the reference counting. (and thus also not generating calls to refcounting functions). So basically a FPC Corba interface is like the hypothetical ancestor of the IUnknown interface.

Besides this, there are sometimes some differences wrt when interfaces are released. Delphi tends to save decreasing the refcount at for the end of the procedure or block (in larger procedures), while FPC sometimes is known to release them sooner, typically immediately after the statement of last use. Both are legal implementation choices btw, base on which scope is used for temporary variables. (only on the function level, or also in deeper nested blocks)

However this sometimes reveals hidden (bad) assumptions in code, specially when using interface references and object references within one procedure that might "survive" in Delphi, but not in FPC. It is a typical case that shows that long-time working code is not necessarily correct. One might only notice hidden assumptions when changing implementation

(added later:) note that you can use COM style on *nix. It mainly is the insertion of calls to reference counting routines that set the two interface types apart. Not what system (COM, Corba or simply in RTL reference counting) those calls are routed to.

Note that I think the COM vs Corba names for both interface types were badly chosen. Corba interfaces are refcounted actually, but traditionally this refcount is manually handled, because Java does not support externally handled interfaces in an automated manner.

The SynEdit in Lazarus is a built-in package, because the IDE uses it itself. Therefore the package can not be removed from the installation list. To remove the entries from the component palette, the SynEditDsgn package can be removed from installation.

Sometimes you might want to edit existing highlighters (just like I wanted a few days ago) that already exist.In this example we're going to edit the highlighter for pascal-like code (classname: TSynPasSyn; package: SynEdit V1.0; unit: SynHighlighterPas.pas).

The lazarus-IDE does automatically detect, what attributes exist and shows them in the options, such as saves them, if you change them.If your application/IDE doesn't do this, you will have to set Color/Font/etc. of the new Attributes somewhere manually (e.g. in the constructor of TSynPasSyn)

SynEdit.Lines can be used to set the initial version of the text (e.g. loaded from file). Note that SynEdit.Lines.Add/SynEdit.Lines.Append does not support line breaks inside the added strings. You should add lines one by one.

As you can see on the other pages, I am interested in Delphi and Linux.
So I was very pleased to find information on the Lazarus project: I started working on porting my Delphi programs to Lazarus and found out that it was very easy to port my Delphi 1 programs.
What I discovered very soon when trying to port my Delphi 5 programs was the lack of the Chart component. So I started programming a replacement for it.
The result was the PlotPanel component
Whit this component you can draw up to 8 plots in one diagram, it has auto scaling properties and has the ability to show animated plots. The TryPlotPanelDemo program allows you to try Plotpanel without installing the component This program gives you some hints for your own program ideas.

Screenshot



You can download this component (version 0.91) here:

Download plotpanel_l.zip

There seems to be some problems with the LRS file in the Demo programs. Here is an updated version that should run on Lazarus 0.9.26
This version also allows you to place a label at the x and y axis
The licence is also changed to LGPL now.
Download plotpanel_lazarus_0.95.zip

A nice feature to change the Marks along X and Y axis was supplied by Jorge Solla. You can find those extentions in version 0.96:
Download plotpanel_lazarus_0.96.zip

Version 0.96 of Plotpanel does not work correct with Lazarus version0.9.28.x. Here an updated version:
N.B. version 0.97 was wrong, so it was not possible to install. Version 0.97.1 will install
Download plotpanel-lazarus-0.97.1.zip



Here is a short description of this component:

PlotPanel
PlotPanel is a component for Delphi or Lazarus to replace (more or less) the TChart component.
With PlotPanel you can draw line- , dot- and bar-graphs. Animated graphs are also possible.
This software is presented as is, without any written warranty. So use the software at your own risk.
Installation

To Install the PlotPanel component in Delphi you have to do the following:


After you have done that all, there must be a new Tab in the component palet with the name "Extra". You can use the Plotpanel now

Run the PlotPanelDemo to explore the features of PlotPanel. N.B. You can try PlotPanel without installing the component by running TryPlotPanel!

Description of the PlotPanel component

This is a very rude description of the component. See the examples for an explanation of how to use the component. The PlotPanel component is derived from the TCustomPanel-component. To this Panel plotting capabilities are added.

Properties inherited from TCustomPanel




To encourage other people to use Lazarus I have converted some programs from Delphi to Lazarus. You have to compile the programs yourself. All source code is free under terms of the GPL
See a description of these programs elsewhere on this site

A simple game, but teasing when you don't know how to solve it
Download lazlucas.zip

Educational program to demonstrate how light is focussed by a lens
Download lazlens.zip

Demonstration af additive color mixing
Download lazcolor.zip

Calculation of frequency, capacitance and inductance in series or parallel resonance circuits
Download lazlcf.zip

Make Me Small
The programs compiled with the current version of Lazarus tend to be big. With this program you can reduce the size by a factor of 10 to 20!
Download lazmakemesmall.zip


Most programs have an educational purpose, but some are usefull for serious applications.
You can use this software under the terms of the GPL.

A communications portcomponent with standard serial port properties (port number, baud rate, andso on), methods for sending and receiving data, and events for commoncommunications situations (data available, buffer empty, and so on).

File Transfer Protocol (FTP)components that take care of the FTP protocol details and present afriendly interface, allowing you to transfer huge files from the Internet andsupport resumable transfers. An FTP logging component automates the process oflogging an FTP client-server dialog for auditing FTP activities.

TApdIniDBase, TApdModemDBase, AwModem.ini: These componentsand files were used for modem configuration and phone book databases. They havebeen replaced by the TApdLibModem component and the modemcap database.

Enter Miletus, which is part of the TMS Web Core product. Web Core makes it easy to develop web applications which should run on pretty much any browser, and Miletus expands on that by running the web application within a binary executable that includes code to connect with the host machine more intimately. On the Pi, this includes components to control devices connected to the GPIO port, so if say you want to measure temperature and humidity using a Pi HAT then Miletus can provide the glue between your application and the hardware.

At the ground we need a receiver to receive that telemetry, and some means of at least displaying the balloon position as latitude, longitude and altitude. Ideally we also want to see that position on a map, so we can follow the flight path in real time and plan a route to the landing position for recovery. So now a receiver will need a suitable colour display as well as the radio receiver.

When the user clicks one of those main buttons, then essentially all that happens is that the relevant TWebPanel is made visible and the previously visible TWebPanel is made invisible. It makes for a quick changeover between forms.

To use an SPI device you will need to read the manual for your specific device as they vary enormously, but in general they will present a number of registers that you can address and then write to or read from. You will then need to configure the device through config registers before sending and/or receiving data such as temperatures etc.

In the case of the LoRa devices that I use, they need to be set to the correct radio frequency etc., and then a status bit in a status register can be polled to know when a radio packet has been received. For high altitude balloons those packets will usually be telemetry containing the balloon position as an ASCII (text) string with time, latitude, longitude and altitude etc. Something like this:

I then wondered if anyone sells a Raspberry Pi tablet where I could add these components internally. There are some tablets available, but the only one that was currently available, and which seemed to have enough internal space, was the Raspad 3. So I ordered one from Amazon and next day it arrived.

7fc3f7cf58
Reply all
Reply to author
Forward
0 new messages