solved , thanks for help
QtSerialControl.ino (564 Bytes)
arduinocontrol.cpp (931 Bytes)
but works only if arduino ide's serial monitor is open
This implies a couple of things. One is that you are not using Windows. Another is that your application is not opening the serial port correctly.
Since the code you are using to open the serial port is NOT running on the Arduino, it is not a "Programming the Arduino" question that you have, so this is NOT the correct forum.
What programming language is QT working on? What command are you using to open the serial port on the PC?
It seems very strange that the Qt app doesn't just report an error if the Arduino IDE is already using the serial port.
Have you tried putting debugging code in the Arduino so that you know what it is actually receiving?
...R
if he is not opening correctly why it works when serial monitor is running ?
I should think that is obvious. It works because the Serial Monitor application DOES open the port correctly.
How interesting. I didn't think it was possible for your C code to open the serial port after the Arduino had opened it. So I started a sketch and opened the Arduino Serial Monitor and then opened a puTTY window and the output from my sketch appeared in puTTY and not in the Serial Monitor. When I closed the puTTY window the output showed in the Serial Monitor again. (I assume puTTY is written in C, but I don't know).
My PC programs are written in JRuby which, like the Arduino IDE, uses the Java JVM and I can't open the same serial port twice with that.
I think you will need to add some debugging code to your C program to get it to confirm to you that the serial port has opened correctly.
It may be useful if you post the line(s) of your C program that open the serial port. Somebody might spot the problem.
...R
When the port is opened it causes the Arduino to reset. You have to allow a few seconds, after opening the port, for your program to start up and be able to respond. If pushing the button in your QT app opens the port and immediately sends a char this may be the problem. Hope this helps.
@tf68, good point. I had forgotten that even though it came up on another thread recently.
I usually write my sketches so they send a short message to identify themselves and my PC software waits for this.
For example
void setup() {
Serial.begin(9600);
Serial.println("Starting my program");
// etc etc
}
...R