Re: [fpc-pascal] String literals and code page of .pas source file

2020-09-13 Thread Tomas Hajny via fpc-pascal

On 2020-09-12 23:03, Tomas Hajny wrote:

On 2020-09-12 18:51, Jonas Maebe via fpc-pascal wrote:

On 12/09/2020 18:44, Sven Barth via fpc-pascal wrote:

Jonas Maebe via fpc-pascal > schrieb am Sa., 12. Sep. 
2020,

17:47:

 .
 .

While performing some tests, I came across other things which are not
very nice either (those are specific to the Win32/Win64 target due to
the difference between process codepage and console codepage). Let's
take the following test program:

{$codepage cp1250}
{$IFDEF USECRT}
uses
 Crt;
{$ENDIF USECRT}
const
 S = 'žluťoučký kůň';
var
 T: string;
begin
 T := S;
{$IFDEF USECRT}
 Write ('Using Crt');
{$ELSE USECRT}
 Write ('Not using Crt');
{$ENDIF USECRT}
 WriteLn (S);
 WriteLn (T);
 WriteLn (DefaultSystemCodepage);
 WriteLn (TextRec (Output).Codepage);
end.

Let's compile it _without_ -dUSECRT and _with_ -Mfpc first. The
original poster uses the same default codepage as me. If I start
cmd.exe and run "chcp" without parameters, it shows codepage 852 as
the console codepage. Now run the test program. It shows that the
codepage for the default file handle Output matches the console
codepage (as it should), but the string output is incorrect for both
WriteLn(S) and WriteLn(T) lines. If you perform "chcp 1250" and run
the program again, the codepages match and the string output is
correct.

If you compile the same program with -dUSECRT, the output is correct
for both WriteLn calls regardless from the console codepage setting
(i.e. both for "chcp 852" and for "chcp 1250" - and also for "chcp
65001").

If you compile the same program with -dUSECRT and -Mdelphi together
and run the program in a console window set to codepage 852 (i.e. the
default setting here), the first WriteLn call is wrong, whereas the
second gives a correct result (due to the fact that T becomes an
ansistring in mode Delphi and dynamic translation is thus performed as
opposed to the case when a shortstring or an untyped constant are
passed).


Questions resulting from my test above and the observed inconsistencies:

1) Wouldn't it be better if shortstrings are treated the same way as 
ansistrings with CP_ACP? This would make a difference only during 
assignments to strings with different codepages. Since strings with 
different codepages didn't exist in the past (and in the current 
situation they are simply broken), this change shouldn't break 
compatibility hopefully.


2) Shouldn't WriteLn with a untyped string constant parameter result in 
calling some Unicode based version of WriteLn rather than the 
shortstring overloaded version (since the constant is stored in UTF-16 
internally)?


3) Shouldn't we try to make the output of Write with and without unit 
Crt compatible to each other? If we do so, what should be the encoding 
used for output redirected to a file - should it use 
DefaultSystemCodePage, or scpConsoleCP, or what (remember that this 
question doesn't exist with unit Crt, because unit Crt isn't compatible 
with redirection).


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


Re: [fpc-pascal] Sending Hex codes over TCP/IP

2020-09-13 Thread Brian via fpc-pascal
Use Ararat Synapse .

http://synapse.ararat.cz/doc/help/

Unit blcksock  Class TTCPBlockSocket

Then send and receive byte arrays using :

Public  function SendBuffer(Buffer: TMemory; Length: Integer): Integer;
override;
Public  function RecvBuffer(Buffer: TMemory; Len: Integer): Integer;
override;

var
 Tx_buffer : array[0..n] of byte;

SentN := SendBuffer(@Tx_Buffer,NumBytes);




--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Sending Hex codes over TCP/IP

2020-09-13 Thread James Richters via fpc-pascal
Thanks!  That is exactly what I’ve been trying to figure out.   Just one simple 
unit, not a whole huge package that is so complicated I can’t follow it.   Your 
MODBUS  TCP implementation is very easy for me to follow and to see what’s 
going on.   I wrote my own MODBUS RTU unit, so I’m familiar with the process.  
I don’t need a whole lot of functionality or any of the really advanced things 
that could be done with MODBUS, I just want to turn some relays on and off and 
check their status.   This will work perfectly for that.
 
Thank you very much, this will help greatly!
 
James
 
 
From: fpc-pascal  On Behalf Of LacaK 
via fpc-pascal
Sent: Sunday, September 13, 2020 5:56 AM
To: ja...@productionautomation.net; FPC-Pascal users discussions 

Cc: LacaK 
Subject: Re: [fpc-pascal] Sending Hex codes over TCP/IP
 
Dňa Fri, 11 Sep 2020 19:13:38 -0400
James Richters via fpc-pascal napísal:
> What I'm trying to do is control some different ethernet relays. 
> They use
> MODBUS TCP. I'm trying to keep it as simple as possible. I found 
>a modbus
> library for Pascal but it was way over complicated for that I need 
>to do,
> and while it looks like it would do some cool stuff, the one 
>function I
> need wasn't implemented yet.
> 



You can look at my simple MODBUS TCP implementation ... 
http://lacak.users.sourceforge.net/freepascal.html
I think that it is simple/straightforward to understand.
If there is something not implemented yet I can add it ... (I just implemented 
what I needed for my work project)



-Laco.



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


Re: [fpc-pascal] String literals and code page of .pas source file

2020-09-13 Thread LacaK via fpc-pascal
<<< text/html;charset=utf-8: Unrecognized >>>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC for FreeBSD/PowerPC64

2020-09-13 Thread Jonas Maebe via fpc-pascal
On 13/09/2020 10:36, Karoly Balogh (Charlie/SGR) via fpc-pascal wrote:
> See systems/t_linux.pas for an example, and do something similar in the
> PPC64 FreeBSD port.

You should also set the ABI in systems/i_bsd.pas already. The code in
t_linux is because of the support for both big and little endian
PowerPC64 (which FreeBSD also has, so you'll indeed have to do the same
there).


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


Re: [fpc-pascal] Sending Hex codes over TCP/IP

2020-09-13 Thread LacaK via fpc-pascal
Dňa Fri, 11 Sep 2020 19:13:38 -0400 James Richters via fpc-pascal  napísal:> What I'm trying to do is control some different ethernet relays. > They use> MODBUS TCP.   I'm trying to keep it as simple as possible.  I found >a modbus> library for Pascal but it was way over complicated for that I need >to do,> and while it  looks like it would do some cool stuff,  the one >function I> need wasn't implemented yet.> You can look at my simple MODBUS TCP implementation ... http://lacak.users.sourceforge.net/freepascal.htmlI think that it is simple/straightforward to understand.If there is something not implemented yet I can add it
  ... (I just implemented what I needed for my work project)-Laco.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC for FreeBSD/PowerPC64

2020-09-13 Thread Karoly Balogh (Charlie/SGR) via fpc-pascal
Hi,

On Sat, 12 Sep 2020, Curtis Hamilton via fpc-pascal wrote:

> I'm attempting to port FPC to Freebsd/PowerPC64  and need some help. 
>
> I've added initial code to get started.  However, when trying to cross 
> compile I'm getting an internal error message when the newly
> created cross compiler (ppcrossppc64) executes.
>
> /root/Downloads/fpc-3.2.0/compiler/ppcrossppc64 -Ur -Ppowerpc64 
> -XPpowerpc64-unknown-freebsd11.2- -Xr -XX -CX -Ur -Xs -O2 -n -Fi../inc
> -Fi../powerpc64 -Fi../unix -Fi../bsd -Fi../bsd/powerpc64 
> -Fi../freebsd/powerpc64 -FE.
> -FU/root/Downloads/fpc-3.2.0/rtl/units/powerpc64-freebsd -dpowerpc64 
> -dRELEASE -CaDEFAULT  -Us -Sg ../bsd/system.pp
> sysos.inc(69,12) Fatal: Internal error 2015021001
> Fatal: Compilation aborted
>
> Can someone help me decipher this? I've attached the fpc debug file, if that 
> will help.

You can just search the source for that IE number as string. It will
reveal, that you failed to specify a default ABI for the target system.
This error seems to be PPC64 specific.

See systems/t_linux.pas for an example, and do something similar in the
PPC64 FreeBSD port.

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