String args = instruction.substring(arg_comma_index + 1, instruction.//**************************************************************** //* Name : Serial Mag Swipe Reader Demo * //* Author : Robert Joseph Korn * //* Notice : Copyright (c) 2015 Open Valley Consulting Corp * //* Date : 12/14/15 * //* Version : 1. How do I configure the serial port settings like speed, parity even/odd Stack Exchange Network Stack Exchange network consists of 178 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Try to put the full code ( with the loop) given by Majenko at the end of your loop() function.
If you want to catch \n, use readStringUntil('\n') instead ( ). I suspect this function not acting as read() to decrease the number returned by available() Note that readString() doesn't take any parameter ( ). If there is nothing to read, port->available() may return -1 error code after 1 sec, but you already checked, isn't it ? Anyway, you should check if it returns something > 0 instead of something != 0. How do you send your commands, char by char or one shot ?
Then you don't need to discard incoming data (empty the serial buffer), which seems to me to be a bad idea anyway. In my example code you would do whatever-it-is you want in process_data which is called once an entire line arrives. do other stuff here like testing digital input (button presses).
terminator reached! process input_line here.
What I tried but didnt work: Restarting many times, installing a dodgy Chinese USB driver called CH34x, then removing it, restarting several times again, installing FTDI driver, restarting, removing it.
I did not update anything whatsoever since it last worked. Void processIncomingByte (const byte inByte) The Arduino IDE cant see the USB Serial port. (but you could compare it to some value, convert to an integer, etc.) here to process incoming serial data after a terminator received Example code that uses a newline delimiter: // how much serial data we expect before a newline You are much better off doing a non-blocking loop, and then processing data when you get a known delimiter, like a newline or comma, or whatever you designate as "ending the stream". It will also introduce a one-second delay while it sits around waiting for that second to elapse. readString keeps reading until it times out (by default after one second), so it may read more - or less even - than you want. In fact I wouldn't be using the String class at all. Checking peek(), available(), and readString() - after I send it one instruction, they return the same values every single time they loop.Setting cmd = "" at the end of each void loop().Flushing the port at the top and/or bottom of each void loop().I'm seeing 20-75 loops after less than 15 minutes of uptime.Ĭlearly the loops where no instruction is being received are still building up something here. If I leave the device running (even if not operating it), the number of times it loops goes up when I finally do send it an instruction.The third time, it loops more times still.The second time, it works but loops anywhere from 1-5 times.The first time, immediately after starting the sketch, it works.Port->read() // Try to throw away whatever's left to prevent looping (which is still happening). String args = instruction.substring(arg_comma_index + 1, instruction.length() + 1 ) String func = instruction.substring(0, arg_comma_index)
I have a Yun that accepts commands via the bridge (note the below code is part of a very simple virtual keyboard that accepts commands then runs Keyboard.println on them: #include Īrg_comma_index = instruction.indexOf(",")