Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUA Serial Communication #2127

Open
DansDesigns opened this issue Jul 1, 2024 · 3 comments
Open

LUA Serial Communication #2127

DansDesigns opened this issue Jul 1, 2024 · 3 comments

Comments

@DansDesigns
Copy link

DansDesigns commented Jul 1, 2024

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
Copy link
Owner

daid commented Jul 1, 2024

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
Copy link
Author

DansDesigns commented Jul 1, 2024

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
Copy link
Author

DansDesigns commented Jul 1, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants