Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Kio |
OK…
First… I am not a seasoned programmer, I am a hack!
I can get port write() communications working from OS.excecute… cmd.exe to powershell… and a crazy amount of command line code that creates > opens > commands > then closes the port… this WAY TOO SLOW of a process need to keep port open accessible and ready.
Example function works (zzz slowly) with code programmed on arduino:
func _changeArduinoLEDColor(RVal,GVal,BVal):
var RGBstringtoPass = "<" + RVal + "," + GVal + "," + BVal + ">"
var output = []
var arduinoCommand = "$port= new-Object System.IO.Ports.SerialPort COM5,9600,None,8,one;$port.open();$port.WriteLine('" + RGBstringtoPass + "');$port.Close()"
var pid = OS.execute('CMD.exe', ['/C', 'powershell.exe', arduinoCommand], false, output)
After smashing my head against a wall for days… I stumbled onto this…
https://github.com/Superwaitsum/GDSercomm
https://github.com/Superwaitsum/GDSerialAsset
Started to follow all the instructions of compiling Godot from source… I do not need to do this, I have no intend to learn any of the C’s, modify or create my own modules etc… GDScript suits my needs just fine… BUT… is there any quick way to get Superwaitsum’s serial modules working in a Godot version installed from exe?
There is no real direction on GIT and the Godot documentation is sending me in circles with no end in sight.
Any help or insight would be appreciated.
This is a really difficult question. I would suggest you post on github and ask the users of those specific libraries.
Todilo | 2018-09-27 10:19
Just hoping to find another solution. If Godot could simply send a command prompt style ECHO > PORT all would be the simple, at least for sending data. But have yet to find a way for that to work without creating a hack third and fourth party SW link.
Kio | 2018-09-27 23:23
Since it’s a long time this question was asked, I think that an update is welcome.
I’m using Godot 3.3.2 and my conclusion about dealing with serial communication is : use C#
You’ll keep all the cross platform advantage of Godot without writing a single low level line of code, here is a snipped:
using System.IO.Ports;
Then in your class if you want to open the port (assuming “SerialPort port” is defined)
port = new SerialPort(portName, (Int32)baudRate, Parity.None, 8, StopBits.One);
Then use the _Process to read the data (snipped for reading lines):
public override void _Process(float delta)
{
Int32 idx = 0;
if (port != null)
{
if (port.BytesToRead > 0)
{
string serData = port.ReadExisting();
string[] str = serData.Split('\n');
parseLines(str);
}
}
}
Don’t use “DataReceived” event, it doesn’t work (I think it’s a question of code context). But anyway with Godot this function is useless since you can check and parse directly in the _Process function.
Also, for efficiency it’s better to use the ReadExisting() function than the Readline() function.
papyDoctor | 2021-07-19 16:41