0

Is there any reason why is my /dev/cu port always busy? How can I fix that?

It happened on both Uno clone and Spark Core.

The problem is, I'm having issues doing serial communication. Where (as a programmer) I'm seeing something like dropped packets with /dev/tty port. I did a quick test running it on Win 7 (a loaner PC), it works fine...

The code for now is extremely simple. It waits for a command, and write a response.

String str = String(30);

void setup()
{
    Serial.begin(9600);
    str = "";
}

void loop()
{
    if (Serial.available() > 0) {
        char inChar = Serial.read();
        if ((inChar == '\n') || (inChar == '\r') || (inChar == 'z')) {
            str.trim();
            if(str == "READ") {
                String x = String(random(27, 45)) + "," + String(random(45, 300)) + "," + String(random(35, 250));
                Serial.println(x);
            }
            str = "";
        }
        else {
            if (str.length() < 30) {
                str += inChar;
            }
            else {
                str = "";
                str += inChar;
            }
        }
    }
}
2
  • I always use the tty one, and not the cu on my mac.
    – Gerben
    Feb 23 '15 at 13:48
  • Yeah, me too. But so far, I've only need to upload sketches. Never really thought nor care about tty or cu.
    – marko
    Feb 23 '15 at 16:46
0

Finally figured it out. I need to call Serial.flush().

Waits for the transmission of outgoing serial data to complete.

1
  • Serial.flush() is not my solution. anyone with any new information on this?
    – user27974
    Nov 5 '16 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.