LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

python shared memory object

Solved!
Go to solution
Solution
Accepted by hallo77

Which is right back to my server/client suggestion. Since your Python application is the source of the data I would make that the server. I haven't really played around with creating asynchronous tasks in Python but I know it is possible. A basic TCP client in LabVIEW is very easy. If you don't use JSON for the data I would create a simple message header which would consist of Message Type, Data Length and Data. This allows you to add new messages easily if needed. The other solution would to have the Python application broadcast a UDP packet. Again use the basic message header or JSON. This way the application just broadcasts it and any number of applications can listen for the UDP. This will generally be limited to a single subnet since most switches will block UDP broadcast packets from being routed over different subnets. The nice thing about either of these approaches in that your application could have multiple UIs active at one time and also be on different machines.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 11 of 24
(1,094 Views)
Solution
Accepted by hallo77

Shared memory is a system feature, also under Windows, implemented by the kernel. And the Python shared memory object simply is a means to access that functionality. Since it is a Windows API feature, there would be a way to access it in LabVIEW too, and there have been some libraries in the past that tried to do that. But shared memory is a tricky beast, the API can be taunting to interface too and there can many things go wrong before it works, so if you can find other options, such as network communications, you will yourself spare a lot of pain and trouble by using them and leaving the shared memory for the low level programmers who want to show off or have some really fancy high speed data transfer requirements between one or more processes.

 

As a little tidbit: if you use TCP/IP with localhost as address on both sides, the Windows socket library will actually use shared memory to connect the endpoints together rather than routing the data through the network adapter drivers down and back up.

Rolf Kalbermatter
My Blog
Message 12 of 24
(1,078 Views)

thanks for your reply!

0 Kudos
Message 13 of 24
(1,069 Views)

Thank you! I could have a try.

0 Kudos
Message 14 of 24
(1,068 Views)

Thank you for your reply.But Python will be accepted later. In other words, the labview human-computer interaction interface sends commands or data to Python, and then Python sends it to the next computer for execution. This is equivalent to Python and labview both having to be servers and clients. What can be done about it?

0 Kudos
Message 15 of 24
(1,063 Views)

Shared memory works not across computers (at least not without very special and expensive special purpose hardware). So if you want to do this between computers and not just on a single computer, you will have to find an IAC method that can go through the network! Anyone saying TCP/IP (or UDP) here?

Rolf Kalbermatter
My Blog
Message 16 of 24
(1,059 Views)

Thank you very much for your reply! I get it. Using shared memory can be a hassle. There will be many problems, I will try using TCP/IP now.

0 Kudos
Message 17 of 24
(1,054 Views)

Also, it sounds like Python and labview can be implemented with shared memory. Could you please tell me how to achieve it in labview? Do you need to use shared variables? But how do you set it up? My attempts to interact with shared variable objects in Python still didn't quite work. Thank you very much indeed!

0 Kudos
Message 18 of 24
(1,052 Views)
Solution
Accepted by hallo77

@hallo77 wrote:

Also, it sounds like Python and labview can be implemented with shared memory. Could you please tell me how to achieve it in labview? Do you need to use shared variables? But how do you set it up? My attempts to interact with shared variable objects in Python still didn't quite work. Thank you very much indeed!


No shared variables have nothing to do with Windows shared memory. To do it in LabVIEW you would need to call the Windows API functions CreateFileMapping or OpenFileMapping followed by MapViewOfFile and then direct pointer access to the created map pointer and eventually UnmapViewOfFile and CloseHandle.

 

But unless you have quite a bit experience in C programming, I would not really recommend you to try to do that.

Rolf Kalbermatter
My Blog
Message 19 of 24
(995 Views)

Thank you so much for your generosity in answering my questions. It does seem complicated, and it would take a long time to study it. I'll consider other options now. But this idea, if there is more time and energy in the future, I still want to have a try to break through myself. Thank you very much for your reply!

0 Kudos
Message 20 of 24
(989 Views)