We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have been using this code below in my sketch, but it causes processing to stop when it is combined with serial communication to an arduino... The serial part of my sketch works fine as long as I remove all of the code below... if I leave it in, it will error out about 4 out of 5 times... then work fine until I run it again... Is there a chance that I am not setting up the robot class correctly or that the serial class is wrong but somehow works because robot isnt there???
import java.awt.Robot;
import java.awt.AWTException;
Robot robby;
void setup()
{
//robot setup
try
{
robby = new Robot();
}
catch (AWTException e)
{
println("Robot class not supported by your system!");
exit();
}
robby.mouseMove(screenResX/2, screenResY/2); //test line to move cursor
}
Answers
the error I get from processing is: **Error, disabling serialEvent() for COM17 null ** The program does not shut down, but just hangs and doesnt receive serial data the mouse does move to the spot on the screen in setup() and stays there until I escape out of the sketch...
There's no serialEvent() in your posted code. /:)
Besides, it's not even compilable either! :-@
Sorry, here is the rest of it:
https://forum.Processing.org/two/discussion/16618/processing-with-arduino-void-serialevent#Item_1
Apologies, Its been years since I post on the boards and will do much better next time.... the sketch is quite large so I deleted the parts that simply compute numbers and execute mouse moves GUIs, etc... I did find that the error occurs when I incorporate the robot class... even without the rest of the code that executes robot commands.... If I remove anything related to robot, it has yet to fail... as soon as I uncomment the robot class I start getting the null error and closes my com port...
Here is the compilable processing code as well as my full arduino sketch the only error you will get is because of the missing config file... the text file just includes the line COM17
Processing:
Arduino:
I will try the example that you provided a link too... It would be extremely helpful to at least get an basic understanding of what is the root of my error in the sketch as it stands... the error message is very vague and my google searches haven't come up with a cause yet... I really appreciate the help and apologize for my incomplete initial post...
I tried your code in place of my old serial method I now get this error instead:
null pointer exception [0] "COM17" null
looks like adding a 1 second delay in the setup function of processing solved the null issue... Your code is so much simpler and efficient for serial.. Thank you for that!
It takes some time before serialEvent() is called back for the 1st time.
Given it's an asynchronous call, if you got anything which depends on serialEvent() to initialize it before usage, it may break your code if it happens before serialEvent() is executed.
However, it's unreliable to depend on some arbitrary delay() millisecond value to w8 for 1st serialEvent() execution.
In your current computer, 1 millisecond was enough. For another, it may need more or none at all.
Rather, at the end of setup(), you can add an infinite loop + delay(), which checks whether the problematic value was properly initialized within serialEvent().
Let's say you depend on pitch to be something else besides
0
:while (pitch == 0) delay(5);
So that statement in setup() is gonna halt the 1st execution of draw() until variable pitch got its proper initialization inside the 1st execution of serialEvent().
Just an extra forum trip: Replace all
/*
w//**
in order to avoid the whole green post glitch. L-)