Recent

Author Topic: Bidirectional SimpleIPCs  (Read 1507 times)

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 396
Bidirectional SimpleIPCs
« on: July 19, 2022, 07:32:36 pm »
I have two instruments, A and B, each controlled by its own Lazarus program.  From time to time, instrument A needs to request the latest measurement taken by instrument B.  The requests occur asynchronously, and speed isn't an issue.

I know I can do this by putting a SimpleIPC server and client in each program, but wonder if there is a better way to accomplish this bidirectional communication?   

Suggestions appreciated.   I just have the feeling that there may be a better way. 

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Bidirectional SimpleIPCs
« Reply #1 on: July 19, 2022, 08:16:13 pm »
Kill two birds with one stone: put the results into a PostgreSQL or Firebird database and use the async notification mechanism both those support to send a message to the other.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

speter

  • Sr. Member
  • ****
  • Posts: 345
Re: Bidirectional SimpleIPCs
« Reply #2 on: July 20, 2022, 05:07:45 am »
It might be simpler to create text (or binary) files to store the info (and maybe a "lock" file); then have the app(s) read &/or write those files.

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Bidirectional SimpleIPCs
« Reply #3 on: July 20, 2022, 11:33:19 pm »
I have a DLL that allows you to share a memory chunk in the DLL using the FS:Segment.

 Not sure if this can be done in 64 bit but it works in 32 bit windows.
The FS register is used by Windows and applications should definitely _not_ be messing with it.

As far as the OP's request for bidirectional communication, a shared memory block is something worth considering (fast and straightforward.)

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Bidirectional SimpleIPCs
« Reply #4 on: July 21, 2022, 06:56:02 am »
Hello! Not sure that this be the better solution, but (as you asked for suggestions) you could use the same mechanism than in this example.

It's a program who starts another program, writes to input and reads output, continuously.

I used that method for a chess GUI. The main application starts an engine (an artificial player) and, after each human player's move, sends the new position to the engine, and reads the engine's move.
« Last Edit: July 21, 2022, 06:59:26 am by Roland57 »
My projects are on Gitlab and on Codeberg.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Bidirectional SimpleIPCs
« Reply #5 on: July 21, 2022, 08:51:56 am »
The compiler allocates a chunk of memory for you, its not something windows is using.

The compiler does not allocate anything there. The FS segment on Windows for 32-bit x86 processors contains Windows' Thread Environment Block and that indirectly handles thread local variables, but on i386-win32 this is also used for exception handling. On Windows  for 64-bit x86 processors the GS segment is used instead and FS is not used.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Bidirectional SimpleIPCs
« Reply #6 on: July 22, 2022, 08:59:44 am »
If anyone is interested I can post the one liner that is needed for the C compiler.

Then show it.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Bidirectional SimpleIPCs
« Reply #7 on: July 22, 2022, 10:18:08 am »
I have a DLL that allows you to share a memory chunk in the DLL using the FS:Segment.

 Not sure if this can be done in 64 bit but it works in 32 bit windows.

 The other problem is FPC cannot compile a workable DLL like this to my knowledge, because I haven't found any doc's where it allows to create a FS segment that is sharable.

 The DLL was built using Builder C++ but it was referenced from a MS compiler example. So if you have one of those you can build this custom DLL to talk between apps directly via memory chunk and a couple of API's you export.
Note FPC already has the sharemem unit (include it in both program and dll). Another option is to use memory mapped files.
Sharemem installs a shared memory manager in the dll('s) and the program. Memory mapped files can even be used between different processes.
 Sharemem is great with an in memory database like TbufDataset or TMemDataset. I prefer TBufDataset in most cases, because it is more flexible than TMemDataset.
« Last Edit: July 22, 2022, 10:24:38 am by Thaddy »
Specialize a type, not a var.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Bidirectional SimpleIPCs
« Reply #8 on: July 22, 2022, 12:56:24 pm »
They name streets after some people 'oneway"

Enjoy it.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018