EmptyEpsilon icon indicating copy to clipboard operation
EmptyEpsilon copied to clipboard

LUA Serial Communication

Open DansDesigns opened this issue 1 year ago • 3 comments

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!

DansDesigns avatar Jul 01 '24 12:07 DansDesigns

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

daid avatar Jul 01 '24 16:07 daid

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 avatar Jul 01 '24 18:07 DansDesigns

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://<SERVER_IPADDRESS>... line?

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

DansDesigns avatar Jul 01 '24 19:07 DansDesigns