Page 1 of 1

Data transfer between 3 PB programs ...

Posted: Wed Aug 28, 2024 8:43 am
by marc_256
Hello (again),


My PLC <-> RS485 <-> 3D virtual simulator becomes to big as a program to control/debug.
So, I decided to split my program in to 3 separated programs.


- 1 = Simulation on PC:
The 3D simulator follows the PLC program,
I need to transfer data from PLC program to the 3D program.
Data can be Strings, and bytes, words, longs.


- 2 = Real world to PC via RS485:
The PC receives data from Sub PC's / MPU's boards via my RS485 terminal program.
The Terminal program need to send data to the PC 3D simulator.


Q)
What is the best/simplest/fast way to transfer/synchronize data between these three programs on the PC level between all PB programs ?
- Receive data from RC485 terminal program.
- Send data from PLC program to 3D simulator program.
- Answer/confirmation from 3D to PLC program.


PS: the simulator PC is connected as a slave and not as master in the RS485 bus.


I use Win10_pro and PB5.73 x64


Thanks,
marc

Re: Data transfer between 3 PB programs ...

Posted: Wed Aug 28, 2024 11:02 am
by NicTheQuick
The easiest cross-platform way would be a local network connection. Create a network server in one application that listens on localhost and a custom port, then let the other applications connect to it and transfer data between them. You just have to think about a communication protocol to be used.

Re: Data transfer between 3 PB programs ...

Posted: Wed Aug 28, 2024 11:21 am
by RASHAD
You can use RAMDISK to store and retrieve Data at any time

Re: Data transfer between 3 PB programs ...

Posted: Wed Aug 28, 2024 5:27 pm
by Caronte3D
If only for Windows, you can use messages WM_COPYDATA, it's easy and fast.
Also you can use "Named Pipes"

Re: Data transfer between 3 PB programs ...

Posted: Wed Aug 28, 2024 5:48 pm
by skywalk
SQLite supports shared memory DB's.
This way you can save to disk(periodically) and keep logs,etc. and still maintain memory disk speeds.
Create a schema that supports your 3 program communication protocol.
Then use standard SQL query read/writes.

Re: Data transfer between 3 PB programs ...

Posted: Wed Aug 28, 2024 8:29 pm
by marc_256
Hi everyone,

Thanks for your ideas ...
But sorry, for me (old guy), its all like chinees for me.


Maybe I forgot to say that the frequency of data transfer is high.
For example, I need refresh rates for the PLC and 3D simulator.


-------------------------------------------------------------------------------------------------------------------------------------------------------------------
- So, I had have an other idea. (I don't know it will work) :?
But, I already use the RS485 BUS as a communication channel between the different (Teensy 3.2 / 4.0 / 4.1) controller modules.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
- This is totally out of my comfort zone ... :mrgreen:
What I want to try is the follow:

- I just ordered a USB-A port module (1xUSB-A to PC <--> 4x USB-A Ports)
And I bought 3x USB-A to RS485 converter.
So, there is a way to communicate via the RS485 BUS on a different COM port.

The advantages are, that I can run one of my programs on a separated MINI PC / Raspberry PI.


Q)
Is it possible to use different COM port in 3 Different PB programs at the same time ?


PC OS = Win 10 pro x64
PB = 5.73 x64



Greatings,
Marc

Re: Data transfer between 3 PB programs ...

Posted: Wed Aug 28, 2024 8:39 pm
by skywalk
Ok, a hardware approach using RS485 does allow multiple devices on 1 com port. Each device has a different
"address". Your speed is limited by the baud rate and parsing of each device. LAN devices can handle even higher data rates. Usually, serial port devices are connected for low speed/low byte counts communication. Not video refresh rates.

Re: Data transfer between 3 PB programs ...

Posted: Thu Aug 29, 2024 6:49 am
by PBJim
There's quite a good thread suggesting UDP as a means of communication between processes, which is also advocated by Infratec in one or two posts. Setting it up is easy, especially since it's connectionless.

https://www.purebasic.fr/english/viewto ... 88#p220188
https://www.purebasic.fr/english/viewto ... 40#p590440
UDP cause of the simplicity and on a LAN you will not loose packets.
TCP has a lot of overhead. If you want transmit one packet, many others are nedeed for handshakes.
The CPU load is less, the transfer is faster, you don't need to handle connect and disconnect ...

Re: Data transfer between 3 PB programs ...

Posted: Thu Aug 29, 2024 8:25 am
by dige
I would also have suggested pipes, but the idea of using SQLite as an in-memory database to exchange data between several programmes is really great!
I hadn't even thought of that idea yet. It saves an enormous amount of programming in terms of data handling and synchronisation.
Thank you Skywalk for this suggestion!

Re: Data transfer between 3 PB programs ...

Posted: Thu Aug 29, 2024 10:08 am
by mk-soft
How to open SQLite shared memory with PB OpenDatabase?

Re: Data transfer between 3 PB programs ...

Posted: Thu Aug 29, 2024 10:29 am
by SMaag
Think about a Modus connection! That's a industrial standard way of communication betwwen a 'PLC' and something else!
I'm working on a new Modbus implementaiton for Purebasic. Once more I guess we need the same tings!

There is a Modbus implementation for Pruebasic in the Tips and Tricks forum. But it is only a Modbus Master.
But for communication in 2 way we need a Master and a slave implementation.

A ready solution for a professional Modbus is the free library libmodbus. The problem for me with libmodus is:
it is written in C and you have to build a lib with Visual Studio C. I tried the coumminty version of Visual Stuido.
But for me it is impossible to build the libmodbus.
The next problem is: You have to create a complete dll import for Purebasic. If you are able to do the build of libmodbus
let's do!

Or if yout want to be part of the Modbus for PB implementation please tell me. Then I can provide you my very early code.
It's complete from scratch in a 'industrial way!

Re: Data transfer between 3 PB programs ...

Posted: Thu Aug 29, 2024 10:54 am
by mk-soft
If you can program a Modbus Master (TCP/IP Client) in PureBasic, it should be no problem to write a Modbus Slave (TCP/IP Server).
Everything has been done before and has been running for years.

Re: Data transfer between 3 PB programs ...

Posted: Thu Aug 29, 2024 10:59 am
by DarkDragon
mk-soft wrote: Thu Aug 29, 2024 10:08 am How to open SQLite shared memory with PB OpenDatabase?
https://www.sqlite.org/draft/inmemorydb.html
https://stackoverflow.com/a/15720872

It's only possible within one process to have a shared cache. Or use a physical file but on a ramdisk.

Re: Data transfer between 3 PB programs ...

Posted: Fri Aug 30, 2024 1:28 pm
by marc_256
Hi,

Sorry for the late response,
I'm working on my development/prototype of my hardware for the RS485 Control modules.

Thanks again for all the ideas and help ...

I gone try to build the [MASTER] and [SLAVE] in one PC.
[MASTER] will be the PB5.73x64 / PLC program.
[SLAVE 01] the 3D simulation program.

- For the people who are interested,
I will start a post about the hardware in the [Off Topic] section.
As this is not PB related.
See https://www.purebasic.fr/english/viewtopic.php?t=85229


Thanks,
Marc,

@SMaag,
Yes, one of us is copying the other. :mrgreen: