Just a running page with the definition of the IO base class for Arduino.
My original name for the class was SerialComm. The second iteration was SerialBase.
available() - is there data available for reading/peeking?peek() - peek at first byte in input bufferpeek()?read() - read 1 byte from input bufferread()?write() - write 1 byte to output bufferwrite()?flush() - flush data from output buffer?flush() for input buffer can be done as follows:while (read() > 0);
(You can download the file by clicking on the file name at the top)
/* ???.h - Abstract Base Class for Arduino IO. Inherits Print base class to enable print and println functionality. Written by Brett Hagman bhagman@roguerobotics.com http://www.roguerobotics.com/ This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. *************************************************/ #ifndef _xxxBase_h #define _xxxBase_h #include <stdint.h> #include <Print.h> /************************************************* * Class Definition *************************************************/ class xxxBase : public Print { public: // available: returns number of bytes available for reading // 0 if no bytes virtual uint8_t available(void) = 0; // peek: returns the byte waiting at the front of the queue // -1 if no bytes/error virtual int peek(void) = 0; // peek (overload): peeks a block of data, if available // -1 if no bytes/error, or <= count for the number of bytes peeked virtual int peek(char *buf, int count) = 0; // read: returns 1 byte if available // -1 if no bytes/error virtual int read(void) = 0; // read (overload): reads a block of data, if available // -1 if no bytes/error, or <= count for the number of bytes read virtual int read(char *buf, int count) = 0; // write: sends a single byte // NOTE: this is also needed for the Print class virtual void write(uint8_t) = 0; // write (overload): sends a block of data virtual void write(const char *buf, int count) = 0; // flush: clears any bytes that may be in the output buffer virtual void flush(void) = 0; }; #endif
Discussion
Если не трудно ответьте пожалуйста на вопрос. В данной программеpublic class VarArgs { public saittc void vaTest (int v) { System.out.print( Количество аргументов: + v.length+ Содержимое: ); for (int x:v) System.out.print(x+ ; ); System.out.println(); } public saittc void main (String args []) { vaTest();При вызове метода vaTest с отсутствующим параметром компилятор не ругается. Но в следующей программе в строке vaTest (); выдает ошибку: reference to vaTest is ambiguous, both method vaTest(int ) in Array. Почему он так поступает не могу понять .public class VarArgs3 { saittc void vaTest (int v){ System.out.print( Кол-во агрументов: +v.length+ ); for (int x:v) System.out.print(x+ ); System.out.println(); } saittc void vaTest (boolean v){ System.out.print( Кол-во агрументов: +v.length+ ); for (boolean x:v) System.out.print(x+ ); System.out.println();} saittc void vaTest (String msg, int v){ System.out.print(msg+ Кол-во агрументов: +v.length+ ); for (int x:v) System.out.print(x+ ); System.out.println();} public saittc void main (String args []){ vaTest ( Кря-кря , 2, 70, 0); vaTest (true,false,true); vaTest (); }}