How to share file descriptor between scripts - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: How to share file descriptor between scripts (/showthread.php?tid=248) |
How to share file descriptor between scripts - 4poker - 10.03.2016 Hi All, I have to open file descriptor once at system init and share it between all scripts. But the following approach doesn't work because this type of data looks like not supported by storage. How to get it working? Thanks init script: local mb = luamodbus.rtu() mb:open('/dev/RS485-1', 38400, 'N', 8, 1, 'H') mb:connect() storage.set('f_mb_rtu_1', mb) resident script: local mb = storage.get('f_mb_rtu_1') mbetslave(6) mb:writebits(0, true) -- but result is nil due to wrong mb RE: How to share file descriptor between scripts - gjniewenhuijse - 11.03.2016 use something like this in a resident script Code: if not start then RE: How to share file descriptor between scripts - admin - 11.03.2016 Each script is a separate OS process. File descriptors are private for each process and cannot be shared. Can you explain your task? Are you trying to share access to the same RS-485 port between several scripts? You can use semaphores (http://openrb.com/docs/semaphore.htm) for locking or just create a profile and use modbus mapper which will take care of data exchange. RE: How to share file descriptor between scripts - 4poker - 11.03.2016 Yes, I meant sharing access to the same RS-485 port between several scripts. Currently it's done as you wrote. Opening/closing the same file every time the script run seems to be excessively, but if there is no ability to open file once from the init process and them share descriptor to the all childs, question is eliminated Thank you for answer! RE: How to share file descriptor between scripts - admin - 11.03.2016 Performance hit for every open/close is minimal. The only problem you might have is when several scripts are trying to access the bus at once. Another solution is to have a single resident script with bus access and other scripts communicating with the resident internally. I'll post our modbus proxy example later on. |