[fpc-pascal] Extra linkxxx.res files left over when compiling/building project

2024-01-15 Thread Bo Berglund via fpc-pascal
I have been working on troubleshooting a command line FreePascal project for a
couple of weeks now and when I look in the project dir it is full of link files:

2021-09-12  10:2323 900 link.res
2024-01-15  00:3023 833 link11600.res
2024-01-13  10:3923 833 link17204.res
2024-01-13  10:3523 833 link19736.res
2024-01-13  10:4323 833 link22340.res
2024-01-13  10:4523 833 link23748.res
2024-01-13  13:3523 833 link24944.res
2024-01-13  10:4123 833 link25456.res
2024-01-13  21:1525 743 link3564.res
2024-01-13  13:4023 833 link5720.res

Of course I can delete them but why has this happened? Should these not be
temporary or else located below the lib dir somewhere?

And what are they used for?

Lazarus 2.2.4/Fpc 3.2.2 on Windows 10 x64


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Error when building fpc on aarch64-linux still not resolved

2023-12-09 Thread Bo Berglund via fpc-pascal
On Thu, 16 Nov 2023 13:15:27 +0100, Bo Berglund via fpc-pascal
 wrote:

>I tried to post this to the devel list but it seems to have failed so now 
>trying
>the general list instead...
>
>See ticket:
>https://gitlab.com/freepascal.org/fpc/source/-/issues/39295
>
>It was closed a year ago being purportedly resolved...
>
>But only for powerpc 64 bit...
>
>It is still there for aarch64-linux used by Pi-OS bookworm 64 bit, which is now
>the recommended version...
>
>RaspberryPi is a very popular platform so a solution for that is needed.
>
>I have tried building (via fpcupdeluxe) several revisions of fpc up to and
>including trunk, but all fail with the same error outlined in the ticket above.

Soon 4 weeks and no reply to this...  :(

I have now started using the Raspberry Pi5B with Pi-OS 64 bit bookworm and I
cannot get past the linking error when building fpc from sources, I have tried
the latest release 3.2.2 and also the pre-release 3.2.3 and 3.3.1 but all fail
with the same error:
undefined reference to `__libc_csu_init'

So now I tested to download what I think might be the trunk:
https://gitlab.com/freepascal.org/fpc/source/-/archive/main/source-main.tar.gz

And with these sources the linker error disappears and the build all succeeds.

Could you not just make an intermediate tag for a version where this fix has
been solved for the arm64 architecture running aarch64-linux?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Question regarding building fpc from sources

2023-11-30 Thread Bo Berglund via fpc-pascal
On Thu, 30 Nov 2023 10:50:02 +0100 (CET), Michael Van Canneyt via fpc-pascal
 wrote:

>> Somewhere in the process above the newly built compiler/ppcarm disappears 
>> from
>> the compiler dir
>>
>> Is this what should happen or is it an error?
>
>Because installing sources requires a 'clean' source tree, 
>'make sourceinstall' does a clean first.
>
>So you should not do this as long as the compiler binary has not been 
>moved somewhere else. (the make install normally does this).
>
>Michael.

Thanks for the explanation!

This explains how it does work then, makes sense since the make install places
the compiler elsewhere in a standardized way and creates the symlinks for
starting it.
I assume that the normal way to use fpc is to have one compiler version and not
move back and forth between them?
And move up once the next is released only.

Right now the highest release version I have compiled is ver 3.2.2
I have also built 3.2.3, which I guess is a testing release not for general use?

I will set 3.2.2 as the one to use on my 32 bit RPi4B devices.

There is/was a problem on RPi4B with PiOS 64 bit regarding building from sources
so I will revisit that and check what will work.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Question regarding building fpc from sources

2023-11-29 Thread Bo Berglund via fpc-pascal
I have for many years been building my Linux versions of fpc and lazarus from
sources downloaded first from the svn repository and later from github.
When doing the build on a new Linux system I need a seed compiler for the
platform and I usually get that from earlier builds on other devices.
To simplify things I have made tgz archives of the compilers I have built and
put them on my website so I can then use wget on a new device to download them
into the fpc dir on that platform.

Now there has been a bit of pause in these activities and I am trying to catch
up so I wanted to create the tgz files for two compilers on my latest build
system (a Raspberry Pi4B running 32 bit bookworm OS).

After building 3.2.2 using a compiler I already had in the fpc dir I exctracted
the ppcarm compiler from the compiler directory in the source tree and put it
into a tgz archive.
But amazingly when I tried to locate the output compiler from when I built the
3.2.0 version a week ago it has disappeared!
No trace of it inside the fpc/3.2.0/compiler directory!

The difference from the newly built compiler is that a week ago I also ran the
make install command to put source files etc into a directory below my $HOME
dir. This step is not yet done for 3.2.2

My script does this for the install operations (variables set before of course).
The current dir for the command is at the top of the source tree such as
$HOME/devel/fpc/3.2.0

make install PREFIX="$HOME" FPC="$HOME/devel/fpc/3.2.0/compiler/$FPCCOMPILER"

rm "$HOME/bin/$FPCCOMPILER"

ln -sf "$HOME/lib/fpc/3.2.0/$FPCCOMPILER" "$HOME/bin/$FPCCOMPILER"

make sourceinstall PREFIX="$HOME" FPC="$HOME/bin/$FPCCOMPILER"

$HOME/lib/fpc/3.2.2/samplecfg $HOME/lib/fpc/3.2.2 $HOME

mv "$HOME/fpc.cfg" "$HOME/.fpc.cfg"

Somewhere in the process above the newly built compiler/ppcarm disappears from
the compiler dir

Is this what should happen or is it an error?
 

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Cannot build fpc on Raspberry Pi4B running PiOS 64 bit (aarch64 Linux)

2023-11-24 Thread Bo Berglund via fpc-pascal
On Tue, 21 Nov 2023 10:33:46 +0100, Tomas Hajny via fpc-pascal
 wrote:

>On November 21, 2023 8:33:55 +0100, Bo Berglund via fpc-pascal 
> wrote:
>>I did not know that there is a library of seed compilers available on
>>Sourceforge, I thought everything had moved over to GitLab nowadays, so where
>>exactly can I find a binary download for PiOS 64 bit on SF?
>>Where I have looked I only find old stuff like from 2021...
>>
>>https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/
>>Here are tarballs that by the size seem to contain a lot of stuff apart from 
>>the
>>compiler itself.
>
>Yes, there are full official releases provided by the FPC team and used by 
>many FPC users.
>

I tried downloading one of the ones on SF and it contains a maze of other tar
file with yet other tar files etc inside.

I failed to locate the actual compiler executable file anywhere, so I gave up on
that

Instead I have put tgz files on my own website for each compiler I hhave
found/built to be used as seed compilers in the future.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Cannot build fpc on Raspberry Pi4B running PiOS 64 bit (aarch64 Linux)

2023-11-20 Thread Bo Berglund via fpc-pascal
On Sat, 18 Nov 2023 13:31:51 +0100, Sven Barth via fpc-pascal
 wrote:

>Bo Berglund via fpc-pascal  schrieb am
>Sa., 18. Nov. 2023, 11:32:
>
>> Today after realizing that I did the following on an RPi4B where I have
>> used apt
>> to install the fpc compiler so I could use that as the seed compiuler to
>> build
>> from sources.
>>
>
>Why don't you simply follow what I DID? First of deinstall that apt fpc
>again. Then download 3.2.2 for aarch64-linux from SourceForge, install it
>and add /path/to/where/you/installed/fpc/bin to your PATH (using "export
>PATH=/new/path:$PATH").

Here I lost you, is SF still in use? I thought that everything moved to GitLab
some time ago?
And is there something like "install" in Linux apart from apt install which is
what I used?

>Best pick in an installation path like /wherever/fpc/ and select
>"yes" when asked whether to adjust the fpc.cfg with $fpcversion, that will
>come in handy later.
>
>Next download the sources for 3.2.3 and extract them somewhere different
>than "/wherever/fpc". Change into that directory and execute the commands
>as I had written in my previous mail (you should be in the same command
>line session where you adjusted PATH for this to work otherwise you need to
>set it again). The INSTALL_PREFIX should be "/wherever/fpc/3.2.3".
>
>Next set your PATH again, but this time use the directory for 3.2.3 ("echo
>$PATH" plus selecting and pasting is your friend here, cause you don't want
>to *extend* your path, but replace it; or simply start a new console
>windows and append the path there now that I think about it ?).
>
>Now you should have a working FPC and you can compile Lazarus from source
>(sorry, don't know how to setup fpcupdeluxe to use an existing compiler,
>cause I don't use it).
>
>In Lazarus you then also need to set the path to your compiler.
>

I might have this wrong, but in that case I have been for many (10+) years...

I always put my sources in a place like $HOME/devtools/fpc/x.y.z and
$HOME/devtools/lazarus/x.y.z

And I use make install pointing to a place below $HOME as well...

When installing from sources you have a hen-and-egg problem since you need a
seed compiler on the pristine target system.

Usually I have been using a compiler from an earlier build on a similar system
but in this case I did not have one for 64 bit Pi-OS. First time on 64 bit.

So I tried using fpcupdeluxe instead with the results shown.

But then I checked if I could get the compiler via apt and that did succeed and
I could use it to build Lazarus itself.

And Lazarus works with this compiler on the target system.

Now I figured I had a seed compiler so I should be able to build a new fpc
compiler from sources using the commands I had always used in the past, but this
is where it went astray as shown.

I did not know that there is a library of seed compilers available on
Sourceforge, I thought everything had moved over to GitLab nowadays, so where
exactly can I find a binary download for PiOS 64 bit on SF?
Where I have looked I only find old stuff like from 2021...

https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/
Here are tarballs that by the size seem to contain a lot of stuff apart from the
compiler itself.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Cannot build fpc on Raspberry Pi4B running PiOS 64 bit (aarch64 Linux)

2023-11-18 Thread Bo Berglund via fpc-pascal
On Fri, 17 Nov 2023 11:27:53 +0100, Sven Barth via fpc-pascal
 wrote:

>Bo Berglund via fpc-pascal  schrieb am
>Do., 16. Nov. 2023, 08:19:
>
>> From the Lazarus list:
>>
>> >Just a quick follow-up here:
>> >It seems like the fpc sources have not been updated with the solution to
>> the bug
>> >discussed here:
>> >
>> >https://gitlab.com/freepascal.org/fpc/source/-/issues/39295
>> >
>> >This causes the build of Lazarus using fpcupdeluxe with the latest fpc
>> 3.2.2 to
>> >fail because of a problem with __libc_csu_init during linking.
>> >
>> >Apparently it is fixed in non-released sources of fpc which we are waiting
>> >for...
>>
>> The GitLab ticket was opened 2 years ago:
>> https://gitlab.com/freepascal.org/fpc/source/-/issues/39295
>>
>> According to a post on the Lazarus forum the fix that solves the fatal
>> error
>> during fpc build on 64 bit aarch64 Linux (like on Raspberry Pi4B with
>> Pi-OS 64
>> bit) has *not* been ported to the target aarch64 Linux, only to powerpc.
>>
>>
>> https://forum.lazarus.freepascal.org/index.php/topic,34645.msg496883.html#msg496883
>
>
>Wrong. Who said that the solution consisted only of a single commit?
>
>
>>
>> So I am sitting here unable to run Lazarus/FPC on the RPi4B with the
>> latest 64
>> bit Pi-OS...
>>
>> Is any solution to this problem in the works?
>> I have tried every fpc source release from 3.2.2 up to trunk with the
>> exact same
>> result (here from a build try on trunk):
>>
>> /bin/ld:
>> /home/bosse/devtools/lazarus/2.2.6/fpcsrc/rtl/units/aarch64-linux/cprt0.o:
>> in
>> function `_start':
>> (.text+0x54): undefined reference to `__libc_csu_init'
>> /bin/ld: (.text+0x58): undefined reference to `__libc_csu_init'
>> /bin/ld: (.text+0x5c): undefined reference to `__libc_csu_fini'
>> /bin/ld: (.text+0x60): undefined reference to `__libc_csu_fini'
>> make[1]: *** [Makefile:2682: packages_smart] Error 2
>> make: *** [Makefile:2837: build-stamp.aarch64-linux] Error 2
>> fpmake.pp(60) Error: Error while linking
>> fpmake.pp(60) Fatal: There were 1 errors compiling module, stopping
>> Fatal: Compilation aborted
>>
>> I believe that a lot of people will experience this since the 64 bit OS on
>> RPi4
>> has been recently released as the *recommended* version on that popular
>> platform...
>>
>
>I can not reproduce. On a Raspberry OS 10 64-bit I downloaded FPC 3.2.2 for
>aarch64-linux from SourceForge as well as the sources of both 3.2.3 and
>3.3.1 from GitLab.
>I install 3.2.2, setup PATH to find the compiler and simply do the
>following for each 3.2.3 and 3.3.1 (in their corresponding source
>directories):
>
>make all FPMAKEOPT="-T 4" -j 4
>make install INSTALL_PREFIX=/path/for/fpc/ - j 4
>cd /path/for/fpc//bin
>ln -s .. /lib/fpc//ppca64 ppca64
>
>(the -T and -j are simply for parallel compilation)
>
>Both 3.2.3 and 3.3.1 (don't forget to set PATH correctly!) can successfully
>compile a hello world program that links against the C library (in my case
>by using the cthreads unit) while 3.2.2 can not (as expected).
>

Hi Sven,
I realized that my tests were not really isolating the problem tp fpc...
I was using fpcupdeluxe for aarch64 to install the Lazarus environment.
That always failed with the error I showed.


Today after realizing that I did the following on an RPi4B where I have used apt
to install the fpc compiler so I could use that as the seed compiuler to build
from sources.

Then I retrieved the fpc 3.2.2 sources from GitLab and extracted them into dir
$home/devtools/fpc/3.2.2

Next I ran these two commands in the 3.2.2 directory:
make clean FPC="/usr/bin/ppca64"  This succeeeded
time make all FPC="/usr/bin/ppca64" This ran for 5m23s and then displayed:

make[3]: Leaving directory '/home/bosse/devtools/fpc/3.2.2/packages/fpmkunit'
/home/bosse/devtools/fpc/3.2.2/compiler/ppca64 fpmake.pp
-Fu/home/bosse/devtools/fpc/3.2.2/packages/fpmkunit/units_bs/aarch64-linux
-Fu/home/bosse/devtools/fpc/3.2.2/rtl/units/aarch64-linux
Free Pascal Compiler version 3.2.2 [2023/11/18] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for AArch64
Compiling fpmake.pp
fpmake.pp(16,3) Note: Local variable "T" is assigned but never used
Assembling fpmake
Linking fpmake
/usr/bin/ld: /home/bosse/devtools/fpc/3.2.2/rtl/units/aarch64-linux/cprt0.o: in
function `_start':
(.text+0x54): undefined reference to `__libc_csu_init'
/usr/bin/ld: (.text+0x58): undefined reference to `__libc_csu_init'
/usr/bin/ld: (.text+0x5c): undefined reference to `__libc_csu_fini'
/usr/bi

[fpc-pascal] Error when building fpc on aarch64-linux still not resolved

2023-11-16 Thread Bo Berglund via fpc-pascal
I tried to post this to the devel list but it seems to have failed so now trying
the general list instead...

See ticket:
https://gitlab.com/freepascal.org/fpc/source/-/issues/39295

It was closed a year ago being purportedly resolved...

But only for powerpc 64 bit...

It is still there for aarch64-linux used by Pi-OS bookworm 64 bit, which is now
the recommended version...

RaspberryPi is a very popular platform so a solution for that is needed.

I have tried building (via fpcupdeluxe) several revisions of fpc up to and
including trunk, but all fail with the same error outlined in the ticket above.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Cannot build fpc on Raspberry Pi4B running PiOS 64 bit (aarch64 Linux)

2023-11-16 Thread Bo Berglund via fpc-pascal
On Thu, 16 Nov 2023 08:19:17 +0100, Bo Berglund via fpc-pascal
 wrote:

>I have tried every fpc source release from 3.2.2 up to trunk with the exact 
>same
>result (here from a build try on trunk)

Forgot to mention that I am using fpcupdeluxe when installing fpc/lazarus on my
RPi4B with 64 bit Pi-OS bookworm operating system.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Cannot build fpc on Raspberry Pi4B running PiOS 64 bit (aarch64 Linux)

2023-11-15 Thread Bo Berglund via fpc-pascal
>From the Lazarus list:

>Just a quick follow-up here:
>It seems like the fpc sources have not been updated with the solution to the 
>bug
>discussed here:
>
>https://gitlab.com/freepascal.org/fpc/source/-/issues/39295
>
>This causes the build of Lazarus using fpcupdeluxe with the latest fpc 3.2.2 to
>fail because of a problem with __libc_csu_init during linking.
>
>Apparently it is fixed in non-released sources of fpc which we are waiting
>for...

The GitLab ticket was opened 2 years ago:
https://gitlab.com/freepascal.org/fpc/source/-/issues/39295

According to a post on the Lazarus forum the fix that solves the fatal error
during fpc build on 64 bit aarch64 Linux (like on Raspberry Pi4B with Pi-OS 64
bit) has *not* been ported to the target aarch64 Linux, only to powerpc.

https://forum.lazarus.freepascal.org/index.php/topic,34645.msg496883.html#msg496883

So I am sitting here unable to run Lazarus/FPC on the RPi4B with the latest 64
bit Pi-OS...

Is any solution to this problem in the works?
I have tried every fpc source release from 3.2.2 up to trunk with the exact same
result (here from a build try on trunk):

/bin/ld:
/home/bosse/devtools/lazarus/2.2.6/fpcsrc/rtl/units/aarch64-linux/cprt0.o: in
function `_start':
(.text+0x54): undefined reference to `__libc_csu_init'
/bin/ld: (.text+0x58): undefined reference to `__libc_csu_init'
/bin/ld: (.text+0x5c): undefined reference to `__libc_csu_fini'
/bin/ld: (.text+0x60): undefined reference to `__libc_csu_fini'
make[1]: *** [Makefile:2682: packages_smart] Error 2
make: *** [Makefile:2837: build-stamp.aarch64-linux] Error 2
fpmake.pp(60) Error: Error while linking
fpmake.pp(60) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

I believe that a lot of people will experience this since the 64 bit OS on RPi4
has been recently released as the *recommended* version on that popular
platform...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Difference between string and Tbytes as procedure arguments?

2023-11-05 Thread Bo Berglund via fpc-pascal
On Sun, 5 Nov 2023 10:36:47 +0100 (CET), Michael Van Canneyt via fpc-pascal
 wrote:

>> So my question is this:
>> Is there a difference in handling the arguments between string, AnsiString,
>> RawByteString and TBytes in a declaration like this:
>>
>> function TSSConnection.ParseCmdFileData(var SSCmdFile: TSSCommandFile; Buf:
>> AnsiString): boolean;
>>
>> and this:
>>
>> function TSSConnection.ParseCmdFileData(var SSCmdFile: TSSCommandFile; Buf:
>> TBytes): boolean;
>>
>> In the first instance it looks like the function receives a *copy* of the 
>> data
>
>No, but an ansistring is copy-on-write. As soon as you change it, a copy is
>made if your routine is not the only one using the string.
>
>> in the Buf argument and in the second case it receives a pointer to the 
>> actual
>> live data such that in the first case the argument source remains untouched
>> whereas in the second case the argument source is changed just as it had been
>> declared as var...
>
>That is correct. TBytes is a fancy wrapper around a pointer with some
>reference counting added to the mix.
>
>>
>> Is there a way to simply tell Delphi/FreePascal to treat also TBytes as copy
>> rather than a pointer to the real data?
>
>You must copy the data. The copy() function can be used for this.

Follow-up question:

Can I change the function declaration like this and preserve the content?

function TSSConnection.ParseCmdFileData(var SSCmdFile: TSSCommandFile; const
Buf:  TBytes): boolean;

Or must I copy the argument Buf inside the function to a local BufL version?
That is what you adviced, right?

Note: I have now found another function that changes the content of the Buf
argument and it too causes havoc...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Difference between string and Tbytes as procedure arguments?

2023-11-05 Thread Bo Berglund via fpc-pascal
I am maintaining an old utility program that started out about 20+ years ago
using Delphi7.

The utility communicates via RS232 with a measuring system in order to retrieve
and process recorded data and at the time this was started I used strings as
buffers for the serial comm.

A string at the time was really just an array of 1-byte characters but it had
useful functions for manipulating data inside so it made sense to use strings at
the time.

But as time evolved and Borland changed the meaning of string to now be
unicodestring it could no longer be used as a comm buffer, so I switched
declaration to AnsiString or even RawByteString to keep the existing utility
tools operational.

New programs I wrote would use TBytes as buffer instead...

Then about 6-7 years ago I had to do a major overhaul of the program in order to
improve the user interface and add support for switching languages in the UI and
at that time I also tried my best to replace the AnsiString buffers with TBytes
buffers. At this time I was on Delphi XE5.

It all looked OK until I recently got a call from a distributor who had
discovered that for a certain type of seldom used data collection mode the
output was corrupted when transfered to disk

And now I have found that the corruption happens inside a function that analyzes
one of the data packets where it will remove the start header record from the
buffer and then continue parsing the data items. (The buffer is sent in as a
regular argument without the var specifier).

Following this analysis in main code the buffer itself (that was used in the
previous call) is saved to disk in binary format.
And here is the problem:

The saved image of the buffer lacks the header part (30 bytes)...

So my question is this:
Is there a difference in handling the arguments between string, AnsiString,
RawByteString and TBytes in a declaration like this:

function TSSConnection.ParseCmdFileData(var SSCmdFile: TSSCommandFile; Buf:
AnsiString): boolean;

and this:

function TSSConnection.ParseCmdFileData(var SSCmdFile: TSSCommandFile; Buf:
TBytes): boolean;

In the first instance it looks like the function receives a *copy* of the data
in the Buf argument and in the second case it receives a pointer to the actual
live data such that in the first case the argument source remains untouched
whereas in the second case the argument source is changed just as it had been
declared as var...

Is there a way to simply tell Delphi/FreePascal to treat also TBytes as copy
rather than a pointer to the real data?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Serial connection via TCP/IP sockets on RPi?

2023-11-04 Thread Bo Berglund via fpc-pascal
On Fri, 03 Nov 2023 19:47:01 +0100, Bo Berglund via fpc-pascal
 wrote:

>I have now found that there is a Linux utility named socat, which apparently is
>able to map a serial port to a network socket server:
>
>https://www.acmesystems.it/socat
>
>Here they actually use ser2net as the remote server point and socat to connect
>to it
>
>Seems like a possible path to go down.
>

UPDATE:

I solved the problem using ser2net on the remote site's RPi3 to publish a
connection to the RPi serial0 device, which is hardwired to the measuring
equipment. This implements a server on port 2001 (my choice) to the serial
connection.

Back at home I have this other RPi4 device on which I have an exposed connector
to the serial0 port, to which I can connect a serial/usb cable from my Windows10
development machine.

After installing socat on the RPi4 I can start it with the remote RPi3
address:2001 as connection parameter for the port and destination.
And this RPi4 has already a VPN connection to the remote network.

So after I opened the VPN connection and started socat I could run the control
program on my Win10 laptop against the equipment across the ocean!
Worked amazingly well!

And no development required on my part.
Just get socat and ser2net via apt on the RPi devices...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Serial connection via TCP/IP sockets on RPi?

2023-11-03 Thread Bo Berglund via fpc-pascal
On Fri, 03 Nov 2023 17:34:09 +0100, Bo Berglund via fpc-pascal
 wrote:

>So ser2net seems like a logical use given that the RPi3 is already there
>connected by wire to the serial line and is available via VPN on the network. I
>have just checked (using PuTTY via VPN) that the RPi3 does not yet have a
>ser2net installed but there is a candidate 3.5-2 available via apt.
>
>So if I shut down the existing control software then the serial port becomes
>free to use with ser2net, I guess.

I have now found that there is a Linux utility named socat, which apparently is
able to map a serial port to a network socket server:

https://www.acmesystems.it/socat

Here they actually use ser2net as the remote server point and socat to connect
to it

Seems like a possible path to go down.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Serial connection via TCP/IP sockets on RPi?

2023-11-03 Thread Bo Berglund via fpc-pascal
On Fri, 3 Nov 2023 06:47:30 -0700, Wayne Sherman via fpc-pascal
 wrote:

>Yes, there is software that bridges a serial connection over a
>network.  On Windows it is often called a "virtual com port" or
>"virtual serial port" or "com port redirector".
>
>Open Source Linux:
>ser2net
>https://github.com/cminyard/ser2net
>(ser2net is available in many distro package managers)

Thanks a lot for your pointers!!!

I have looked up your links on ser2net and gogled a bit, but I see many
references to using the system with *Telnet* apparently to log in to a console
command window or such.

That is not my application, all transfers are binary in nature with data as big
as 1 Mbytes but sent as packets with checksums.

Question:
-
Does ser2net interfere with the data transfer by assuming "control chars" or the
like?
If so it cannot be used for my application even though it looked promising when
I started to read about it.

OTOH:
If these mentions of Telnet are only examples and ser2net actually does not
assume anything at all about the data being sent/received, then this seems like
what I need.

In fact the device hooked to the measure system is an RPi3B using the serial
port on the RPi and it works fine using the custom automation software.

But now I need to troubleshoot the Windows general user interface to the system
from afar and I need the link via the network.

So ser2net seems like a logical use given that the RPi3 is already there
connected by wire to the serial line and is available via VPN on the network. I
have just checked (using PuTTY via VPN) that the RPi3 does not yet have a
ser2net installed but there is a candidate 3.5-2 available via apt.

So if I shut down the existing control software then the serial port becomes
free to use with ser2net, I guess.

So then I need to do the Windows side as well to complete the system.
I assume ser2net is a server only software so one cannot connect two ser2net to
each other and then use the serial ports in both ends to complete the
connection?

I.e. on my location using another RPi3 to expose its serial port as an entry
point towards the other end would not be possible, right?

Or can ser2net in fact run as a client too and connect to another instance
running as a server?
If so all I need is an RPi here that can VPN over to the remote LAN (it can, I
use that for subversion commits) and on which I install ser2net too but as a
client and I now have a serial port to hook my Windows system into...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Serial connection via TCP/IP sockets on RPi?

2023-11-03 Thread Bo Berglund via fpc-pascal
I am wondering if there is already available what I am needing?
My situation is the following:

I have a remote installation of a measuring equipment, which communicates
through RS232 to an RPi3 interface unit. On that there is a service that handles
the data sent both ways. But it is geared towards automatic operations so there
is no direct connection to the target system.

Now I have a need to debug a Windows application that is also designed to talk
to the same type of equipment via RS232. But the problem is that I am across the
ocean from the equipment, so I need to insert some network link between me and
the remote system.

I have a VPN connection to the remote location so I can work on the RPi3 command
line (and actualy also via VNC on the GUI). So a socket client/server solution
seems possible.

What I want to do is this:
- close down the existing service on the RPi3 that handles the data recording.
- Use an RS232 <=> TCP/IP socket service on the RPi3 to transfer data to/from
the device
- Set up a TCP/IP socket <=> RS232 handler on a local RPi4 in my location
- Connect the Windows RS232 to the RPi4 by wire
- Use the application under debug normally via RS232 from Windows but have the
RPi pair move the data between the endpoint RS232 connections via TCP/IP through
the VPN connection.

Before I start coding the RS232/Socket interface server and client parts myself
I would like to know if someone here knows about an already existing Lazarus
open source project that implements my wanted functionality?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why does RunCommand not produce the correct output?

2023-05-02 Thread Bo Berglund via fpc-pascal
On Mon, 01 May 2023 11:00:56 -0400, Bo Berglund via fpc-pascal
 wrote:

>I am trying to create a function to list the available serial ports on a Linux
>device. But I have trouble getting commands which work on a terminal to also
>work when run from my console program.
>
>When I run this conmmand in the terminal I get the correct reply:
>
>$ ls -l /sys/class/tty/*/device/driver | grep -v "platform/drivers/serial8250" 
>|
>awk '{print $9}' | awk -F'/' '{print "/dev/" $5}'
>
>/dev/ttyAMA0
>
>But when I use RunCommand() in FPC it does not work.

I have asked on the Lazarus forum too and there I gotr a solution for my base
problem so I do not need to use complex commands vua RunCommand.
See this thread:

https://forum.lazarus.freepascal.org/index.php/topic,63256.msg478804.html#msg478804


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why does RunCommand not produce the correct output?

2023-05-01 Thread Bo Berglund via fpc-pascal
On Mon, 1 May 2023 14:25:28 -0400, Travis Siegel via fpc-pascal
 wrote:

>You could just add the line:
>
>#!/bin/bash
>
>to the first line of your script, then just call the script from your 
>program.
>
>Alternatively, you could call the bash command, and pass the command to 
>it that way, either one should get you the output you desire.

I did already create a script "listserial" that does the extraction:
(long line split by newsreader)

-
#!/bin/bash
SERLIST=$(ls -l /sys/class/tty/*/device/driver | grep -v
"platform/drivers/serial8250" | awk '{print $9}' | awk -F'/' '{print "/dev/"
$5}')
echo $SERLIST
-

This successfully lists the available serial ports by their device name, which
can be used to open the port using the built-in serial unit functionality.

Of course I *could* call the script from the program but I wanted it all be
within the FPC program itself...

But it can be done by calling the standalone script file of course...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Why does RunCommand not produce the correct output?

2023-05-01 Thread Bo Berglund via fpc-pascal
I am trying to create a function to list the available serial ports on a Linux
device. But I have trouble getting commands which work on a terminal to also
work when run from my console program.

When I run this conmmand in the terminal I get the correct reply:

$ ls -l /sys/class/tty/*/device/driver | grep -v "platform/drivers/serial8250" |
awk '{print $9}' | awk -F'/' '{print "/dev/" $5}'

/dev/ttyAMA0

But when I use RunCommand() in FPC it does not work long line wrapped by
newsreader):

program listserialports;
{$mode objfpc}{$H+}

uses
  baseunix, classes, sysutils, process;

function ListSerialPorts: integer;
var
  ListCmd: TProcessString;
  OutData: string;
begin
  Result := 0;
  ListCmd := 'ls -l /sys/class/tty/*/device/driver | grep -v
"platform/drivers/serial8250" | awk ''{print $9}'' | awk -F''/'' ''{print
"/dev/" $5}''';
  Writeln('Command: ' + ListCmd); //To see what is actally sent to Linux
  RunCommand(ListCmd, OutData);
  Writeln(OutData);
end;

begin
  ListSerialPorts;
  Writeln('Done');
end.

I see the command being executed but there is an empty output.
If I copy the dislayed command and paste it in and run it I get the result as
shown above. So there should be no typo in the command line, right?
Still no output...

What can I do?
(I have created a shellscript with the same command string and it runs just fine
and prints the data on screen.
But I need the function in order to populate a control with the output inside a
GUI program once thus function works.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to use StrToDateTime() to convert a string with no delimiters?

2023-04-25 Thread Bo Berglund via fpc-pascal
On Tue, 25 Apr 2023 08:25:01 +0200 (CEST), Michael Van Canneyt via fpc-pascal
 wrote:

>
>
>On Mon, 24 Apr 2023, Thomas Kurz via fpc-pascal wrote:
>
>> I always use ScanDateTime for such purposes:
>>
>> https://www.freepascal.org/docs-html/rtl/dateutils/scandatetime.html
>>
>> You can explicitly define the pattern.
>
>Correct. This is the only correct way to do this.
>
>StrToDateTime is very limited in what it accepts.
>
>Michael.

Thanks, I did not know about this before, but now it is inserted in my code and
works fine. :-)

So now I can just specify the pattern of data to be scanned using the y, m, h, n
and s letters.
But I am adding 20 on front of the telegram value because that uses only a
2-digit year and I had problems on my new RPiZero until I added the two yy in
front of the pattern making it a 4-char year and the 20 in front of the
telegram.

Then all works fine.

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] How to use StrToDateTime() to convert a string with no delimiters?

2023-04-24 Thread Bo Berglund via fpc-pascal
I have a device that sends data over the serial port with a timestamp in this
format:

(230424194642W)

This is coded as yymmddhhnnss and the last char designates daylight savings
(S)ummer or normal (W)inter time. In the example above it is W for normal winter
time.

What I have done so far is:
- Remove the () at start and end
- Remove the W at the end
- Add 20 (as the century) up front
- Insert a space after the 6th char (so between date and time
- Set the TFormatsettings like this (to say that there are no separators):
  FS.DateSeparator := #0; (Is this how it is done?)
  FS.TimeSeparator := #0;
- Then the call:
  Value := StrToDateTime(sValue, FS); (Value is declared as TDateTime)

This triggers an exception with the message:
 "194522" is not a valid time

What is the proper way to decode a string as shown above?
Since the date part could be decoded, why not also the time part, after all I
separated the two with a space and set the same separators?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is there a Pos() function for TBytes?

2023-04-20 Thread Bo Berglund via fpc-pascal
On Thu, 20 Apr 2023 08:40:48 +0200 (CEST), Michael Van Canneyt via fpc-pascal
 wrote:

>> I found this page:
>> https://www.freepascal.org/docs-html/rtl/system/copy.html
>>
>> Here there is also reference to the other functions for strings:
>> Delete  (string and dyn array)
>> Copy(string and dyn array)
>> Insert  (string and dyn array but limited to 255 elements, why?)
>> Pos (string only..)
>>
>> They describe what can be done with strings and in some cases dynamic arrays
>> (like TBytes?), but for Pos() there is only string...
>>
>> And Insert seems to have a limit of 255 elements, why?
>>
>> What I need is a Pos(token) for TBytes where the token can be a single or
>> multiple bytes in size (just like for strings).
>>
>> Is there such a thing?
>
>Not that I am aware of, but I think it would be a welcome addition to one of
>the RTL units. I've been in need of such a function on multiple occasions,
>and had to resort to custom code each time.
>

FWIW, I threw together two overloaded Pos functions for a TBytes container like
this (except I didn't name them Pos in order not to interfere with the RTL):

function PosInBytes(const Pattern, Target: TBytes): integer; overload;
function PosInBytes(const Pattern: byte; const Target: TBytes): integer;
overload;

implementation

function PosInBytes(const Pattern, Target: TBytes): integer;
var
  i, j, res: integer;
begin
  Result := -1;
  for i := 0 to Length(Target) - 1 - Length(Pattern) do
  begin
if Target[i] = Pattern[0] then  //First byte of pattern found
begin
  res := i;
  for j := 1 to Length(Pattern)-1 do
  begin
if Target[i+j] <> Pattern[j] then
begin
  res := -1;
  break;
end;
  end;
  if res >= 0 then break;
end;
  end;
  Result := res;
end;

function PosInBytes(const Pattern: byte; Target: TBytes): integer;
var
  i: integer;
begin
  Result := -1;
  for i :=  0 to Length(Target) - 1 do
  begin
if Target[i] = Pattern then
begin
  Result := i;
  break;
end;
  end;
end;


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Is there a Pos() function for TBytes?

2023-04-20 Thread Bo Berglund via fpc-pascal
I am transferring data via serial comm and they wind up inside a TBytes dyn
array.
Now I want to easily find a certain pattern of bytes inside that array, but how?

I have a cludge that does not feel right but works and I want to get it replaced
by the "correct" way of doing it.

So what I have done so far is the following kind of thing using an AnsiString to
supply the Pos() functionality:

var
  bData: TBytes;
  sData: AnsiString;
  p: integer;
begin
  GetSerialData(bData); //Load the array with incoming data
  SetLength(sData, Length(bData); //Prepare string to receive data
  Move(bData[0], sData[1], Length(bData)); //Copy all data
  p := Pos(pattern, sData);
  ...

I'd rather use some built-in function that is *not* using intermediate strings
but can operate on the TBytes array directly.

I found this page:
https://www.freepascal.org/docs-html/rtl/system/copy.html

Here there is also reference to the other functions for strings:
Delete  (string and dyn array)
Copy(string and dyn array)
Insert  (string and dyn array but limited to 255 elements, why?)
Pos (string only..)

They describe what can be done with strings and in some cases dynamic arrays
(like TBytes?), but for Pos() there is only string...

And Insert seems to have a limit of 255 elements, why?

What I need is a Pos(token) for TBytes where the token can be a single or
multiple bytes in size (just like for strings).

Is there such a thing?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Declaring an array as var or not in function calls?

2023-04-12 Thread Bo Berglund via fpc-pascal
On Thu, 13 Apr 2023 00:06:16 +0200, Sven Barth via fpc-pascal
 wrote:

>Bo Berglund via fpc-pascal  schrieb am
>Mi., 12. Apr. 2023, 21:17:
>
>> Now my question:
>> 
>> Since I am modifying the WArgs variable inside the BuildArgumentsArray
>> function and using its new content afterwards in the WriteItem function
>> I assumed that I had to use var as shown above, but I am not certain this
>> is the case...
>>
>
>If you modify the length or the contents of a dynamic array parameter then
>you need to use "var" or "out" modifiers (the later only if you don't need
>the data passed in).

In this case I am assuming that there is no existing data because I change the
length of the array depending on the calculation of the number of needed calls
to complete the write operation.
So it is definitely only an "out" argument (I have never used out before...).

>
>> It seems like it works also if I do not use the vars specification...
>>
>
>It should not. If it does it will likely be an implementation detail and
>you shall not rely on it. Do you have an explicit example for this
>behavior?

Well, I think I have done this earlier but now I have made a quick test using
TBytes and it seems like var *is* needed...

Since I have not used out before I also tested that and it worked like var does.

What is the use case for "out" compared to "var" when it seemingly is doing the
same thing?
Or is it exactly this:
With "out" you get a pristine empty variable which you have to initialize if
needed (setting its length in this case)?
And you are ensured no stale data will be part of it?

>
>And if so, what is the rule for *when* to use var in function call argument
>> lists for items that will be changed inside the called function and used
>> afterwards
>>
>
>The rule is simple: if you need to modify the parameter value itself (e.g.
>changing a primitive type, changing a field in a record, changing an
>array's length or data, changing the value of a class instance - but not
>its fields!) you need to pass it as "var".
>If it's a write only parameter you can even use "out".

So "out" it is unless I need to use the existing data or append new data to it,
in which case I need "var", right?

Thanks!


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Declaring an array as var or not in function calls?

2023-04-12 Thread Bo Berglund via fpc-pascal
I am wondering how to deal with this var or not in function calls:

In a processing program where I am building the command arguments for a write
operation by analyzing incoming commands and splitting the data such that the
write can be fully done by executing a series of smaller write commands for
chunks of data.

The container for this is a dynamic array of write commands and this array is
part of the arguments for the build function.

Like this (simplified): 

type
  TWriteBytesArgs = record 
DeviceAddr: byte;
StartAddr: uint16;
SourceAddr: uint16;
NumWriteBytes: uint16;
NextSourceAddr: uint16;
  end;

  TWriteCommands = array of TWriteBytesArgs;


function BuildArgumentsArray(Arg: TWriteBytesArgs; var WArgs: TWriteCommands):
boolean;
var
  variables...
begin
  stuff...
  (Build arguments into WArgs)
end;

procedure main();
var
  WCmd: TWriteBytesArgs;
  WCmds: TWriteCommands;
  Data: TBytes; //Container for actual data
  i: integer;
begin
  ...
  - Fill Data array with values to write
  - Set values to WCmd record members
  if BuildArgumentsArray(WCmd, WCmds) then
  begin
for i := 0 to Length(WCmds) -1 do
  WriteItem(WCmd[i].DeviceAddr, WCmds[i].StartAddr, 
WCmd[i].SourceAddr, WCmds[i]NumWriteBytes, Data);
etc...

In main() the Arg record is analyzed by a call to BuildArgumentsArray and based
on that one or several actual smaller write commands will be generated. These
are written to the WArgs array.

So the WArgs dyn array is originally length zero, but inside the
BuildArgumentsArray function its length will be set to contain the needed write
commands to do the complete write.
And the caller can iterate over the array items and generate a write command for
each.

Now my question:

Since I am modifying the WArgs variable inside the BuildArgumentsArray function
and using its new content afterwards in the WriteItem function I assumed that I
had to use var as shown above, but I am not certain this is the case...

It seems like it works also if I do not use the vars specification...

What is the deal here, is this kind of variable written to inside a called
function not needing to be set as var and it will work anyway?

And if so, what is the rule for *when* to use var in function call argument
lists for items that will be changed inside the called function and used
afterwards?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Building trunk of today fails on Windows: Error: Invalid DLL C:\WINDOWS\system32\common.dll, invalid header size

2023-04-08 Thread Bo Berglund via fpc-pascal
On Mon, 23 Aug 2021 23:01:39 +0200, Bart via fpc-devel
 wrote:

Replying here since my attempt at replying in the devel group failed...


>On Mon, Aug 23, 2021 at 8:04 PM Bart  wrote:
>
>> And, of course, the guide on how to remove this utility
>> (https://www.intel.com/content/www/us/en/support/articles/32459/processors/processor-utilities-and-programs.html)
>> do not apply.
>> No XtuService in "Apps and Features", no XtuService.exe. in any of the
>> suggested locations.
>
>Finally good news.
>
>In taskmanager I had to stop one process,then go to services, find
>xtu3service.exe, right-click, then "open services", find that service
>again (now called XTUOCDriverService) in the newly opened window,
>right-click, select properties, then set Startup type (? "Opstart
>type") to Disabled.
>
>After a reboot I was able to rename that common.dll to _common.dll,
>rebooted again.
>All this as administrator of course.
>
>Finally after all that I was able to build fpc for 32-bit.
>
>And now just hoping that with the nex Windows update it won't get
>re-installed again.

Bart, thanks for this description which I found now 19 months later!

I had trouble when installing the Win32 version of Lazarus/Fpc using fpcupdeluxe
(needed because I wanted a cross-compile tool for RaspberryPi on my Windows10
x64 box).

The install failed no matter what I did with an error message that was hard to
decode for me.

Now I have done the following as described above:

- Started Servicemanager on my Win10 workstation.

- Found the Intel service "XTUOCDriverService" and stopped it

- Then I also set the type to disabled.

- But I did *not* reboot, instead I renamed the common.dll in
C:\Windows\SysWOW64 to _common.dll, which was allowed now.

- Then I just started the fpcupdeluxe 32 bit exe and commanded it to install
3.2.2/Lazarus 2.2.6. And this time it succeeded!

- So when it was done I could tell fpcupdeluxe to install the cross-compiler for
arm-linux, which it also successfully completed.

The base install took 19m30s and the cross another 5 minutes when it fetched the
various source files from the Internet.

And the new cross-compiler actually works to build applications for RaspberryPi
on Widows10! :-)

And Win64 applications from this 32 bit install as a cross...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-05 Thread Bo Berglund via fpc-pascal
On Wed, 5 Apr 2023 17:57:00 +0200, Christo Crause via fpc-pascal
 wrote:

>The use of WriteBytesToReg in the TI2c_eeprom.WriteData method seems fine,
>perhaps retest with the updated WriteBytesToReg method.

I pulled the i2c.pas file from GitHub (actually downloaded the zip since I don't
really know how git works (I use SVN myself), earlier today (at 12:01 in fact)
and made the tests using that.

But now I saw that there is an even newer version available, so I downloaded
that and lo-and-behold, the write does complete and the data are there in the
EEPROM!

Thanks for your updates to i2c.pas!

Now I will continue by handling the case of write page overlaps so it will be
dealt with in the code!

;-)



-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-05 Thread Bo Berglund via fpc-pascal
On Wed, 5 Apr 2023 11:40:09 +0200, Christo Crause via fpc-pascal
 wrote:
>Looking at the datasheet for CAT24C128, Fig. 6 Byte Write Sequence, shows
>no repeated start condition between register address and data bytes. I
>suspect that the second i2c message should contain the I2C_M_NOSTART flag,
>else the address and data parts of the transaction will be separated by a
>repeated start signal. I have modified the WriteBytesToReg methods in
>i2c.pas, please feel free to pull from Github and test this again.

Thanks, I did so and used it in my code but it still does not write the
EEPROM...

Here is the code I use to test (in a command line program), maybe you can see a
usage problem?

var
  i2cbus,
  dev_addr,
  reg_addr,
  data_cnt: integer;
  indata: TBytes;

procedure main_12c_write(); //This is the main application procedure
var
  i: integer;
  num: uint16;
  i2cEeprom: TI2c_eeprom;
begin
  processInputs; //Read command line and write to variables
  //Now process the data towards the EEPROM
  i2cEeprom := TI2c_eeprom.Create; //Defaults are set for my EEPROM
  try
num := i2cEeprom.WriteData(reg_addr, data_cnt, indata);
Writeln('Wrote ' + IntToStr(num) + ' bytes to address $' +
IntToHex(reg_addr,4) );
  finally
i2cEeprom.Free;
  end;

function TI2c_eeprom.WriteData(StartAddress, NumBytes: uint16; Source: TBytes):
uint16;
var
  endpos, capacity, addr: uint16;
  i2cMaster: TI2cMaster;
  i2cbus: TI2CBus;
  sourcelen, i, j: integer;
  pSource: PByte;
begin
  Result := 0;
  //Check valid indata:
  //snip
  //Prepare the handler for action...
  i2cbus := TI2CBus(FI2cBusNo);
  i2cMaster := TI2cMaster.Create;
  try
if not i2cMaster.Initialize(i2cbus) then
begin
  writeln('Error opening i2c device: ', FI2cBusNo);
  exit;
end;

//Check if data will fit into a single page start at given address:
if ((StartAddress and $ffc0) = (endpos and  $ffc0)) then //Fits in page
begin
  //Perform a single write cycle into the buffer
  pSource := @source[0];
  if not i2cMaster.WriteBytesToReg(FEEPROMAddr, startaddress, pSource,
NumBytes) then
  begin
Writeln('Error: Could not write to I2C device!');
exit;
  end
  else
Result := NumBytes;
end
else  //We need to split data over several commands
begin
  Writeln('Not yet implmented data split into several writes');
end;
  finally
i2cMaster.Free;
  end;


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-04 Thread Bo Berglund via fpc-pascal
On Wed, 05 Apr 2023 00:33:50 +0200, Bo Berglund via fpc-pascal
 wrote:

>On Tue, 4 Apr 2023 23:43:21 +0200, Christo Crause via fpc-pascal
> wrote:
>
>
>>Is your startaddress variable an unsigned 16 bit integer
>>(word/uint16)? If not, type cast this to a uint16 to ensure the compiler
>>calls the correct overloaded method.

Did not answer the type question:
Yes, that has always been a uint16 for the reason you outline: to select the
correct overloaded method.


>>
>>Passing the address of the first element of a TBytes array as you did above
>>is correct.
>
OK, I thought so. It has been there with some variations all the time.
>
>
>Note: I have not changed anything inside the i2c.pas file...

This was just to point out that I am not modifying this base file, just using
it.

Another observation:

I *can* write a sequence of bytes into the EEPROM succsessfully using an
i2c-tools command like this:

i2ctransfer -y 1 w18@0x50 0x00 0x38 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08
0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f

This writes data starting towards the end of the page and wraps around such that
part of the data gets to the start of the page.

It shows:
- It is possible to write the data in one go
- If the data length is past the end of the page it wraps around to the
beginning

So if the problem cannot be solved then I could either use the loop with delay
or call the i2c-tools command i2ctransfer as a TProcess execution to write
multiple bytes in one command.

But I would rather not use the TProcess method at all since it relies on an
external tool being present and the argument list can be pretty long and tedious
to build...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-04 Thread Bo Berglund via fpc-pascal
On Tue, 4 Apr 2023 23:43:21 +0200, Christo Crause via fpc-pascal
 wrote:


>> if not i2cMaster.WriteBytesToReg(FEEPROMAddr, startaddress, @source[0],
>> NumBytes) then
>>
>> Here the source argument is a TBytes array of bytes so I supply the
>> address of
>> element 0 as the data argument (expected to be a PByte).
>>
>
>This is the correct way of passing the starting address of your data
>buffer.  Is your startaddress variable an unsigned 16 bit integer
>(word/uint16)? If not, type cast this to a uint16 to ensure the compiler
>calls the correct overloaded method.

OK, I have tested various similar ways but all fail to work.

>
>
>Note that I haven't tested WriteByteToReg with a device supporting 10 bit
>register addresses, or in your case 16 bit...

Actually it is more like 14 bits (16 kbytes)

>
>Passing the address of the first element of a TBytes array as you did above
>is correct.

OK

>
>I will look at the EEPROM datasheet, in case the details do not agree with
>the WriteBytesToReg implementation.

I have two cases here, writing a single byte, which works and writing an array
of byte which does not work...
Everything else seems to work fine.


So I have been fiddling with this the whole evening and I am not getting it to
work the supposed way...

So I changed as a test to use the following code instead:
Source is a TBytes container, startaddress and addr are uint16

j := 0;
for i := 0 to Length(Source)-1 do
begin
  addr := startaddress+i;
  if not i2cMaster.WriteByteToReg(FEEPROMAddr, addr, source[i]) then break;
  Inc(j);
  Delay(10);//Delay(1) does not work...
end;
Writeln('Wrote ' + IntToStr(j) + 'bytes');

With this in place it works to write a TBytes data to the EEPROM but only 100
bytes/second.

But this does not work (nothing winds up into the EEPROM):

pSource := @source[0];
NumBytes := Length(source);
i2cMaster.WriteBytesToReg(FEEPROMAddr, startaddress, pSource, NumBytes)

This does not generate any errors but nothing winds up into the EEPROM...

Note: I have not changed anything inside the i2c.pas file...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-04 Thread Bo Berglund via fpc-pascal
On Sun, 02 Apr 2023 23:21:38 +0200, Bo Berglund via fpc-pascal
 wrote:

>On Sun, 2 Apr 2023 23:14:25 +0200, Christo Crause via fpc-pascal
> wrote:
>
>>On Sun, Apr 2, 2023 at 9:30?PM Bo Berglund via fpc-pascal <
>>fpc-pascal@lists.freepascal.org> wrote:
>>
>>> Is there a reason that there is no i2c_write_reg demo in the github
>>> package?
>>>
>>
>>I haven't gotten round to that, waiting for hardware to test the code with.
>>
>>I will try to write one so I can test that as well...
>>>
>>Would be nice if you could share that :-)
>
>Sure, I will probably continue with this tomorrow (I'm in Europe so it is soon
>midnight here...).
>
>If I get it going I will post it or else I will ask about it here.
>
>My hardware is ready and operational, in fact my board also has another EEPROM
>(same type) sitting on the i2c-0 bus prepared for being used as a HAT EEPROM.
>Haven't gotten that far on the HAT handling though so it is totally unused.

So now I have created a new class TI2c_eeprom, that uses the i2c.pas file to do
the actual i2c handling.
In this class I have tested the read and write functionality and I have the
following findings:

1) The read works just fine for what I have done so far.
 
2) But I have problems with the write functions for multiple data

I use the method:
 
i2cMaster.WriteBytesToReg(i2caddress: byte; regAddress: uint16; data: PByte;
size: byte): boolean;)

With data specified as follows in the call:

if not i2cMaster.WriteBytesToReg(FEEPROMAddr, startaddress, @source[0],
NumBytes) then

Here the source argument is a TBytes array of bytes so I supply the address of
element 0 as the data argument (expected to be a PByte).

When I step through this in the debugger and get into the method itself I can
see that the source argument contains the data I have loaded into it, so the
data is there.

When I run that method to the end and it finishes without error, I still cannot
see the data in the EEPROM at the given address.

So for testing I changed the call to be:
if not i2cMaster.WriteByteToReg(FEEPROMAddr, startaddress, source[0]) then

This uses the method to write a single byte to the i2c device and it works just
fine!

So either there is a problem with the WriteBytesToReg() method or else my use of
it...
What comes to mind is the data type PByte, which I have never used before and do
not know if it is valid.

I am keeping the data in a dynamic array of bytes (the pascal type TBytes) and
send the address of element 0 of that array as the argument to the method.
Is this wrong?
If so what should I use instead?
Can I typecast it like this:

if not i2cMaster.WriteBytesToReg(FEEPROMAddr, startaddress, PByte(source),
NumBytes) then
(Tried it and it does not work)



Seems like I am getting close but missing something important...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-03 Thread Bo Berglund via fpc-pascal
On Mon, 03 Apr 2023 15:09:38 -0400, Dennis Lee Bieber via fpc-pascal
 wrote:

>On Mon, 03 Apr 2023 20:55:43 +0200, Bo Berglund via fpc-pascal
> declaimed
>the following:
>
>>I just tested by writing four 0x00 bytes in a row, then verifying that the
>>memory read shows these, then writing other data and again verifying that the
>>data is there.
>>
>
>   Which may only mean the chip has an on-board controller and memory
>buffer, and the chip is performing the page level erase followed by buffer
>write.

Yeah, seems like this is happening as I just wrote in another reply...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-03 Thread Bo Berglund via fpc-pascal
On Mon, 3 Apr 2023 14:37:48 -0400, "Jeffrey A. Wormsley via fpc-pascal"
 wrote:

>I noticed you put the part number in the original email.
>
>Interestingly, the data sheet mentions 64 byte pages, and 1,000,000 erase
>cycles, but does not mention the need to erase a page before writing.  So
>perhaps this part does not have that restriction.
>
>If you're making a library specifically for this part, then I guess you
>don't have to worry about this.  If you're making a library for generic
>eeprom support, I think you might want to consider that not all parts
>behave this way.

You alerted me to the page size which I have been mis-reading until now it seems
like...
This 128 kbit part is apparently built like this:

- 16384 memory bytes
- Organized as 256 64 byte "pages"
- The page write buffer is 64 bytes, i.e. the same size as a memory "page"

Then there is a discusion about the way the write buffer maps onto the memory
array, which I didn't understand fully...

[quote]
Page Write
By continuing to load data into the Page Write Buffer after
the 1st data byte and before issuing the STOP condition, up
to  64  bytes  can  be  written  simultaneously  during  one
internal Write cycle (Figure 8). If more data bytes are loaded
than locations available to the end of page, then loading will
continue from the beginning of page, i.e. the page address is
latched and the address count automatically increments to
and then wraps-around at the page boundary. Previously
loaded data can thus be overwritten by new data. What is
eventually written to memory reflects the latest Page Write
Buffer contents. Only data loaded within the most recent
Page Write sequence will be written to memory.
[/quote]

Maybe it is like this:

The page write buffer is 64 bytes and incoming data are written to the buffer
starting at an address (I assume) within that buffer given by the last 6 bits of
the address being written in the command.

This to me reads like the same place in the buffer as eventually in the memory
*page* when written.
And if one continues to send data to the part after reaching the end of the
buffer it writes those to the beginning of the buffer instead (wrap-around,
which is bad and will destroy data).

Finally when the transfer is ended (STOP condition) then the buffer somehow is
moved onto the main memory.

Here I am unclear on how it works, one possibility would be that there is some
bit field or similar on chip that marks bytes in the buffer that have been
written by incoming data. Then all other bytes can be filled from the page in
main memory by reading those to unwritten locations in the buffer.

Or else maybe simpler: when the write starts and the page is determined the
buffer may be filled from a main memory page copy and then overwritten by
incoming data...

Now the buffer has a content that is the same as in main memory except for the
data that were sent in.
So then the part may erase the page in main memory as you stated and once that
is done write the buffer content on top of the page that is now blanked out to
0xff cells.

I cannot think of any other procedure that matches what the datasheet says..
And if it is like this you are right that the cells must be bulk erased before
one can write random data there...
But it is handled without the user having to do anything at all...


Now I have to go back into my code and adjust the handling for the write buffer,
since I can only send in at most 64 bytes at a time and that only if the write
starts at 6 bit address 0 in the buffer. Otherwise less data can be written in
each cycle.

I am transfering the data to write to the write procedure as a TBytes array of
random size and the code needs to start (in most cases) by sending in a smaller
than 64 byte write packet and then fill with full 64 byte pages and then
finalize with a short page at the end of the write procedure. Unless everything
happens to align on 64 byte address boundaries...

Getting a bit dizzy...
But still the main Freepascal interface into Linux that I got from GitHub works
so this is just a case of sequencing the commands correctly! :-)

Thanks for making me read closer into the datasheet!


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-03 Thread Bo Berglund via fpc-pascal
On Mon, 03 Apr 2023 20:55:43 +0200, Bo Berglund via fpc-pascal >On Mon, 3 Apr
2023 14:26:17 -0400, "Jeffrey A. Wormsley via fpc-pascal"
> wrote:
>
>>I've been using i2c and SPI eeproms for almost two decades.  All of them
>>can read/write a single byte if that's what you want to do, but the
>>write/erase restrictions I noted are there for any parts I've ever used.
>>If you write a byte to $00, you cannot write it to $01 without first
>>erasing the entire block that it is located in (usually 128 to 256 bytes).
>>You can write $FF to $F0, then $F0 to $80, then $80 to $00, as these all
>>only involve turning 1 bits into 0 bits, but if you try to write from a $00
>>to a $01, then it will not work, at least not on any part I've ever used,
>>as that involves turning a 0 bit into a 1 bit.   All of the parts I've
>>seen, if you want to modify a single memory location (if the write involves
>>turning a 0 bit into a 1 bit), they require you to read the block of data
>>into your CPU, modify it there, erase the block, then write the entire
>>block data back into the chip.  I've seen some parts that have an on-chip
>>RAM buffer that would let you read the block into this RAM buffer with one
>>command, modify the RAM buffer with a single byte write, erase the block,
>>then write the RAM buffer back to the chip, which is a lot faster than
>>having to do this yourself with your CPU memory, but it still required the
>>block erase and that block erase still counted towards your maximum number
>>of erase cycles.  I have not seen a chip that allowed completely random
>>writes at the byte level before short of a static ram with battery backup.
>>
>>If you have an i2c part that doesn't work like this, then I would be very
>>interested in knowing the part number and seeing a link to the data sheet.
>>Such a part would make using these sorts of devices much easier, but to
>>date I have never seen one.
>>
>>Jeff
>>
>I just tested by writing four 0x00 bytes in a row, then verifying that the
>memory read shows these, then writing other data and again verifying that the
>data is there.
>
>All using the i2c-tools commands:
>
>$ i2ctransfer -y 1 w6@0x50 0x00 0x00 0x00 0x00 0x00 0x00
>$ i2ctransfer -y 1 w2@0x50 0x00 0x00 r8@0x50
>0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff
>
>$ i2ctransfer -y 1 w6@0x50 0x00 0x00 0x70 0x30 0x55 0x40
>$ i2ctransfer -y 1 w2@0x50 0x00 0x00 r8@0x50
>0x70 0x30 0x55 0x40 0xff 0xff 0xff 0xff
>
>The part number is: CAT24C32 by ON Semiconductor (www.onsemi.com)
>It is a 128 kbit (16 kbyte) part organized as 64 pages of 256 bytes.

Sorry copied from the wrong datasheet here, should be CAT24C128


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-03 Thread Bo Berglund via fpc-pascal
>On Mon, Apr 3, 2023 at 10:53?AM Bo Berglund via fpc-pascal <
>fpc-pascal@lists.freepascal.org> wrote:
>
>> On Mon, 3 Apr 2023 08:42:12 -0400, "Jeffrey A. Wormsley via fpc-pascal"
>>  wrote:
>>
>> >>
>> >> i2c_read_reg works too inasmuch as it does not error out, but it
>> returns FF
>> >> whatever addres I read like the i2c-tools command does.
>> >> I am not sure that it is correct though...
>> >>
>> >
>> >Yes this is expected, as eeproms erase to $FF.  You can write to the same
>> >byte as many times as you want, as long as you only change 1 bits to 0
>> >bits.  If you must change a 0 bit to a 1 bit, you have to erase back to
>> $FF
>> >first.  Be aware that erase means erasing the entire page, and not just a
>> >single byte.  This is where things like "wear leveling" come into play,
>> >because a page can only be erased a limited number of times (it used to be
>> >around 10,000, but maybe newer devices have extended this).  How you
>> manage
>> >writes to eeprom can be tricky, best to use them for things that don't
>> >change very often, such as configuration data.
>> >
>> >Jeff
>> >
>>
>> This is incorrect!
>> The EEPROM I am talking about is a small 8-pin chip specifically used in
>> IoT
>> devices to save non-volatile data and these devices are r/w on single
>> bytes.
>>
>> I have just tested it by executing command line commands to write a set of
>> data
>> to a specific address and then read it back and verified that it was there.
>> Then I repeated the process for the same addresses but different data.
>> Readback again showed only the new data correctly.
>>
>> What you are talking about might be certain microcontrollers which
>> simulate an
>> EEPROM memory in their flash program memory data. That flash is commonly
>> erasable only for full pages. Not the case here...
>>
>> I am working on using the FreePascal GitHub code and expanding it into a
>> class I
>> can use in my RPi4 project. Since I want to generalize it as much as
>> possible it
>> takes a few more hours than I thought...
>>
On Mon, 3 Apr 2023 14:26:17 -0400, "Jeffrey A. Wormsley via fpc-pascal"
 wrote:

>I've been using i2c and SPI eeproms for almost two decades.  All of them
>can read/write a single byte if that's what you want to do, but the
>write/erase restrictions I noted are there for any parts I've ever used.
>If you write a byte to $00, you cannot write it to $01 without first
>erasing the entire block that it is located in (usually 128 to 256 bytes).
>You can write $FF to $F0, then $F0 to $80, then $80 to $00, as these all
>only involve turning 1 bits into 0 bits, but if you try to write from a $00
>to a $01, then it will not work, at least not on any part I've ever used,
>as that involves turning a 0 bit into a 1 bit.   All of the parts I've
>seen, if you want to modify a single memory location (if the write involves
>turning a 0 bit into a 1 bit), they require you to read the block of data
>into your CPU, modify it there, erase the block, then write the entire
>block data back into the chip.  I've seen some parts that have an on-chip
>RAM buffer that would let you read the block into this RAM buffer with one
>command, modify the RAM buffer with a single byte write, erase the block,
>then write the RAM buffer back to the chip, which is a lot faster than
>having to do this yourself with your CPU memory, but it still required the
>block erase and that block erase still counted towards your maximum number
>of erase cycles.  I have not seen a chip that allowed completely random
>writes at the byte level before short of a static ram with battery backup.
>
>If you have an i2c part that doesn't work like this, then I would be very
>interested in knowing the part number and seeing a link to the data sheet.
>Such a part would make using these sorts of devices much easier, but to
>date I have never seen one.
>
>Jeff
>
I just tested by writing four 0x00 bytes in a row, then verifying that the
memory read shows these, then writing other data and again verifying that the
data is there.

All using the i2c-tools commands:

$ i2ctransfer -y 1 w6@0x50 0x00 0x00 0x00 0x00 0x00 0x00
$ i2ctransfer -y 1 w2@0x50 0x00 0x00 r8@0x50
0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff

$ i2ctransfer -y 1 w6@0x50 0x00 0x00 0x70 0x30 0x55 0x40
$ i2ctransfer -y 1 w2@0x50 0x00 0x00 r8@0x50
0x70 0x30 0x55 0x40 0xff 0xff 0xff 0xff

The part number is: CAT24C32 by ON Semiconductor (www.onsemi.com)
It is a 128 kbit (16 kbyte) part organized as 64 pages of 256 bytes.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-03 Thread Bo Berglund via fpc-pascal
On Mon, 3 Apr 2023 08:42:12 -0400, "Jeffrey A. Wormsley via fpc-pascal"
 wrote:

>>
>> i2c_read_reg works too inasmuch as it does not error out, but it returns FF
>> whatever addres I read like the i2c-tools command does.
>> I am not sure that it is correct though...
>>
>
>Yes this is expected, as eeproms erase to $FF.  You can write to the same
>byte as many times as you want, as long as you only change 1 bits to 0
>bits.  If you must change a 0 bit to a 1 bit, you have to erase back to $FF
>first.  Be aware that erase means erasing the entire page, and not just a
>single byte.  This is where things like "wear leveling" come into play,
>because a page can only be erased a limited number of times (it used to be
>around 10,000, but maybe newer devices have extended this).  How you manage
>writes to eeprom can be tricky, best to use them for things that don't
>change very often, such as configuration data.
>
>Jeff
>

This is incorrect!
The EEPROM I am talking about is a small 8-pin chip specifically used in IoT
devices to save non-volatile data and these devices are r/w on single bytes.

I have just tested it by executing command line commands to write a set of data
to a specific address and then read it back and verified that it was there.
Then I repeated the process for the same addresses but different data.
Readback again showed only the new data correctly.

What you are talking about might be certain microcontrollers which simulate an
EEPROM memory in their flash program memory data. That flash is commonly
erasable only for full pages. Not the case here...

I am working on using the FreePascal GitHub code and expanding it into a class I
can use in my RPi4 project. Since I want to generalize it as much as possible it
takes a few more hours than I thought...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-02 Thread Bo Berglund via fpc-pascal
On Sun, 2 Apr 2023 23:14:25 +0200, Christo Crause via fpc-pascal
 wrote:

>On Sun, Apr 2, 2023 at 9:30?PM Bo Berglund via fpc-pascal <
>fpc-pascal@lists.freepascal.org> wrote:
>
>> Is there a reason that there is no i2c_write_reg demo in the github
>> package?
>>
>
>I haven't gotten round to that, waiting for hardware to test the code with.
>
>I will try to write one so I can test that as well...
>>
>Would be nice if you could share that :-)

Sure, I will probably continue with this tomorrow (I'm in Europe so it is soon
midnight here...).

If I get it going I will post it or else I will ask about it here.

My hardware is ready and operational, in fact my board also has another EEPROM
(same type) sitting on the i2c-0 bus prepared for being used as a HAT EEPROM.
Haven't gotten that far on the HAT handling though so it is totally unused.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-02 Thread Bo Berglund via fpc-pascal
On Sun, 02 Apr 2023 15:07:48 -0400, Dennis Lee Bieber via fpc-pascal
 wrote:

>On Sun, 02 Apr 2023 16:16:46 +0200, Bo Berglund via fpc-pascal
> declaimed
>the following:
>
>
>>
>>
>>Byte Write
>
>>a  location  within  a  64  byte  page.  A  byte  following  the
>>address bytes will be interpreted as data. The data will be
>>loaded into the Page Write Buffer and will eventually be
>>written to memory at the address specified by the 14 active
>
>>The Master then starts the internal Write cycle by issuing a
>>STOP condition (Figure 6). During the internal Write cycle
>>(tWR), the SDA output will be tri-stated and additional Read
>>or Write requests will be ignored (Figure 7).
>>--
>>
>   This sounds suspiciously like one is expected (or is able) to write
>multiple bytes /within/ the "page" via multiple address/data operations,
>and have all those bytes "burned" into the memory using a single "stop"
>operation.
>

Exactly, you specify *start* as a 2-byte address (pageno/offset) and then you
output as many sequential bytes as you need to write in the command.

All will wind up in the 256 byte on-chip write buffer until the stop arrives and
then it will be dumped into memory. If the buffer address increments past 0xff
it will wrap back into 0x0 in the buffer for following bytes and this is
probably something you must not allow...

So an application using i2c must check the arguments for this page transition
case and either error out or spawn a second operation for the following page in
EEPROM to handle the excess bytes.

I have not yet tested this case because the github project does not have an
i2c_write demo...
Must write one myself.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-02 Thread Bo Berglund via fpc-pascal
On Sun, 2 Apr 2023 07:31:43 +0200, Christo Crause via fpc-pascal
 wrote:

>On Sat, Apr 1, 2023 at 9:57?PM Bo Berglund via fpc-pascal <
>fpc-pascal@lists.freepascal.org> wrote:
>
>> Question:
>> Can I use Linux file system commands to read/write the data on the i2c
>> EEPROM
>> memory device and if so how from fpc?
>>
>
>To some extent it is possible to handle i2c transactions as file read/write
>operations, but some ioctl calls are required to configure e.g. the device
>address [1]. Take note that only a subset of i2c functionality is available
>using read/write calls. Lazi2cdev [2] uses this approach.
>
>For finer control over the i2c transactions (for example combined
>write/read transactions) low level ioctl calls are available in Linux.  I
>wrote an i2c class [3] using this approach.
>
>1. https://www.kernel.org/doc/html/latest/i2c/dev-interface.html
>2. https://github.com/laz2wiringpi/lazI2cdev/blob/master/i2cdev_base.pas
>3. https://github.com/ccrause/rpiplc_pas/blob/main/native/i2c.pas

Hello again!

I have now tested the two demos in github [3] and they seem to work OK.

The i2cscan works and shows exactly the same as sudo i2cdetect -y 1 does from
the i2c-tools package I installed via apt.

i2c_read_reg works too inasmuch as it does not error out, but it returns FF
whatever addres I read like the i2c-tools command does.
I am not sure that it is correct though, for that I need to create an i2c_write
demo app first so I can write values at different locations and read them back.
The EEPROM has until now not been used so it is in its factory state with no
data.

Is there a reason that there is no i2c_write_reg demo in the github package?

I will try to write one so I can test that as well...
 

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-02 Thread Bo Berglund via fpc-pascal
On Sun, 02 Apr 2023 10:23:24 +0200, Bo Berglund via fpc-pascal
 wrote:

>On Sun, 2 Apr 2023 07:31:43 +0200, Christo Crause via fpc-pascal
> wrote:
>
>>On Sat, Apr 1, 2023 at 9:57?PM Bo Berglund via fpc-pascal <
>>fpc-pascal@lists.freepascal.org> wrote:
>>
>>> Question:
>>> Can I use Linux file system commands to read/write the data on the i2c
>>> EEPROM
>>> memory device and if so how from fpc?
>>>
>>
>>To some extent it is possible to handle i2c transactions as file read/write
>>operations, but some ioctl calls are required to configure e.g. the device
>>address [1]. Take note that only a subset of i2c functionality is available
>>using read/write calls. Lazi2cdev [2] uses this approach.
>>
>>For finer control over the i2c transactions (for example combined
>>write/read transactions) low level ioctl calls are available in Linux.  I
>>wrote an i2c class [3] using this approach.
>>
>>1. https://www.kernel.org/doc/html/latest/i2c/dev-interface.html
>>2. https://github.com/ccrause/rpiplc_pas/blob/main/native/i2c.pas
>
>Thanks for the reply and links!
>Then I need to go the low-level way, I guess...
>
>I had hoped it would be a simpler way using OS available functions on RPi.
>
>I have used these EEPROM devices on some Microchip PIC24 projects where I had 
>to
>do the nitty-gritty low level stuff myself including bit-banging the I2C bus...
>
>With that approach I have to *read the details* on the EEPROM datasheets to see
>how they are handled, unless of course I can port my own i2c code (Ansi-C) to
>pascal...
>
>Luckily on RPi the system is built to allow users to do low-level stuff on the
>I/O lines.

After consulting my old code and the datasheet for CAT24C128 and looking at the
links you posted I have come to the following conclusion:

1) My old code for PIC24 is too close to the silicon and I don't see how I can
use that on a Linux machine...

2) Your linked FPC unit i2c.pas looks promising to mee, I will test it.

Notes:
--
The EEPROM on the board is a 128 kbit (16 kbytes) version organized as 64 256
byte pages. The datsheet says this about a write cycle:


Byte Write
Upon receiving a Slave address with the R/W bit set to ‘0’,
the CAT24C128 will interpret the next two bytes as address
bytes. These bytes are used to initialize the internal address
counter; the 2 most significant bits are ‘don’t care’, the next
8 point to one of 256 available pages and the last 6 point to
a  location  within  a  64  byte  page.  A  byte  following  the
address bytes will be interpreted as data. The data will be
loaded into the Page Write Buffer and will eventually be
written to memory at the address specified by the 14 active
address  bits  provided  earlier.  The  CAT24C128  will
acknowledge the Slave address, address bytes and data byte.
The Master then starts the internal Write cycle by issuing a
STOP condition (Figure 6). During the internal Write cycle
(tWR), the SDA output will be tri-stated and additional Read
or Write requests will be ignored (Figure 7).
--

So here the sequence on the bus will contain a 2-byte address rather than a
single byte address.
This needs to be taken into consideration and I believe it *is* in the i2c.pas
unit where there are overloaded functions for byte and uint16 type addresses for
read and write, one only needs to use the correct width of the address argument
and it will be correctly chosen! :-)

3) Regarding the other unit you linked to (i2cdev_base.pas):
I see it is not really relevant to me due to the type of EEPROM I have etc, so I
will go with the i2c.pas.


I have just gotten to this reply so have not yet had time to fire up my RPi4
Lazarus on the system that has the board installed in order to test it..

I will do so shortly and report back what I found.
The plan is to store the application settings on the EEPROM along with a hashed
authentication code to unlock the application itself.

AGAIN:
I AM GRATEFUL FOR THE LINK TO THIS FPC UNIT
Hopefully it will solve my problems in using the EEPROM on the board.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-02 Thread Bo Berglund via fpc-pascal
On Sun, 2 Apr 2023 07:31:43 +0200, Christo Crause via fpc-pascal
 wrote:

>On Sat, Apr 1, 2023 at 9:57?PM Bo Berglund via fpc-pascal <
>fpc-pascal@lists.freepascal.org> wrote:
>
>> Question:
>> Can I use Linux file system commands to read/write the data on the i2c
>> EEPROM
>> memory device and if so how from fpc?
>>
>
>To some extent it is possible to handle i2c transactions as file read/write
>operations, but some ioctl calls are required to configure e.g. the device
>address [1]. Take note that only a subset of i2c functionality is available
>using read/write calls. Lazi2cdev [2] uses this approach.
>
>For finer control over the i2c transactions (for example combined
>write/read transactions) low level ioctl calls are available in Linux.  I
>wrote an i2c class [3] using this approach.
>
>1. https://www.kernel.org/doc/html/latest/i2c/dev-interface.html
>2. https://github.com/laz2wiringpi/lazI2cdev/blob/master/i2cdev_base.pas
>2. https://github.com/ccrause/rpiplc_pas/blob/main/native/i2c.pas

Thanks for the reply and links!
Then I need to go the low-level way, I guess...

I had hoped it would be a simpler way using OS available functions on RPi.

I have used these EEPROM devices on some Microchip PIC24 projects where I had to
do the nitty-gritty low level stuff myself including bit-banging the I2C bus...

With that approach I have to *read the details* on the EEPROM datasheets to see
how they are handled, unless of course I can port my own i2c code (Ansi-C) to
pascal...

Luckily on RPi the system is built to allow users to do low-level stuff on the
I/O lines.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-02 Thread Bo Berglund via fpc-pascal
On Sat, 1 Apr 2023 20:30:02 -0400, Travis Siegel via fpc-pascal
 wrote:

>Generally, raspberry pi devices connected to other devices will (by 
>default) use python for their programming.  The python libs have all the 
>setup and tear down code built in.  You can use C as well, so I see no 
>reason why FPC couldn't be used.  It's probably going to take some work 
>though.  You'll need to either find the appropriate python files, and 
>port them to FPC, or convert the C headers into something pascal can 
>understand.

I have never used Oython, looked at it a while back and was taken aback by the
idea that whitespace in source code has meaning

>I've never made the attempt to do this, though now that you 
>bring this up, I might just take a crack at it.  Up until now, I've used 
>C (since I'm not a fan of python) when talking to raspberry connected 
>devices, but I'm pretty sure I've seen posts where folks were using 
>other languages such as PHP or Java to talk to the pi devices, so those 
>header files have most certainly been ported to other languages. It's 
>possible someone already did the pascal port, though I can't point to 
>one.

I wonder if Chat-GPT can help here?
Never tried it myself but my daughter tells me it can do things google cannot.

>I've not been messing with my raspberry pis for the last year or 
>so because of moving, and things are just now getting back to normal (I 
>hate moving), and I need a new pi anyhow, so perhaps I will get back to 
>it this year, but the reason I say this, is because I've not kept up 
>with the pi forums, so I don't know what's happening around the pi 
>ecosystems lately, which is why I can't answer the question directly, 
>though it's certainly more than possible.

If you have missed it the RaspberryPi Foundation is one of these that have been
hardest hit by the Covid pandemic's disruption of supply lines and semiconductor
shortage! They use state-of-the-art level of silicon for their newer models and
these are the hardest hit by the manufacturing problems in Taiwan.
Expected resume of deliveries second half of 2023...
Meanwhile only small quantities of RPi4 devices can be made and are on
allocation.

Right now there is *no* availability of RPi4 devices for the general public at
all!

Older models may appear in very small batches now and then..

Sometimes you may find a couple of RPiZero W devices for purchase, but then they
are limited to a single item per customer (while stock lasts, which usually is a
day or two).

Here is a RPiForum thread about this dilemma (last page of 16) :
https://forums.raspberrypi.com/viewtopic.php?p=2095696#p2095696

And here is the PiLocator, which tries to keep track of where there are actual
devices to buy:
https://rpilocator.com/

Except it seems like it is off-line right now, it worked a week ago when I could
find and buy a PiZero.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-01 Thread Bo Berglund via fpc-pascal
I need to read and write data to an EEPROM connected by I2C on a RaspberryPi4.
The I2C channel is found in /dev as i2c-1:

$ ll /dev/i2*
crw-rw 1 root i2c 89, 1 2019-02-14 11:12 /dev/i2c-1

In this channel the EEPROM CAT24C128 is at address 0x50
The data on the device is organized as 256 pages of  64 bytes data each AFAIU.

I can check the EEPROM using i2c-tools, which I have installed, but I am unsure
if the read is correct...

Question:
Can I use Linux file system commands to read/write the data on the i2c EEPROM
memory device and if so how from fpc?

I have installed the current versions of Lazarus and Fpc on the RPi4 itself.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-30 Thread Bo Berglund via fpc-pascal
On Thu, 30 Mar 2023 10:02:49 +0200, Tomas Hajny via fpc-pascal
 wrote:

>On 30 March 2023 9:36:35 +0200, Marco van de Voort via fpc-pascal 
> wrote:
>>On 30-3-2023 07:38, Bo Berglund via fpc-pascal wrote:
>>> The problem seems to be that neither is a valid COFF file according to my 
>>> Fpc
>>> (or Lazarus) in any case. Both generate the COFF error when reaching the 
>>> linker
>>> step.
>>
>>32-bit objs for delphi are typically OMF, 64-bit are typically coff (for 
>>AMD64).
>
>I'd suggest trying to switch to external linking (for both versions) - that 
>might help...
>

Could you be more specific?

I have never heard of such, I am just a long time user of Lazarus/Fpc but not in
the deep understanding of how it all works. I have always focused on my
applications and not how they were screwed together behind the scenes by Fpc...

Is there a setting to use something other than Fpc to link after compiling?
How is that done?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-29 Thread Bo Berglund via fpc-pascal
On Wed, 29 Mar 2023 19:27:12 -0400, Dennis Lee Bieber via fpc-pascal
 wrote:

>   I'd expect trying to link a 32-bit object file into a 64-bit
>application to result in all sorts of possible errors.

That is not the case here, they have supplied two obj files, one is 32 and the
other 64 bit.
The problem seems to be that neither is a valid COFF file according to my Fpc
(or Lazarus) in any case. Both generate the COFF error when reaching the linker
step.

And in the case of the 32 bit version of the obj file I have set my Lazarus to
target a 32 bit Win application for the i386 processor (I have installed the 32
bit cross compiler found at SourceForge for this).
https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Lazarus%202.2.6/


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-29 Thread Bo Berglund via fpc-pascal
On Wed, 22 Mar 2023 14:17:23 +0100, Sven Barth via fpc-pascal
 wrote:

>Then you should ask them for a suitable 64-bit object file (I assume that
>they'll provide the one for C which they probably also did for you back
>then and then you might need to adjust the import unit a bit to be usable
>with x86_64-win64; as long as they also provide a C header that should be
>doable).
>

Back here again after I raised a ticket with Thales and got a response!
I think they provide something that will work with Delphi rather than for C.

The reply from THALES is linking to no less than 7 different archive files for
various use of the keys.

In one of these I found an example for *Delphi 10*, which contained an updated
interface file and a 32 bit object file:
spromeps.pas
superpro.obj

(I do not think I even ever had Delphi 10...)

I copied these to my project and disabled the old versions.

Then I tried to cross-compile to Win32 on Lazarus 2.2.4 and Fpc 3.2.2.

Syntax check (Run/Quick_Compile) finishes successfully.

But the Compile does not, it fails like this:

-
Compile Project, Mode: Default, OS: win32, CPU: i386, Target: DongleTest.exe:
Exit code 1, Errors: 1
DongleTest.lpr(28,1) Error: Illegal COFF Magic while reading
D:\Engineering\Projects\Subversion\PC\DongleTest\superpro.obj
-

The same happens if I set the target to default everywhere so going for 64 bit.
In tyhis case I had to switch to the spromeps.pas superpro.obj files from the
same archive but for 64 bit applications.
Here the error when I try to compile:

--
Compile Project, Mode: Default, Target: DongleTest.exe: Exit code 1, Errors: 1
DongleTest.lpr(28,1) Error: Failed reading coff file, illegal reloctype $000A
while reading D:\Engineering\Projects\Subversion\PC\AgiDongleTest\superpro.obj
--

So again I have the problem with the obj file(s) which are now more recent than
the old single one.

How can I check the obj file for "type"?

I have asked this before here but now cannot find if I got an answer or not...

Is there some command I can use to check what kind of an obj file I have?

Is it possible to find anything by looking at the interface file spromeps.pas,
which is the interface from the main application towards the obj file?

ThHis pretty much looks like the old file to me except it has more available API
calls and also some defines for MSWINDOWS and LINUX respectively in the
implementation part defining all the API calls into the driver.

My problem is that I do not have any Delphi on my new (from 2019) laptop except
Delphi-7...

So I guess I have to check if my test app can be opened in Delphi7 using the
supplied obj file and if it works there, how do I proceed?

TIA


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Fpc 3.2.2 fails to "make install" on RPi4 to local directory

2023-03-28 Thread Bo Berglund via fpc-pascal
On Tue, 28 Mar 2023 13:47:30 +0200, Marco van de Voort via fpc-pascal
 wrote:

>
>On 28-3-2023 13:43, Bo Berglund via fpc-pascal wrote:
>> make install prefix="$HOME" FPC="$HOME/dev/fpc/3.2.2/compiler/ppcarm"
>
>It is install_prefix= not install prefix=  iow, insert a underscore
>

No, the problem was *case sensitivity*!
the command should be:

make install PREFIX="$HOME" FPC="$HOME/dev/fpc/3.2.2/compiler/ppcarm"

Stupid confusion of case sensitive OS with Windows where case does not come into
play...

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Fpc 3.2.2 fails to "make install" on RPi4 to local directory

2023-03-28 Thread Bo Berglund via fpc-pascal
I have a RaspberryPi4 where I have installed several versions of Lazarus/Fpc
over some time.
The latest versions are (fpc from Tools/Options/Compiler_executable):

Laz 2.0.8  with Fpc 3.0.4 set to use fpc: fpc
Laz 2.0.10 with Fpc 3.2.0 set to use fpc: /home/pi/lib/fpc/3.2.0/ppcarm
Laz 2.0.12 with Fpc 3.2.0 set to use fpc: /home/pi/lib/fpc/3.2.0/ppcarm

Now I wanted to add a new Lazarus version and update my FPC to 3.2.2 as well.

So I have done what I always do, gotten the fpc sources from GitLab into a new
dir ~/dev/fpc/3.2.2, then executed inside that dir using fpc 3.2.0 as seed:

make clean FPC="/home/pi/dev/fpc/3.2.0/compiler/ppcarm"
make all   FPC="/home/pi/dev/fpc/3.2.0/compiler/ppcarm"

And then after that succeeded:

make install prefix="$HOME" FPC="$HOME/dev/fpc/3.2.2/compiler/ppcarm"
which throws an error! So I tried without $HOME:

make install prefix="/home/pi" FPC="/home/pi/dev/fpc/3.2.2/compiler/ppcarm"
which also throws the error, it displays this sequence:

make installbase FPC=/home/pi/dev/fpc/3.2.2/compiler/ppcarm
ZIPDESTDIR=/home/pi/dev/fpc/3.2.2
FPCMAKE=/home/pi/dev/fpc/3.2.2/utils/fpcm/bin/arm-linux/fpcmake
make[1]: Entering directory '/home/pi/dev/fpc/3.2.2'
/usr/bin/install -m 755 -d /usr/local/lib/fpc/3.2.2
/usr/bin/install: cannot create directory ‘/usr/local/lib/fpc’: Permission
denied
make[1]: *** [Makefile:2858: installbase] Error 1
make[1]: Leaving directory '/home/pi/dev/fpc/3.2.2'
make: *** [Makefile:2875: installall] Error 2

This has *never* happened before to me and I do not understand why it brings up
/usr/bin/ and /usr/local/lib/, the whole point of my use of the argument
prefix="/home/pi"
is to install *locally* below the home dir and not to a global location where
you nhave to be sudo to do anything...

Note:
my $HOME/.fpc.cfg from 2019 contains exclusively paths looking like this:

#ifndef VER2
-FM/home/pi/lib/fpc/../../share/fpc/$fpcversion/unicode/
#endif
# searchpath for units and other system dependent things
-Fu/home/pi/lib/fpc/$fpcversion/units/$fpctarget
-Fu/home/pi/lib/fpc/$fpcversion/units/$fpctarget/*
-Fu/home/pi/lib/fpc/$fpcversion/units/$fpctarget/rtl


Is this a new behaviour for Fpc 3.2.2 different from that of Fpc 3.2.0 where it
did not happen???

If not, what could have happened and in both cases how do I fix it?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Cross-compile for Linux Arm (RaspberryPi) on Windows 10?

2023-03-25 Thread Bo Berglund via fpc-pascal
On Sat, 25 Mar 2023 23:25:07 +0100, Bo Berglund via fpc-pascal
 wrote:

>I have latest Lazarus/Fpc on my Windows 10 main computer, but also on a number
>of RaspberryPi (3 and 4) devices. If I create an application on Windows and 
>want
>to build the same for RPi, then I have to transfer the sources (via Subversion)
>to the RPi and build there.
>
>And doing so requires me to use VNC to connect to the RPi, which is less than
>optimal.
>
>Now I wonder how to set up FPC on Windows to cross-compile for Raspberry Pi
>(arm6/arm7 processor and Debian based Linux)?
>
>The freepascal Wiki articles I have found are either outdated or do not 
>describe
>enough in detail how one can do this...
>
>So is there some up-to-date article describing it?

I have found this: https://wiki.freepascal.org/Cross_compiling

and it actually mentions RaspberryPi in passing, so I guess that is encouraging.

Since I have RPi units with Lazarus/FPC installed there is also a directory:

$HOME/lib/fpc/3.2.2/units which contains subdir arm-linux

If I tar this arm-linux dir I get a file arm-linux.tgz which is about 52 MB in
size.

Do I extract this into my Windows FPC 3.2.2 installation somewhere in order to
be able to cross-compile?

Below the Lazarus installation dir /dev/lazarus/2.2.4 I also have this dir:

/dev/lazarus/2.2.4/units/arm-linux and this is 233 KB in size.
Do I tar and copy this too into my Windows Lazarus/FPC installation?

It contains only 2 subdirs:
/dev/lazarus/2.2.4/units/arm-linux/gtk2
/dev/lazarus/2.2.4/units/arm-linux/nogui

If so, where do I deposit these files on Windows?
I have used the SourceForge installer to get the Lazarus 2.2.4 installed.

Do I drop them off into a new ...\fpc\3.2.2\units\arm-linux directory even
though they came from two different places on the live system?

Grateful for some advice, I have never done this ever before...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Cross-compile for Linux Arm (RaspberryPi) on Windows 10?

2023-03-25 Thread Bo Berglund via fpc-pascal
I have latest Lazarus/Fpc on my Windows 10 main computer, but also on a number
of RaspberryPi (3 and 4) devices. If I create an application on Windows and want
to build the same for RPi, then I have to transfer the sources (via Subversion)
to the RPi and build there.

And doing so requires me to use VNC to connect to the RPi, which is less than
optimal.

Now I wonder how to set up FPC on Windows to cross-compile for Raspberry Pi
(arm6/arm7 processor and Debian based Linux)?

The freepascal Wiki articles I have found are either outdated or do not describe
enough in detail how one can do this...

So is there some up-to-date article describing it?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is Online Package Manager not a standard part of Lazarus?

2023-03-24 Thread Bo Berglund via fpc-pascal
On Fri, 24 Mar 2023 22:20:15 +0100, Bo Berglund via fpc-pascal
 wrote:

>I thought Online Package Manager was standard since it appeared in all earlier
>installs I have made both using Sourceforge Windows installers or via sources
>downloaded with SVN or Git and building on Linux.
>
>Now I have tested fpcupdeluxe on Windows and it looked at first to work OK, but
>when I wanted to complete the install using OLPM to get a few packages I am
>always installing including Indy, that was missing in the Package menu!
>
>Is it intentionally removed by the fpcupdeluxe developers?
>
>Or do I just not know how to handle the fpcupdeluxe installer?

OK, after navigating around fpcupdeluxe I found a button on tab "Modules" which
installed OLPM when clicked.
So now I have it in the menu.
Wonder why it was not part of the original install?

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Is Online Package Manager not a standard part of Lazarus?

2023-03-24 Thread Bo Berglund via fpc-pascal
I thought Online Package Manager was standard since it appeared in all earlier
installs I have made both using Sourceforge Windows installers or via sources
downloaded with SVN or Git and building on Linux.

Now I have tested fpcupdeluxe on Windows and it looked at first to work OK, but
when I wanted to complete the install using OLPM to get a few packages I am
always installing including Indy, that was missing in the Package menu!

Is it intentionally removed by the fpcupdeluxe developers?

Or do I just not know how to handle the fpcupdeluxe installer?

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Downloaded cross-compiler from Sourceforge - wiki incorrect?

2023-03-24 Thread Bo Berglund via fpc-pascal
On Fri, 24 Mar 2023 07:38:30 +0100, Bo Berglund via fpc-pascal
 wrote:

>On Thu, 23 Mar 2023 09:47:36 +0100, Martin Frb via fpc-pascal
> wrote:
>
>>On 23/03/2023 09:25, Bo Berglund via fpc-pascal wrote:
>>>
>>> Then opened Lazarus 2.2.4 with my project and changed project options as
>>> follows:
>>>
>>> Compiler_Options/Config_and_Target/Target OS(-T): Win32
>>>
>>> Everything else left as-is.
>>You need to change the CPU to i386 too
>>
>OK, I thought that the current processor could be used since it can run both
>types of programs...

A follow-up question:

Is it possible to configure Lazarus itself to have multiple build modes (Default
and win32) such that one does not have to redefine them every time a new project
is created?

Right now I have operated on the Project/Options/Compiler_options to set the
target as Default or win32. I could create a new build option for win32 along
side with the Default where the target system, target cpu and target dir were
changed from default to specific.

But these modes are AFAICT specific to this project and so have to be re-created
for every new project where the crosscompiler will be used in order to easily
switch between them.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Downloaded cross-compiler from Sourceforge - wiki incorrect?

2023-03-24 Thread Bo Berglund via fpc-pascal
On Thu, 23 Mar 2023 09:47:36 +0100, Martin Frb via fpc-pascal
 wrote:

>On 23/03/2023 09:25, Bo Berglund via fpc-pascal wrote:
>>
>> Then opened Lazarus 2.2.4 with my project and changed project options as
>> follows:
>>
>> Compiler_Options/Config_and_Target/Target OS(-T): Win32
>>
>> Everything else left as-is.
>You need to change the CPU to i386 too
>
OK, I thought that the current processor could be used since it can run both
types of programs...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-23 Thread Bo Berglund via fpc-pascal
On Wed, 22 Mar 2023 13:56:59 +0100, Bo Berglund via fpc-pascal
 wrote:

>On Wed, 22 Mar 2023 12:33:16 +0100, Giuliano Colla via fpc-pascal
> wrote:
>
>>Il 22/03/2023 11:18, Bo Berglund via fpc-pascal ha scritto:
>>
>>> If I have fpc 3.2.2 inbstalled on Windows 10 x64 I assume it is a 64 bit 
>>> target
>>> exe which will be the output, right?
>>If in Project Options -> Config and Target ->Target OS you specify 
>>Win32, you'll get a 32 bit exe (which is what Delphi does, I presume, if 
>>it links a 32 bit object).
>
>I changed target to Win32 then when I closed the dialog an error message popped
>up:
>
>The current FPC has no config file. It will probably miss
>some units. Check your installation of fpc.
>[OK]  [Ignore]
>
>My installation was done using a full Lazarus/FPC installer from SourceForge:
>lazarus-2.2.4-fpc-3.2.2-win64.exe
>
>So both Lazarus and Fpc come from the same installer and it installs an 
>isolated
>environment so one can have several versions installed at the same time.
>
>What to do now?
>And what is the problem?

I looked at the FPC Wiki on cross-compilation and tried to install the cross for
win32 into my Lazarus 2.2.4.
https://wiki.freepascal.org/Cross_compiling#From_win64_to_win32

But it seems like the wiki instructions are missing something because it does
not even find what is needed to switch to target win32...
See separate thread about cross-compile.

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Downloaded cross-compiler from Sourceforge - wiki incorrect?

2023-03-23 Thread Bo Berglund via fpc-pascal
I tried to add a cross-compiler for Win32 to my existing Lazarus 2.2.4
installation on Windows 10 x64.

So I followed the instructions on the fpc wiki:
https://wiki.freepascal.org/Cross_compiling#From_win64_to_win32

The link to SF from the Wiki got me to SF and I could download the cross exe I
needed.

But when I try to run it, Windows pops up a "Windows protected your PC" message:

"Microsoft Defender SmartScreen prevented an unrecognised app from starting.
Running this app might put your PC at risk."

There is a button "Don't run" and a link to more info that displays:

"Application: 
lazarus-2.2.4-fpc-3.2.2-cross-i386-win32-win64.exe 
Publisher:  
Unknown publisher"

Now another button "Run anyway" is shown, so I did that and the install seemed
to work...

As described in the Wiki I selected to install into the same folder as I had
installed Lazarus 2.2.4 initially.

Then opened Lazarus 2.2.4 with my project and changed project options as
follows:

Compiler_Options/Config_and_Target/Target OS(-T): Win32

Everything else left as-is.


Now when I OK this, Lazarus pops up a message saying:
--
The current FPC has no config file. It will probably miss
some units. Check your installation of fpc.
--

When I hit the OK button another pop-up:
--
The project uses target OS=win32 and CPU=x86_64.
The system.ppu for this target was not found in the FPC
binary directories.
Make sure fpc is installed correctly for this target and the
fpc.cfg contains the right directories.
[OK]
---

So I followed the install instructions on the Wiki and wound up in this
non-working state...

What steps are missing that I must do?
Why does it not find the correct system.ppu?

I searched the install dir for system.ppu and found two here:

C:\Programs\Lazarus_2.2.4\fpc\3.2.2\units\i386-win32\rtl
C:\Programs\Lazarus_2.2.4\fpc\3.2.2\units\x86_64-win64\rtl


What I see is:
in C:\Programs\Lazarus_2.2.4\fpc\3.2.2\bin\ only x86_64-win64 exists

in C:\Programs\Lazarus_2.2.4\fpc\3.2.2\units these dirs exsist:
i386-win32
x86_64-win64

in C:\Programs\Lazarus_2.2.4\fpc\3.2.2\fpmkinst these dirs exsist:
i386-win32
x86_64-win64

It seems like the cross installer failed to install the cross binaries, why

I must have done something seriously wrong...

Or could the problem be that Windows Defender has blocked all exe files from
being installed?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-22 Thread Bo Berglund via fpc-pascal
On Wed, 22 Mar 2023 12:33:16 +0100, Giuliano Colla via fpc-pascal
 wrote:

>Il 22/03/2023 11:18, Bo Berglund via fpc-pascal ha scritto:
>
>> If I have fpc 3.2.2 inbstalled on Windows 10 x64 I assume it is a 64 bit 
>> target
>> exe which will be the output, right?
>If in Project Options -> Config and Target ->Target OS you specify 
>Win32, you'll get a 32 bit exe (which is what Delphi does, I presume, if 
>it links a 32 bit object).

I changed target to Win32 then when I closed the dialog an error message popped
up:

-
The current FPC has no config file. It will probably miss
some units. Check your installation of fpc.
[OK]  [Ignore]
-

When I hit [OK] I got this pop-up:

---
The project uses target OS=win32 and CPU=x86_64.
The system.ppu for this target was not found in the FPC
binary directories.
Make sure fpc is installed correctly for this target and the
fpc.cfg contains the right directories.
   [OK]


My installation was done using a full Lazarus/FPC installer from SourceForge:
lazarus-2.2.4-fpc-3.2.2-win64.exe

So both Lazarus and Fpc come from the same installer and it installs an isolated
environment so one can have several versions installed at the same time.

What to do now?
And what is the problem?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-22 Thread Bo Berglund via fpc-pascal
On Wed, 22 Mar 2023 12:33:16 +0100, Giuliano Colla via fpc-pascal
 wrote:

>Il 22/03/2023 11:18, Bo Berglund via fpc-pascal ha scritto:
>
>> If I have fpc 3.2.2 inbstalled on Windows 10 x64 I assume it is a 64 bit 
>> target
>> exe which will be the output, right?
>If in Project Options -> Config and Target ->Target OS you specify 
>Win32, you'll get a 32 bit exe (which is what Delphi does, I presume, if 
>it links a 32 bit object).

I changed target to Win32 then when I closed the dialog an error message popped
up:

The current FPC has no config file. It will probably miss
some units. Check your installation of fpc.
[OK]  [Ignore]

My installation was done using a full Lazarus/FPC installer from SourceForge:
lazarus-2.2.4-fpc-3.2.2-win64.exe

So both Lazarus and Fpc come from the same installer and it installs an isolated
environment so one can have several versions installed at the same time.

What to do now?
And what is the problem?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-22 Thread Bo Berglund via fpc-pascal
On Wed, 22 Mar 2023 11:18:10 +0100, Bo Berglund via fpc-pascal
 wrote:

>
>I guess I have to just create a simple program which reads the key data and 
>does
>nothing else to check if the handling will actually work...
>Or convert a small tool we already have from Delphi7 to Lazarus/FPC and see 
>what
>happens..

Now I created a new program and set it to mode Delphi.
The syntac check Run/Quick_Compile works OK but then when I use the Run/Compile
function this is what I get:

Compile Project, Target: DongleTest.exe: Exit code 1, Errors: 1
DongleTest.lpr(24,1) Error: Illegal COFF Magic while reading
D:\Engineering\Projects\Subversion\PC\DongleTest\SPROMEPS.OBJ

Sigh...
I guess it is a problem regarding 32 vs 64 bit application code here...

Is there a settinmg in FPC which will make it produce a 32bit Windows exe?

Or do I have to install a complete set of 32 bit Lazarus/FPC on my 64 bit
Windows 10?
Or even worse: do I have to create a virtual Windows 10 32 bit computer to do
the build on? It might not work there too.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-22 Thread Bo Berglund via fpc-pascal
On Wed, 22 Mar 2023 08:01:57 +0100, Sven Barth via fpc-pascal
 wrote:

>Bo Berglund via fpc-pascal  schrieb am
>Di., 21. März 2023, 23:54:
>
>> 1) How should I go about translating the above to current FreePascal
>> syntax?
>>
>> This involves:
>> { Force FAR calls }
>> {$F+}
>>
>> {$L SPROMEPS.OBJ}  { LINK WITH THE SUPERPRO OBJECT FILE }
>>
>
>These won't be a problem. Both Delphi and FPC (for non-i8086) will skip the
>$F directive as it's not necessary on 32- or 64-bit systems.

OK, so I don't have to modify this part then.

>The object file won't be a problem for FPC on i386-win32 because it will be
>a COFF file which is the default.

When you say "on i386-win32" does that mean a 32 bit version of Windows as the
host system for building the programs?

If I have fpc 3.2.2 inbstalled on Windows 10 x64 I assume it is a 64 bit target
exe which will be the output, right?

If that is the case will the obj file work when building the exe?

Is it possible to check if the obj file is of the "COFF" type?
Note that the timestamp of the obj file is 2003-05-29...

>> 2) Is there a way to translate/convert the 32 bit Windows SPROMEPS.OBJ
>> file into
>> a 64 bit one such that it could be used for a 64 bit fpc compiler?
>> It is the interface to the protection key driver on the Windows system...
>>
>
>Aside from asking the company for a 64-bit variant or reverse engineering
>the object file, no. How large is that object file?

Size = 39330 bytes

>Maybe it's only a relatively simple interface to the driver..

The accompanying pas file I quoted from declares 12 different API calls into the
driver, which we have used to create our own interface functions for the key
handling. This was done about 20 or so years ago...

>
>> It does work for our 32 bit Delphi7 programs on Windows 10 x64, so there
>> must be some 32<->64 bit handling in Windows maybe?
>>
>
>Are you really sure there's a driver involved? When you install it is there
>a driver binary for both 32- and 64-bit? Cause 64-bit Windows *can not*
>load 32-bit drivers.

THALES has supplied a dedicated driver for Windows, which we use on all s/w
installations. It is a rather big (2945376 bytes) installer file named "Sentinel
System Driver Installer 7.6.0.exe"
So, yes I am sure it is needed, whithout it the s/w cannot read the protection
key.
The driver has changed over the years as Windows progressed and we now use
version 7.6.0


I guess I have to just create a simple program which reads the key data and does
nothing else to check if the handling will actually work...
Or convert a small tool we already have from Delphi7 to Lazarus/FPC and see what
happens..


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-22 Thread Bo Berglund via fpc-pascal
On Wed, 22 Mar 2023 00:19:58 +0100 (CET), Michael Van Canneyt via fpc-pascal
 wrote:

>Maybe the THALES company has a 64-bit version of the .OBJ file.

OK, I will try and get some answers from them.
Problem is that they seem to have concentrated on Microsoft dev tools so lat
time I looked there was not much for Delphi and none for FreePascal.

There really should be some generic interface to use independent of dev
environment nowadays when there are so many systems in use (C-sharp, C++, Python
etc etc).

I will have to open a support ticket.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Converting Delphi7 code to FreePascal with interfacing to protection key?

2023-03-21 Thread Bo Berglund via fpc-pascal
We have a number of old Delphi7 applications which are in need of porting over
to FreePascal. I have successfully done a number of these ports in the last few
years...
But now I am up against a bit of a problem regarding software we have protected
using an USB connected hardware key originally bought from Rainbow, a company
that has been bought up in several steps and is now named THALES.

Anyway, our software interfaces to the SuperPro protection keys is via a Windows
driver from THALES and they have provided a software integration kit way back
when we started using the keys.
It consist of a Delphi unit basically containing a list of definitions of
available API functions into the driver looking like this:

--
{ Force FAR calls }
{$F+}

INTERFACE

CONST
 { SuperPro API error codes }
 SP_SUCCESS = 0;
 
 SPRO_MAX_QUERY_SIZE= 56;

TYPE

RB_SPRO_APIPACKET  = ARRAY [1..1028] OF CHAR;  { Spro API Packet }
RB_SPRO_APIPACKET_PTR  = ^RB_SPRO_APIPACKET;

FUNCTION SproInitialize( ApiPacket : RB_SPRO_APIPACKET_PTR   ) : WORD;
FUNCTION SproGetExtendedStatus( ApiPacket : RB_SPRO_APIPACKET_PTR ) : WORD;


IMPLEMENTATION
USES
   Windows;

{$L SPROMEPS.OBJ}  { LINK WITH THE SUPERPRO OBJECT FILE }
{ External functions }

FUNCTION RNBOsproFormatPacket( ApiPacket : RB_SPRO_APIPACKET_PTR;
   thePacketSize : WORD ) : WORD; STDCALL; EXTERNAL;

FUNCTION RNBOsproInitialize( ApiPacket : RB_SPRO_APIPACKET_PTR ) : WORD;
STDCALL; EXTERNAL;


FUNCTION SproInitialize( ApiPacket : RB_SPRO_APIPACKET_PTR ) : WORD;
VAR
returnVal : WORD;
BEGIN
returnVal := RNBOsproFormatPacket (ApiPacket, RB_SPRO_APIPACKET_SIZE);
IF returnVal <> SP_SUCCESS THEN
   SproInitialize := returnVal
ELSE
   SproInitialize := RNBOsproInitialize (ApiPacket);
END; { SproInitialize }




BEGIN
END.
--

Obviously being from the time when it was received the OBJ file SPROMEPS.OBJ to
be linked in is a 32 bit type, so the ported programs need to be compiled/linked
into a 32 bit exe file on Windows.

Questions:
--

1) How should I go about translating the above to current FreePascal syntax?

This involves:
{ Force FAR calls }
{$F+}

{$L SPROMEPS.OBJ}  { LINK WITH THE SUPERPRO OBJECT FILE }

2) Is there a way to translate/convert the 32 bit Windows SPROMEPS.OBJ file into
a 64 bit one such that it could be used for a 64 bit fpc compiler?
It is the interface to the protection key driver on the Windows system...

It does work for our 32 bit Delphi7 programs on Windows 10 x64, so there must be
some 32<->64 bit handling in Windows maybe?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Calculating CRC16?

2022-10-25 Thread Bo Berglund via fpc-pascal
On Tue, 25 Oct 2022 08:30:19 +0200, Bo Berglund via fpc-pascal
 wrote:

>I am working on a handler for IoT data from an electricity meter which
>communicates via TTL serial at 115200 baud. It only sends data in packets of
>less than 1 kbytes every 5-10 seconds.
>
>In order to validate the data I need to check the CRC16 checksum at the end and
>here is where I don't find a good way to do it...
>The application will run on Linux so I checked for operating support but found
>only sksum, which apparently does not do CRC16.
>
>Is there some package or code available somewhere which can calculate the CRC16
>value over a byte array of some 1000 bytes?
>
>In a description of the protocol after showing the data structure it adds this:
>
>crc16 = libscrc.ibm(example_data).to_bytes(2, 'big').hex() >> '7945'
>
>Googling libscrc brings me to Python code on GitHub, which I am not really able
>to use, never programmed Python...
>https://github.com/hex-in/libscrc
>
>Anyone able to help with FPC implementation?

I have found a c++ function that purportedly does CRC16:

unsigned int CRC16(unsigned int crc, unsigned char *buf, int len)
{
for (int pos = 0; pos < len; pos++)
{
crc ^= (unsigned int)buf[pos];// * XOR byte into least sig. 
byte of
crc
  // * Loop over each bit
for (int i = 8; i != 0; i--)
{
// * If the LSB is set
if ((crc & 0x0001) != 0)
{
// * Shift right and XOR 0xA001
crc >>= 1;
crc ^= 0xA001;
}
// * Else LSB is not set
else
// * Just shift right
crc >>= 1;
    }
    }
return crc;
}

Can someone please decode this into pascal?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Calculating CRC16?

2022-10-25 Thread Bo Berglund via fpc-pascal
I am working on a handler for IoT data from an electricity meter which
communicates via TTL serial at 115200 baud. It only sends data in packets of
less than 1 kbytes every 5-10 seconds.

In order to validate the data I need to check the CRC16 checksum at the end and
here is where I don't find a good way to do it...
The application will run on Linux so I checked for operating support but found
only sksum, which apparently does not do CRC16.

Is there some package or code available somewhere which can calculate the CRC16
value over a byte array of some 1000 bytes?

In a description of the protocol after showing the data structure it adds this:

crc16 = libscrc.ibm(example_data).to_bytes(2, 'big').hex() >> '7945'

Googling libscrc brings me to Python code on GitHub, which I am not really able
to use, never programmed Python...
https://github.com/hex-in/libscrc

Anyone able to help with FPC implementation?

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-23 Thread Bo Berglund via fpc-pascal
On Sun, 23 Oct 2022 23:40:32 +0200, Jean SUZINEAU via fpc-pascal
 wrote:

>Le 23/10/2022 à 22:50, Jean SUZINEAU via fpc-pascal a écrit :
>>
>> This way you'll receive the output of mosquitto_sub on the standard 
>> input of SomePascalProgram.
>>
>A very small example for SomePascalProgram for  use with pipe, reading 
>on standard input and writing on standard output :
>
>var
>    s: String;
>begin
>  repeat
>    readln( s);
>    writeln( s);
>  until false;
>end.
>

Might get stuck at readln(s) if no messages are sent, i.e. no carriage-return
coming along?
AFAIK readln is blocking, right?

I will try things out tomorrow, it's midnight now...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-23 Thread Bo Berglund via fpc-pascal
On Sun, 23 Oct 2022 11:51:31 +0200, Bo Berglund via fpc-pascal
 wrote:

>TESTING.
>No it does not work!
>The mosquitto output cannot be redirected like this because it seems to be
>printed to an output screen which is not redirectable...
>All that happens is that an empty file is created at start of the command and
>then nothing more...

Well, I was wrong, it *does* work if done properly...

First of all, it seems like the call to mosquitto_sub with redirection somehow
opens that file for writing *once* and then you cannot delete that file from the
outside because mosquitto will keep writing to it but now it is invisble to all
others...
This is on an ext4 file system where deleted files still exist such that an
application can keep working with it even when the directory system has lost it.
I have tested this on Ubuntu 20.04 server:

mosquitto_sub -h 192.168.117.131 -F '@Y-@m-@d @H:@M:@S ; %t ; %p' -t '#' >>
mqttlog.txt

And this happens:

- every new message coming in is logged to that file as a new line
- if I delete that file (from another terminal window) then the
  file is *not* recreated when a new message arrives and there is
  no longer any accessible logging. The file still exists, but
  is not visible anywhere else any longer.
- but if I echo a blank to the file (echo "" > mqttlog.txt) then
  the file *contents* gets erased but it accepts new messages.

So the procedure needs to be:
- start mosquitto_cli as shown with >> redirection
- then look for the log file to change size
- open it for read/write
- copy out all the lines
- erase the content and then save the file and close the handle
- it is now an empty file waiting for new data

Then one can process the saved content of the file and do whatever is needed
depening on that.
And finally return to waiting for the file size change again

All of this can be done with an FPC command line program, I believe.
But...

QUESTION:
-
It seems like I should not have to start a shell with the mosquitto_cli program
when there is TProcess, which could run it directly and read the data without
using an intermediate log file...

I have found this:
https://wiki.freepascal.org/Executing_External_Programs#Reading_large_output

How should I accomplish the above using TProcess?
- The called application mosquitto_cli must run until my program itself exits
- The data produced by the process should be checked while the process runs
- Using a TMemoryStream to retrieve the output is apparently the way

But how can I handle this situation:
- The incoming data is arriving one msg at a time with seconds in between
- The messages may contain 10-1500 characters each
- How to check that the stream has received all data for one transmission?

Can I do this (using the example from the wiki link above):

// All generated output from AProcess is read in a loop until no more data...
repeat
  repeat
BytesRead :=  AProcess.Read(Buffer, BUF_SIZE);
OutputStream.Write(Buffer, BytesRead)
  until BytesRead = 0;  // Stop if no more data is available
  ProcessIncomingMessages(OutputStream);
until 1 //Run forever... How do I get out eventually ??

What happens if the data in the AProcess output stream is less than my buffer
size, will it then stall until as many messages have arrived as will fill the
buffer?

This cannot be allowed to happen because there may be hours before the next
burst of messages.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-23 Thread Bo Berglund via fpc-pascal
On Sun, 23 Oct 2022 05:19:24 +0200, Jean SUZINEAU via fpc-pascal
 wrote:

>Le 22/10/2022 à 23:37, Bo Berglund via fpc-pascal a écrit :
>> If I could get at each output that mosquitto_cli writes into a script or such
>> then I would be good to go.
>Maybe with a redirection ( > ) to a file in bash ?

Do you mean something like this then:

Scriptfile checkmqtt:

#!/bin/bash
COMMFILE="$HOME/mqtt/messages"
eval "mosquitto_sub -h  -F '@Y-@m-@d @H:@M:@S ; %t ; %p' -t '#' >>
$COMMFILE"

And then an FPC program that essentially starts the script and then loops
checking for the existence of file $HOME/mqtt/messages and if found opens it and
processes each line of data and then erases the file?

Or even cleaner the FPC program could launch the command itself as a separate
process (in a thread maybe) and then loop as above checking for the output file
and so on?

Seems a bit roundabout but would use the existing working mosquitto program on
the Linux box to do the MQTT work...

I know that there will be about 5-10 seconds between each MQTT message arriving
so there is ample time to process each arrival.

TESTING.
No it does not work!
The mosquitto output cannot be redirected like this because it seems to be
printed to an output screen which is not redirectable...
All that happens is that an empty file is created at start of the command and
then nothing more...

So how can one make mosquitto write output to a file instead?

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-22 Thread Bo Berglund via fpc-pascal
On Fri, 21 Oct 2022 16:32:17 +0200, Koenraad Lelong via fpc-pascal
 wrote:

>FWIW,
>I'm using MQTT via cmd-line. I.e. I call
>  ExecuteProcess(MQTTExec,MQTTStrArr);
>while MQTTExec is /usr/bin/mosquitto_pub
>
>That's on a linux-server.

I can use mosquitto for the pub part because that is a one-timer for each
message to send.
The problem is the other side, the client subscribing to the data...

Here the mosquitto_cli is running constantly and printing data as they come in
to the terminal window.
How can I pick that up from an application that will handle the data and do
something other than wayching the screen?

If I could get at each output that mosquitto_cli writes into a script or such
then I would be good to go.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-20 Thread Bo Berglund via fpc-pascal
On Thu, 20 Oct 2022 11:11:17 +0200, Bo Berglund via fpc-pascal
 wrote:

>On Tue, 11 Oct 2022 19:42:26 +0200 (CEST), Karoly Balogh via fpc-pascal
> wrote:
>
>>Hi,
>>
>>On Tue, 11 Oct 2022, Bo Berglund via fpc-pascal wrote:
>>
>>> I am looking for a pascal implementation of the MQTT protocol.
>>> I could not find anything inside Lazarus' OnLinePackageManager.
>>>
>>> Is there something like that available?
>>
>>I made a front-end Pascal library, and and Object Pascal wrapper for
>>libmosquitto a couple of years ago. It's available here. It's know to work
>>on Linux, Windows and macOS at least. It's against libmosquitto 1.x. Not
>>sure if 2.x got released meanwhile. I can update things if needed. (Pull
>>requests are welcomed.)
>>
>>It's available here:
>>https://github.com/chainq/mosquitto-p
>
>Well, the version of the mosquitto broker server that gets installed on my
>RaspberryPi4 is:
>
>$ mosquitto --version
>Error: Unknown option '--version'.
>mosquitto version 2.0.11
>mosquitto is an MQTT v5.0/v3.1.1/v3.1 broker.
>
>So this is what I have to communicate with as a client.
>
>I need to be able to publish as well as subscribe to topics.
>
>In the Lazarus forum I have seen people having problems with this when they use
>various FPC packages while the native command line works OK (on Linux), 
>probably
>because they are using old packages not updated for the changes made in MQTT in
>recent years.
>
>So this is why I am asking if there is some MQTT client package available for
>FPC/Lazarus that complies to the updated protocols?

I found this on the Lazarus forum:
https://forum.lazarus.freepascal.org/index.php/topic,54397.msg435050.html#msg435050

Not a poackage, but rather advice on how to utilize binary "drivers" installed
on the system via translated header files. Not optimal, but might be doable
anyway.

I will try that path going forward, just now dealing with the MQTT source
devices.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-20 Thread Bo Berglund via fpc-pascal
On Tue, 11 Oct 2022 19:42:26 +0200 (CEST), Karoly Balogh via fpc-pascal
 wrote:

>Hi,
>
>On Tue, 11 Oct 2022, Bo Berglund via fpc-pascal wrote:
>
>> I am looking for a pascal implementation of the MQTT protocol.
>> I could not find anything inside Lazarus' OnLinePackageManager.
>>
>> Is there something like that available?
>
>I made a front-end Pascal library, and and Object Pascal wrapper for
>libmosquitto a couple of years ago. It's available here. It's know to work
>on Linux, Windows and macOS at least. It's against libmosquitto 1.x. Not
>sure if 2.x got released meanwhile. I can update things if needed. (Pull
>requests are welcomed.)
>
>It's available here:
>https://github.com/chainq/mosquitto-p

Well, the version of the mosquitto broker server that gets installed on my
RaspberryPi4 is:

$ mosquitto --version
Error: Unknown option '--version'.
mosquitto version 2.0.11
mosquitto is an MQTT v5.0/v3.1.1/v3.1 broker.

So this is what I have to communicate with as a client.

I need to be able to publish as well as subscribe to topics.

In the Lazarus forum I have seen people having problems with this when they use
various FPC packages while the native command line works OK (on Linux), probably
because they are using old packages not updated for the changes made in MQTT in
recent years.

So this is why I am asking if there is some MQTT client package available for
FPC/Lazarus that complies to the updated protocols?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-11 Thread Bo Berglund via fpc-pascal
I am looking for a pascal implementation of the MQTT protocol.
I could not find anything inside Lazarus' OnLinePackageManager.

Is there something like that available?

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Are there any drawbacks to "reference to"?

2022-06-06 Thread Bo Berglund via fpc-pascal
On Mon, 6 Jun 2022 08:26:47 +0700, Hairy Pixels via fpc-pascal
 wrote:

>First off I didn’t see Anthony’s original email, just like Sven says he 
>doesn’t see mine. 
>What’s going on here? I’m using a Gmail account because my personal domain was 
>getting 
>rejected for some reason, is Anthony on Gmail also? We need to get this fixed 
>I think.

You can interface this discussion via GMane news mirror

I use a dedicated news reader and it has these advantages:
- Does not pollute my regular email account with lots of messages
- Keeps a threaded local archive of the discussions for easy reference
- Any such blockades you describe are non-existent

Point your news reader to news.gmane.io and subscribe to:

gmane.comp.compilers.free-pascal.general
gmane.comp.ide.lazarus.general
gmane.comp.compilers.free-pascal.devel


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Where can I find working code for xidel and dependencies

2022-01-09 Thread Bo Berglund via fpc-pascal
On Sun, 09 Jan 2022 17:46:00 +0100, Bo Berglund via fpc-pascal
 wrote:

>I have been adviced to use xidel to analyze the content of websites, so when
>searcing for it I found that it is a FreePascal utility with the sources on
>GitHub.
>https://www.videlibri.de/xidel.html
>So I tried to get it going.
>Buit when I tried to compile the utility using Lazarus 2.0.12/FPC 3.2.0 it
>failed to find package "internettools".
>After some searching I found it on GitHub:
>https://github.com/benibela/internettools
>
>But still no luck, I get errors when trying to compile the internettools
>package

UPDATE:
---
After trying to fix this I decided to search for binaries and found them here:
https://sourceforge.net/projects/videlibri/files/Xidel/Xidel%200.9.8/
These I believe are all for PC style CPU:s

So I will not need to build it myself unless I want to run it on a RaspberryPi
of course.

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Where can I find working code for xidel and dependencies

2022-01-09 Thread Bo Berglund via fpc-pascal
I have been adviced to use xidel to analyze the content of websites, so when
searcing for it I found that it is a FreePascal utility with the sources on
GitHub.
https://www.videlibri.de/xidel.html
So I tried to get it going.
Buit when I tried to compile the utility using Lazarus 2.0.12/FPC 3.2.0 it
failed to find package "internettools".
After some searching I found it on GitHub:
https://github.com/benibela/internettools

But still no luck, I get errors when trying to compile the internettools
package:
Compile package internettools 0.0: Exit code 1, Errors: 1, Warnings: 2
bbutils.pas(1060,15) Warning: Symbol "strDecodeUTF8Character" is deprecated:
"Use (pchar,pchar) overload or strIterator."
bbutils.pas(5890,13) Warning: Symbol "strEncodeHex" is deprecated
xquery.internals.common.pas(434,80) Fatal: Cannot find PasDblStrUtils used by
xquery.internals.common of package internettools.
Compile package internettools 0.0: Exit code 1, Errors: 1, Warnings: 2
bbutils.pas(1060,15) Warning: Symbol "strDecodeUTF8Character" is deprecated:
"Use (pchar,pchar) overload or strIterator."
bbutils.pas(5890,13) Warning: Symbol "strEncodeHex" is deprecated
xquery.internals.common.pas(434,80) Fatal: Cannot find PasDblStrUtils used by
xquery.internals.common of package internettools.

Has anyone here successfully managed to build xidel, if so what is the recepy?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is there a range limitation for the in operator?

2021-12-22 Thread Bo Berglund via fpc-pascal
On Wed, 22 Dec 2021 17:07:55 +0100, Sven Barth via fpc-pascal
 wrote:

>Bo Berglund via fpc-pascal  schrieb am
>Mi., 22. Dez. 2021, 16:08:
>
>> So I wonder if there is a value range limitation for the arguments inside
>> an in
>> command like:
>> if a in [x..y] then
>>
>
>The right side of the in-operator is a set constructor. And sets may only
>contain up to 256 values. (Though I don't know right now whether that is
>always counted from 0 or not)
>

Ok, thanks. Figured that it was something like that.
So I have to stack several if conditions instead.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Is there a range limitation for the in operator?

2021-12-22 Thread Bo Berglund via fpc-pascal
I have been debugging a file analyzer program which is supposed to show a record
if one clicks in the hex representation of the binary file content.

I have a function which will grab the start and length of a record given the
address clicked on.

The file contains several different sections, basically:
- header (30 bytes)
- array of type 1 records (n * 14 bytes)
- array of type 2 records (m * 25 bytes)
The counts m and n are available in the header record as word size values.

So I have this construct to translate theinput address into a start and length
result:
if Addr in [0..sizHd-1] then  //Clicked in the header
begin
  //Calculate start and end address of header
end
else if Addr in [(sizHd)..(sizHd + sizGeos -1)] then
begin
  //Calculate start and end address of clicked record in array
end
else if Addr in [(sizHd + sizGeos)..(sizHd + sizGeos + sizCmds -1)] then
begin
  //Calculate start and end address of clicked record in array
end;

This seemingly worked fine until I clicked inside the area of he type 2 records,
when the execution never got to the last calculation...

So I changed the code from using "in" to this instead:

else if (Addr >= strtCmds) and (Addr < (strtCmds + sizCmds)) then

Where I previously have done this:
strtCmds := strtElecs + sizGeos;

Now it works as planned

So I wonder if there is a value range limitation for the arguments inside an in
command like:
if a in [x..y] then

???


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Building fpc 3.2.2 from sources - which compiler to use for install?

2021-12-06 Thread Bo Berglund via fpc-pascal
On Mon, 6 Dec 2021 13:29:31 +0100, Marco van de Voort via fpc-pascal
 wrote:

>
>Op 6-12-2021 om 12:53 schreef Bo Berglund via fpc-pascal:
>>   
>>
>> I.e. should I use the newly compiled 3.2.2 in this step or the seed compiler,
>> which is the previous version?
>>
>>
>New. See buildfaq.

I used this:

make install PREFIX="$HOME" FPC="$HOME/devel/fpc/3.2.2/compiler/ppcx64"
ln -sf "$HOME/lib/fpc/3.2.2/ppcx64" "$HOME/bin/ppcx64"
make sourceinstall PREFIX="$HOME" FPC="$HOME/bin/ppcx64"

Seems to have worked fine.
Was able to continue with Lazarus using the $HOME/bin/ppcx64 compiler.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Building fpc 3.2.2 from sources - which compiler to use for install?

2021-12-06 Thread Bo Berglund via fpc-pascal
I am building fpc 3.2.2 from sources on a Linux Mint x64 box.
When I compile fpc inside the downloaded source folder I use this:

make all FPC="$HOME/devel/fpc/ppcx64"

The FPC compiler in this case is 3.2.0, which I have built earlier on another
box. This works fine.

Now I am at the next step and here I am unsure which FPC to specify:

make install PREFIX="$HOME" FPC="$HOME/devel/fpc/ppcx64"

or

make install PREFIX="$HOME" FPC="$HOME/devel/fpc/3.2.2/compiler/ppcx64"

I.e. should I use the newly compiled 3.2.2 in this step or the seed compiler,
which is the previous version?



-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Make clean error when building fpc 3.2.2 from sources

2021-11-22 Thread Bo Berglund via fpc-pascal
On Mon, 22 Nov 2021 16:47:29 +0100, Tomas Hajny via fpc-pascal
 wrote:

>On 2021-11-22 16:21, Jonas Maebe via fpc-pascal wrote:
>> On 22/11/2021 16:02, Bo Berglund via fpc-pascal wrote:
>>> This is what happens when I execute the first make command inside the 
>>> fpc source
>>> dir:
>>> 
>>>~/devel/fpc/3.2.2$ make clean
>>>make: -iVSPTPSOTO: Command not found
>>>/usr/bin/rm -f build-stamp.*
>>>/usr/bin/rm -f base.build-stamp.*
>>> 
>>> I have checked that build-essentials are installed on this Ubuntu 
>>> machine.
>>> 
>>> Where do I go from here?
>> 
>> FPC needs a previous version of FPC to bootstrap. So first install fpc
>> using apt-get on the VM.
>
>While the answer from Jonas is obviously the simplest and most complete 
>solution, there is an alternative workaround (not necessarily a fully 
>guaranteed solution!) for your situation. The particular failing / 
>missing command used by make is the fpc binary. If you have installed a 
>bootstrap compiler _and_ if you try to perform a native build (not to 
>build for a different CPU), you can run make with an additional 
>parameter setting the variable "FPC" to the path of your compiler binary 
>(e.g. 'make all "FPC=/usr/bin/ppcx64"').

Thanks, I thought that would not be needed when only doing clean...
Was going to add it in the next step "make all"
Now running the build.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Make clean error when building fpc 3.2.2 from sources

2021-11-22 Thread Bo Berglund via fpc-pascal
I am trying to build fpc 3.2.2 on an Ubuntu 20.04.3 virtual machine while
documenting my steps along the way.
I am doing this so I can later repeat it on the real target and after getting
the fpc sources not through SVN but using this wget command which I received
after asking on the forum:

wget
https://gitlab.com/freepascal.org/fpc/source/-/archive/release_3_2_2/source-release_3_2_2.tar.gz

Then expanding the file into dir ~/devel/fpc/3.2.2 using:

  tar -xvf source-release_3_2_2.tar.gz
  mv source-release_3_2_2 3.2.2

I have also downloaded a seed compiler ppcx64 version 3.2.0 and symlinked it
into my ~/bin dir.

This is what happens when I execute the first make command inside the fpc source
dir:

  ~/devel/fpc/3.2.2$ make clean
  make: -iVSPTPSOTO: Command not found
  /usr/bin/rm -f build-stamp.*
  /usr/bin/rm -f base.build-stamp.*

I have checked that build-essentials are installed on this Ubuntu machine.

Where do I go from here?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-28 Thread Bo Berglund via fpc-pascal
On Sun, 24 Oct 2021 08:18:31 +, Alexander Grotewohl via fpc-pascal
 wrote:

>In the end we have a black box with Indy that isn't going to be opened.. 
>and from the sound of it, a dated method of manually checking for i/o 
>(in this case likely with select() and a zero timeout..). Calling that 
>and sleep() over and over millions of times..
>
>I'm sorry to the OP if I'm assuming a lot but my guess is the code is 
>a bit old and could use some refactoring to do away with the old Pascal 
>"active loop."

Yes it is *old* code written with Delphi starting from about 2004 and
"maintained" on Windows up until 2012 or thereabouts.

Issues were discovered on Windows7 but these were fixed and then Windows 10 made
it so much worse that I decided to try and port it over to Linux.

It is a Windows TService application ported to a command line program on Linux
so the base framework had to be modified a lot...
But the majority of the code is only modified wherever it deals with protection
dongles and read/write the Windows Registry.
Plus all file system accesses using \ separators and drive letters...
And of course the event driven model as a whole...

As long as it does not eat up more than 10% or so CPU I might have to swallow
it. And maybe schedule a regular restart of the server to clear whatever builds
up.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-17 Thread Bo Berglund via fpc-pascal
On Sun, 17 Oct 2021 12:03:44 +0200 (CEST), Michael Van Canneyt via fpc-pascal
 wrote:

>> Does this mean that:
>> _newselect is running for 207 ms during the 3 second test time?
>> (Which is 17 ms per call)
>>
>> And what is _newselect in the first place?
>
>Select (or _newselect) checks if there is activity on a file descriptor.
>If you're working with Indy, it uses this call to check for data on a
>socket; It is called frequently.
>
>> I assume nanosleep is some kind of Linux API call made by fpc when it invokes
>> sleep() in my code.
>
>Yes.
>
>>
>> And futex
>
>Futex is used for thread synchronisation. 
>Again, if you're using Indy and threads, it is called a lot.

You are right concerning Indy usage!
This is what is used for the networking part. The application has been ported
from Delphi on Windows where it was a TService based application.

I will have to look at what is going on with the permanent increase in activity
during (expected) and after a task execution (should go back to idle).

But I will have to do a couple of more checks where I make it start a task and
while the task executes run the strace -c recording.

Some objects might not be freed properly or else do not get down to idle
activity...

The code is quite big and handles several separate aspects, like client
communication via TCP/IP socket, scheduling the tasks, running a task and
collecting the output data, mailing the result data to configured recipients.

My test done with strace was done after I have communicated with the application
as a client.
I really need to test this:
- right after the service restart
- during a client communication session
- after disconnecting a client
- after switching on scheduling
- during a task execution
- after task execution

So there will be a lot of data gathering to see what changes, but since I did
not know about strace and it seems able to do this it might actually work.

Thanks for pointing me towards it!


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-17 Thread Bo Berglund via fpc-pascal
On Sun, 17 Oct 2021 00:43:51 +0200, Bo Berglund via fpc-pascal
 wrote:

>timeout --signal=2 3s strace -f -c -p 488 -o tracelog2.log
>
>% time seconds  usecs/call callserrors syscall
>-- --- --- - - 
> 46.470.348353 414   841   nanosleep
> 27.670.207437   1728612   _newselect
> 16.170.121220 211   57277 futex

So 90.3 % of the time is spent in these 3 syscalls...

Does this mean that:
_newselect is running for 207 ms during the 3 second test time?
(Which is 17 ms per call)

And what is _newselect in the first place?

I assume nanosleep is some kind of Linux API call made by fpc when it invokes
sleep() in my code.

And futex????


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-16 Thread Bo Berglund via fpc-pascal
On Sat, 16 Oct 2021 18:16:57 -0400, Travis Siegel via fpc-pascal
 wrote:

>
>On 10/16/2021 6:06 PM, Bo Berglund via fpc-pascal wrote:
>> Meanwhile the strace outputs stuff like this to the screen:
>> strace: Process 6360 attached
>> strace: Process 6361 attached
>> strace: Process 6362 attached
>> strace: Process 6363 attached
>> strace: Process 6364 attached
>> strace: Process 6365 attached
>> strace: Process 6366 attached
>> strace: Process 6367 attached
>> strace: Process 6368 attached
>> strace: Process 6369 attached
>> strace: Process 6370 attached
>> strace: Process 6371 attached
>> strace: Process 6372 attached
>>
>> I don't understand what this means either
>>
>It looks like your application is spawning additional processes. If it's 
>supposed to do that, then all is well.  If it isn't supposed to do that 
>when it's idling, then you have some troubleshooting to do. :)

I found a howto-page for strace so I could modify the call to have strace
produce a summary after running for the set time (3 seconds here).
Easier read but does not give me much to work with.

timeout --signal=2 3s strace -f -c -p 488 -o tracelog2.log

% time seconds  usecs/call callserrors syscall
-- --- --- - - 
 46.470.348353 414   841   nanosleep
 27.670.207437   1728612   _newselect
 16.170.121220 211   57277 futex
  2.540.019020  89   213   munmap
  1.770.013281  62   213   mmap2
  1.630.012250  43   284   284 ioctl
  0.730.005485  7771   madvise
  0.550.004137  29   142   gettimeofday
  0.530.003958  27   142   clock_gettime
  0.510.003858  5471   rt_sigprocmask
  0.370.002748  3871   clone
  0.360.002688  3771   sched_setscheduler
  0.310.002315  3271   set_robust_list
  0.300.002262  3171   ugetrlimit
  0.070.000548 182 3 1 restart_syscall
-- --- --- - - 
100.000.749560  2848   362 total

I don't really see how this helps either, though

As a reminder here is the main application's loop:

  While not (bSTerm or bSInt or bsHup) do
  begin
//Here is where the server runs as defined elsewhere
//Eternal loop to wait for system messages
Sleep(5); //To not hog the CPU
CheckSynchronize(); //No timeout here since sleep is used
//CheckSynchronize(5); //Timeout here instead of using sleep
if CheckRestartReq then
begin
  Debug_Writeln('Restart timeout reached - exiting');
  FLogServ.StdLog('Restart timeout reached - exiting');
  break;
  //FServerStartTick := GetTickCount64; //Reset timeout for now
end;
  end;

And CheckRestartReq implementation:
Note that FRemoteTaskServer.AutoRestartInterval is 0 here.
So the function CheckRestartReq should always return immediately with a false
result.

function CheckRestartReq: boolean;
var
  NextStart: TDateTime;
begin
  Result := false;
  if FRemoteTaskServer.AutoRestartInterval < 120 then exit; //Not configured for
automatic restart (min time 2 min)
  if (GetTickCount64 - FServerStartTick) <
(FRemoteTaskServer.AutoRestartInterval * 1000) then exit; //Not reached set
restart time yet
  if FRemoteTaskServer.TaskRunning then exit; //Cannot restart when task is
running
  if FSuperStingSocketServer.ClientCount > 0 then exit; //Cannot restart when
client connected

  NextStart := FRemoteTaskServer.NextTaskStartTime; //Get next time a task will
start
  if NextStart = 0 then  //No task scheduled to start so OK to restart server
  begin
Result := true;
exit;
  end;
  if (NextStart - Now) > (2.0 / 60 / 24) then  Result := true; // More than 2
minutes until next task start, so OK to exit
end;


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-16 Thread Bo Berglund via fpc-pascal
On Fri, 8 Oct 2021 00:12:50 +0200 (CEST), Michael Van Canneyt via fpc-pascal
 wrote:

>> No matter how long I wait it is now stuck at that double value.
>>
>> So clearly something must be left behind after the task has finished...
>>
>> The question is: how to find what is still using CPU?
>
>Run the process under strace:
>strace -f -p PID -o log1.txt
>with PID the process ID.
>
>You will see what system calls are executed. Do this when the load is 4% and
>when it's 8%, maybe this will tell you something.
>

Sorry for not getting back until now, but I have been dealing with Linux system
upgrades the whole week...

So I tried this at an idle time after start on the test system when nothing has
happened and top shows 4% CPU usage. PID of the application is 488.

strace -f -p 488 -o tracelog1.log

It resulted in a massive tracelog1.log logfile with stuff like this (cut at
random iside the file):

488   <... nanosleep resumed> 0x7ee339f0) = 0
488   nanosleep({tv_sec=0, tv_nsec=500}, 0x7ee339f0) = 0
488   nanosleep({tv_sec=0, tv_nsec=500},  
533   <... nanosleep resumed> 0x76212bb0) = 0
533   nanosleep({tv_sec=0, tv_nsec=1000},  
488   <... nanosleep resumed> 0x7ee339f0) = 0
488   nanosleep({tv_sec=0, tv_nsec=500}, 0x7ee339f0) = 0
488   nanosleep({tv_sec=0, tv_nsec=500},  
533   <... nanosleep resumed> 0x76212bb0) = 0
533   nanosleep({tv_sec=0, tv_nsec=1000},  
488   <... nanosleep resumed> 0x7ee339f0) = 0
488   nanosleep({tv_sec=0, tv_nsec=500},  
533   <... nanosleep resumed> 0x76212bb0) = 0
533   nanosleep({tv_sec=0, tv_nsec=1000},  
488   <... nanosleep resumed> 0x7ee339f0) = 0
488   nanosleep({tv_sec=0, tv_nsec=500}, 0x7ee339f0) = 0
488   nanosleep({tv_sec=0, tv_nsec=500},  
6063  <... futex resumed> ) = -1 ETIMEDOUT (Connection timed out)
6063  futex(0x76f6fb98, FUTEX_WAKE_PRIVATE, 1) = 0
6063  mmap2(NULL, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0x75e0b000
6063  futex(0x75e0b048, FUTEX_WAIT_PRIVATE, 0, NULL 
533   <... nanosleep resumed> 0x76212bb0) = 0
533   nanosleep({tv_sec=0, tv_nsec=1000},  
488   <... nanosleep resumed> 0x7ee339f0) = 0
488   clone( 
6064  set_robust_list(0x75aff4b0, 12)   = 0
6064  futex(0x75aff654, FUTEX_WAIT_PRIVATE, 2, NULL 
488   <... clone resumed> child_stack=0x75afef78,
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CL$
488   sched_setscheduler(6064, SCHED_OTHER, [0]) = 0
488   futex(0x75aff654, FUTEX_WAKE_PRIVATE, 1 
6064  <... futex resumed> ) = 0
488   <... futex resumed> ) = 1
6064  futex(0x75aff654, FUTEX_WAKE_PRIVATE, 1 
488   clock_gettime(CLOCK_MONOTONIC_RAW,  
6064  <... futex resumed> ) = 0
488   <... clock_gettime resumed> {tv_sec=228720, tv_nsec=105079052}) = 0

which I really understand nothing of...

Running for some 5-10 secnds resulted in a logfile of 2 MB size

Meanwhile the strace outputs stuff like this to the screen:

strace: Process 6360 attached
strace: Process 6361 attached
strace: Process 6362 attached
strace: Process 6363 attached
strace: Process 6364 attached
strace: Process 6365 attached
strace: Process 6366 attached
strace: Process 6367 attached
strace: Process 6368 attached
strace: Process 6369 attached
strace: Process 6370 attached
strace: Process 6371 attached
strace: Process 6372 attached

I don't understand what this means either


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-07 Thread Bo Berglund via fpc-pascal
On Tue, 5 Oct 2021 10:22:44 +0200 (CEST), Michael Van Canneyt via fpc-pascal
 wrote:

>> My program in Lazarus *is* a "simple program" and it has no GUI components.
>>
>> I never even looked at the implementation of CheckSynchronize()...
>> It was just given in another thread when I was working on the port from 
>> Delphi
>> to Linux and thus from the Windows GUI environment to the non-GUI command 
>> line
>> program environment.
>
>The name 'Gui thread' is misleading. It's simply the main program thread.
>
>If you want to use TThread.Synchronize then the call to CheckSynchronize is
>needed. The LCL for GUI application simply calls it automatically for you.
>In a non-GUI command-line program, you're responsible for calling it from
>time to time.

That is what I had learned back in beginning of this year when I was starting
testing on actual hardware. Checksynchronize is needed in the main program loop
in order for threads to fire off events etc. I use threads to handle serial port
communications, and the threads should be disposed of after use...

Now I have done some more investigations and I am more confused by it...
My service program runs at about 4% CPU usage as shown by top. This holds true
for a long time after starting it (several idle days).

But when a client connects to inspect data on the system the usage spikes when
he commands some data display etc. But then goes back to the 4% or so.

If the client enables a task to be executed then nothing really happens until
that task starts on its set time.
At that time the CPU usage raises from 4% to 11% and goes up/down a few % for
the minutes it runs and then returns to an idle value of about 8%, which it
never gets below after that.

No matter how long I wait it is now stuck at that double value.

So clearly something must be left behind after the task has finished...

The question is: how to find what is still using CPU?

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-04 Thread Bo Berglund via fpc-pascal
On Mon, 04 Oct 2021 12:46:32 -0400, Dennis Lee Bieber via fpc-pascal
 wrote:

>
>   COMMENT: here you ask about a non-GU /service/ application, but in your
>prior post you gave a code snippet. It may just be a documentation flaw,
>but...
>
>-=-=-
>{ function to be called when gui thread is ready to execute method
>  result is true if a method has been executed
>}
>function CheckSynchronize(timeout : longint=0) : boolean;
>var
>  { method proc that is called to trigger gui thread to execute a
>method }
>  WakeMainThread : TNotifyEvent = nil;

My program in Lazarus *is* a "simple program" and it has no GUI components.

I never even looked at the implementation of CheckSynchronize()...
It was just given in another thread when I was working on the port from Delphi
to Linux and thus from the Windows GUI environment to the non-GUI command line
program environment.

It was needed in the main loop in order for threads down inside the program to
be able to transfer their data into an event handler which is processing
incoming data.

Originally I had a sleep(5) inside the loop too, but I took that out when it was
clear that CheckSynchronize had a timeout argument (optional).

It is now close to midnight so I have to postpone any testing until tomorrow.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is the Lazarus list down? (2021-10-04)

2021-10-04 Thread Bo Berglund via fpc-pascal
On Mon, 04 Oct 2021 06:45:23 -0400, DougC via fpc-pascal
 wrote:
> On Mon, 04 Oct 2021 04:36:32 -0400 Bo Berglund via fpc-pascal 
> wrote 
>
>
>>On Mon, 04 Oct 2021 10:28:38 +0200, Bo Berglund via fpc-pascal
><mailto:fpc-pascal@lists.freepascal.org> wrote:
>>
>>>I have tried to post to the list (via GMane) but it does not come through.
>>>And the last post made seems to be on 2021-10-01...
>>>Is the list itself down or is there a GMane problem?
>>
>>Seems to be GMane...
>>I repeated the posting via email instead and this appears in the GMane 
>>listing.
>>So their posting function seems to have broken for the lazarus list. :(
>

>I received the original posting and also the second direct attempt.
>
>Doug C.

Well, then there is something else going on at GMane...
I am using a newsreader to communicate with the mail list via GMane and on this
fpc list posts I make are shown after a little wait.

But on the lazarus list I post and I do not see my message at all in the list,
even now after so long time has passed.
But when I sent the same post via email to the list then it appeared almost
directly. And following that I have received replies to my emailed query on the
GMane server...
I wonder why it does not list the posts I make via GMane but does so for the
posts I email?
Note: it seems opnly to affect the lazarus list.

Anyway, it is not an fpc topic, I just posted here to get in touch with people
also on the lazarus list


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is the Lazarus list down? (2021-10-04)

2021-10-04 Thread Bo Berglund via fpc-pascal
On Mon, 04 Oct 2021 10:28:38 +0200, Bo Berglund via fpc-pascal
 wrote:

>I have tried to post to the list (via GMane) but it does not come through.
>And the last post made seems to be on 2021-10-01...
>Is the list itself down or is there a GMane problem?

Seems to be GMane...
I repeated the posting via email instead and this appears in the GMane listing.
So their posting function seems to have broken for the lazarus list. :(


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Is the Lazarus list down? (2021-10-04)

2021-10-04 Thread Bo Berglund via fpc-pascal
I have tried to post to the list (via GMane) but it does not come through.
And the last post made seems to be on 2021-10-01...
Is the list itself down or is there a GMane problem?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-04 Thread Bo Berglund via fpc-pascal
On Sun, 03 Oct 2021 19:51:49 +0200, Bo Berglund via fpc-pascal
 wrote:

>In this scenario I expected next to no CPU usage when this is running as a
>service controlled by systemd, but in fact top shows the service to consume 10%
>CPU when it is doing nothing, no client connected and no task running...
>
>How can I find out what is the cause of this?
>
>I am developing using Lazarus 2.0.12 and FPC 3.2.0 on the RPi3B+.
>

I found the LazProfiler on the wiki: https://wiki.freepascal.org/LazProfiler

Could it be used to profile a service command line application (no GUI) too or
is it limited to "normal" GUI type applications?

Does it work on ARM Linux?

https://forum.lazarus.freepascal.org/index.php/topic,38983.msg420564.html#msg420564


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-03 Thread Bo Berglund via fpc-pascal
So I have this service application which is ported from a Windows Delphi 2007
TService app to a regular command line program for use in Linux.
It runs on a RaspberryPi3B+

Normally it sits idle doing nothing but waiting for a client to connect via TCP
or a time to occur when it needs to execute a task. Or else for system signals
from systemd.

So in the main program there is a loop after the initialization has been done
looking like this:

  While not (bSTerm or bSInt or bsHup) do //System exit signals
  begin
//Here is where the server runs as defined elsewhere
//Eternal loop to wait for system messages
CheckSynchronize(5); //Timeout here instead of using sleep
if CheckRestartReq then //Check if we need to restart the service
begin
  Debug_Writeln('Restart timeout reached - exiting');
  FLogServ.StdLog('Restart timeout reached - exiting');
  break;
end;
  end;

The actual stuff that is done happens inside the objects that get created before
reaching this loop and they are the following events:

If a TCP connection is made from a client a number of handler objects are
created and started for the client communications. These are done using Indy.
But if there is no client connection the objects do not exist.

On a timer timeout a check is made if there are any programmed tasks waiting for
execution. These can be scheduled on minute resolution times.
If there is no waiting task then nothing happens.

In this scenario I expected next to no CPU usage when this is running as a
service controlled by systemd, but in fact top shows the service to consume 10%
CPU when it is doing nothing, no client connected and no task running...

How can I find out what is the cause of this?

I am developing using Lazarus 2.0.12 and FPC 3.2.0 on the RPi3B+.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to list IP and MAC of network adapters on Windows?

2021-09-10 Thread Bo Berglund via fpc-pascal
On Fri, 10 Sep 2021 09:46:11 +0200, Sven Barth via fpc-pascal
 wrote:

>You can use the ipconfig command and parse its output (especially ipconfig
>/all).

I also figured that to be the case, so I will run TProcess with Ipconfig /all
and then parse the result line by line.

It looks like there is a simple system to it:

Adapter headings start at pos 1 on a line.
   Data within the adapter start on pos 4 on each line

And the adapter name starts directly after the word "adapter " on the heading
line.

Data for this adapter follow until the next adapter starts.

Should be easy enough to parse out.

Thanks!

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] How to list IP and MAC of network adapters on Windows?

2021-09-10 Thread Bo Berglund via fpc-pascal
Is there a way to enumerate the active adapters on a Windows computer with their
IPv4 and MAC addresses?

I am trying to convert a Linux reporting script to Windows, but I have a hard
time finding a suitable Windows command. The script uses common Linux commands
and tools to get the eth0 and wlan0 data (IPv4 and MAC addresses) and then to
POST it to my website mailer (php script) via curl. See below.

I have curl on Windows too so once the data are found the same command can be
used here as well, but the network info extraction seems to be a lot harder.

So I figured I could write a small FPC command line tool to extract this
information and use it in the batch file.

But is there some such call available in FPC or standard packages like LNet or
similar?

On Linux I can do this in the bash script:

MyName=$(hostname)
IPAddr=$(ifconfig eth0|grep "inet "|sed 's/ *inet //;s/ .*//')
IPAddrWiFi=$(ifconfig wlan0|grep "inet "|sed 's/ *inet //;s/ .*//')
IPMac=$(ifconfig eth0 | grep -Eo ..\(\:..\){5})
IPMacWiFi=$(ifconfig wlan0 | grep -Eo ..\(\:..\){5})

I don't believe there is a similar command line way on Windows, so therefore I
ask for a FPC way of getting it.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to get fpc and lazarus sources when svn has shut down?

2021-08-13 Thread Bo Berglund via fpc-pascal
On Thu, 12 Aug 2021 16:24:33 -0400, Dennis Lee Bieber via fpc-pascal
 wrote:

>On Thu, 12 Aug 2021 16:39:56 +0200, Bo Berglund via fpc-pascal
> declaimed
>the following:
>
>
>>
>>Not verified by building fpc and lazarus on this machine yet.
>>But it is clear that svn export is what should be in the script anyway to save
>>both time and disk space...
>>
>
>   Based upon google searches; export is used to obtain the source file
>tree but without maintaining version control on the fetched files. OTOH, co
>creates a local SVN repository with a version control subdirectory,
>metadata, etc., and working directory above it.

I know this and that was the reason that I now tested both above.

Note that I started version control life with CVS back in 2001 and there are no
metadata in CVS except for a file listing the versioned files in the checkout
including the revision.

Export is the same as if one first does a checkout and then erase the hidden CVS
directory in each folder. So the size difference between checkout and export in
CVS is tiny, whereas both svn and git keeps huge data in parallel.

>   If you never intend to apply version control to the files -- and
>download a complete new set of files for each change of interest then

For the case I am asking there is ABSOLUTELY NO WISH to keep any metadata or
possibility to update to newer revisions.
Just the complete source file trees are required.



-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to get fpc and lazarus sources when svn has shut down?

2021-08-12 Thread Bo Berglund via fpc-pascal
On Thu, 12 Aug 2021 02:08:25 -0400, Dmitry Boyarintsev via fpc-pascal
 wrote:

>On Thu, Aug 12, 2021 at 2:00 AM Bo Berglund via fpc-pascal <
>fpc-pascal@lists.freepascal.org> wrote:
>
>>
>> What could I replace these svn co (or svn export) calls with?
>>
>the current:
>svn co https://svn.freepascal.org/svn/fpc/tags/$FPCTAG/ $FPCVER
>turns into:
>svn co https://github.com/fpc/FPCSource/tags/$FPCTAG/$FPCVER



>If you open https://github.com/fpc/ you can find all the mirrors are there.
>And this is the official Github mirror, so all the latest changes should be
>reflected there pretty quickly.

Thanks,
that would be a good solution by not involving git at all...

I will change my links in the script for fpc 3.2.2 and lazarus 2.0.12 like this:

svn co https://github.com/fpc/FPCSource/tags/release_3_2_2 3.2.2
 
svn co https://github.com/fpc/Lazarus/tags/lazarus_2_0_12 2.0.12

Tested these on an RPi4 with 4GB RAM on a 24 MBps mobile broadband connection:

checkout times:
fpc: 12m 35s
lazarus:  6m 37s

Checkout size:
fpc: 697 Mb, 352 Mb in .svn/
lazarus: 392 Mb, 192 Mb in .svn/

Also tried svn export rather than svn co:

svn export https://github.com/fpc/FPCSource/tags/release_3_2_2 3.2.2x
 
svn export https://github.com/fpc/Lazarus/tags/lazarus_2_0_12 2.0.12x

checkout times:
fpc:  4m 10s
lazarus:  1m 09s

Checkout size:
fpc: 345 Mb
lazarus: 199 Mb


Not verified by building fpc and lazarus on this machine yet.
But it is clear that svn export is what should be in the script anyway to save
both time and disk space...

Thanks again, this was what I needed to know! :)


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to get fpc and lazarus sources when svn has shut down?

2021-08-12 Thread Bo Berglund via fpc-pascal
On Wed, 11 Aug 2021 23:13:28 +0200, Martin Frb via fpc-pascal
 wrote:

>Well I don't know your script, and I am not sure how exactly you do that 
>in svn

It is not done in SVN, instead I visit the (now removed) page
 https://svn.freepascal.org/svn/lazarus/ (for lazarus)
or
 https://svn.freepascal.org/svn/fpc/ (for fpc)

and look at the tags list to find the most recent release tag.
I then use that as input to my script.

>Also I do not know, if this is for a once up setup (so you only wont to 
>download the one revision and nothing else), or if you don't mind.
>(I have not measured the overhead..>)

It is for installation on a pristine RaspberryPi (or Ubuntu) machine and the
script does everything including setting up the folder tree for development and
adding the desktop shortcuts.
Of corse now it is unusable because it cannot retrieve the sources... :(

I want to download the complete source tree for the tagged revision I want to
install. I do not care if it is with metadata or not, I only ever use the files
as is and never modify them.
Of course I do not want to get excessive overhead like the complete history of
all files for eternity...
No history at all would be fine.

But retrieval via a bash script in unattended operation (because it normally
takes upwards of 20 min to install on an RPi) is what I want.

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to get fpc and lazarus sources when svn has shut down?

2021-08-12 Thread Bo Berglund via fpc-pascal
On Thu, 12 Aug 2021 11:02:50 +0200, Martin Frb via fpc-pascal
 wrote:

>1) Afaik the OT is looking at only checking out. He isn't planing on 
>making any (local) commits.

Exactly, I could have used svn export instead of svn co in my script and it
would have worked fine. But at the time I was totally geared towards co...

What I am after is a way to retrieve the sources inside a script so no webpages
to click buttons on etc, just a simple command to actually get the sources
themselves is what is requested.

I am installing on multiple Raspberry Pi devices and it simplifies a lot to use
the script.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to get fpc and lazarus sources when svn has shut down?

2021-08-11 Thread Bo Berglund via fpc-pascal
On Wed, 11 Aug 2021 23:38:23 +0200, Bart via fpc-pascal
 wrote:

>On Wed, Aug 11, 2021 at 11:37 PM Michael Van Canneyt via fpc-pascal
> wrote:
>
>> As a programmer, switching version systems should be a no-brainer.
>
>My brain begs to differ...

Thanks, then I am not alone....


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to get fpc and lazarus sources when svn has shut down?

2021-08-11 Thread Bo Berglund via fpc-pascal
On Wed, 11 Aug 2021 22:22:54 +0200 (CEST), Michael Van Canneyt via fpc-pascal
 wrote:

># Get sources
>git clone https://gitlab.com/freepascal.org/fpc/source.git  $FPCVER
># switch to branch/tag
>cd $FPCVER
>git checkout $FPCTAG
>cd ..

How big a size is the git clone going to pull?

By the looks of it I get the impression that the git clone will download every
single tag/branch/commit etc ever done and then the git checkout activates the
actual tagged file set?
If this is correct then the size on disk will be too big.

Now as I said I have not used git and for my day use cannot switch because we
use properties of svn that are simply not available in git...

I *really* do not want to revert to getting fpc/lazarus from the distro manager
via apt and therefore be stuck with old code decided by someone else.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


  1   2   3   4   5   6   >