daid / EmptyEpsilon

Open source bridge simulator. Build with the SeriousProton engine.
https://daid.github.io/EmptyEpsilon/
GNU General Public License v2.0
551 stars 188 forks source link

LUA Serial Communication #2127

Open DansDesigns opened 4 months ago

DansDesigns commented 4 months ago

Hey all,

I'm trying to design some physical Repairable Ship Components that are basically Arduino's with some kind of sensor combination.

The idea is that within the Mission Script - something causes Shields or Beam Weapons etc to loose power, a Serial message (possibly a single char) is sent to the Arduino that is the "Shield Matrix" or "Beam Weapon Control Conduits". The Arduino then requires fixing - when this is done the Arduino sends another Serial Char that is picked up by the Mission Script and puts Shields/Beams Power back to Full..

I'm having issues getting a Mission Script to successfully send a single Char over Serial.. I have tried the following methods (for Windows) in several places in the Mission Script:

   file = io.open("COM6","wb")

   io.output(file)

   io.write("B")

^ this one seems to allow the Script to load and I can see the Mission Assets in the Game Master screen but does not send anything over Serial (Arduino is configured to light up its built-in LED upon receiving the letter "B")

and

   Arduino_Com_Port = com.open("COM6", 115200, 0)

   com.write(Arduino_Com_Port, "B")

^ this one has issues with the 'Global com not being recognized'

any help would be greatly appreciated Thank you!

daid commented 4 months ago

EE lua scripts are sandboxed, so they cannot access hardware. Currently, the only way to do this would be a 2nd program that talks to the serial port and the EE webserver

DansDesigns commented 4 months ago

ah ok, I already have a python script that I use to translate from an Arduino Nano to keyboard commands (Nano doesn't have USB HID) so i'll see if i can add this functionality to that.. thank you

DansDesigns commented 4 months ago

I have a webserver running and a python script able to send commands and receive ship info (actually working very well!) I would like to understand the set.lua instruction abit more, where would one place the: _OBJECT_=someObjectGetter()

does it go in the http://... line?

I assume the correct way of getting the 2nd player ship would be the following? : _OBJECT_=getPlayerShip(2)