Hi, I’m trying to send a simple on/off command to Arduino, but the thing is, the serial port setup takes exactly 1561ms (so I had to add a delay of 1561 prior to sending the command)
The question is, can I get one Processing exe to open the port, while the other to just send the command without setup? So that the serial port setup happens just once and then stays open
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
void setup()
{
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
}
void draw()
{
println(myPort.readStringUntil('\n'));
delay (1561);
myPort.write ("off\n");
exit();
}
I don’t think it would be any good to start another exe beforehand, mainly because it is pretty difficult. If you just want to send a signal to the arduino, just send the signal by pressing a key, instead of having it send once the sketch opens. Like :
void keyPressed(){
if (millis() > 1561) //you can probably remove this, unless you really don't want input before
myPort.write("off\n");
}
Yes, your suggestion is possible, but is not applicable in my project.
See, I’m trying to use this command via VoiceAttack, which can execute an inline function (via C# or VB .net) or execute an exe. This processing program is just my prototype for my future project, which would be impossible to do via keystrokes, as I want to do it in the background and I want the full keyboard to still be available.
Well, the keyPressed was just a way to give input. You just need to execute the function in processing.
Edit:
Just change the method from keyPressed to myInput and execute it from outside.
Here’s a link to see how to use command line with C# :
I’ll look for a specific line to call in the cmd to exec a method in a running processing sketch.
And here’s the cmd text to start the sketch and a link to a more detailled introduction:
processing-java --sketch=%cd% --output=%cd%/output" --force --run http://www.dsfcode.com/using-processing-via-the-command-line/
One method would be to host a network server that opens the serial port and waits for commands from a client.
Take a look at Libraries/Network/ChatServer example (included with Processing) and the HTTPClient example.
To see a simple message being sent, modify the HTTPClient line 24 from:
c = new Client(this, "www.ucla.edu", 80); // Connect to server on port 80
To this:
c = new Client(this, "127.0.0.1", 10002); // Connect to local server on port 10002
With a network interface, you are not restricted on your client side (command line, java, python, web browser, etc.)