IO Base Class

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.

Necessities

  • Inherit from Print class?
    • more than likely all ABC inheriting classes will require the Print class.
    • it's not necessary, but quite useful.
  • Virtual functions (must be implemented by inheriting class):
    • available() - is there data available for reading/peeking?
    • peek() - peek at first byte in input buffer
      • should we have a block peek()?
    • read() - read 1 byte from input buffer
      • should we have a block read()?
    • write() - write 1 byte to output buffer
      • block write()?
    • flush() - flush data from output buffer?
      • flush() for input buffer can be done as follows:
        while (read() > 0);

The Class

(You can download the file by clicking on the file name at the top)

UnamedBaseClass.h
/* ???.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

test188.143.232.12, 2012/06/26 20:12

Если не трудно ответьте пожалуйста на вопрос. В данной программе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 (); }}

You could leave a comment if you were logged in.
  • Bookmark at
  • Bookmark "IO Base Class" at del.icio.us
  • Bookmark "IO Base Class" at Digg
  • Bookmark "IO Base Class" at Google
  • Bookmark "IO Base Class" at StumbleUpon
  • Bookmark "IO Base Class" at Technorati
  • Bookmark "IO Base Class" at Facebook
  • Bookmark "IO Base Class" at Twitter
  • Bookmark "IO Base Class" at Slashdot
  • Bookmark "IO Base Class" at Yahoo! Bookmarks
  • Bookmark "IO Base Class" at Furl
  • Bookmark "IO Base Class" at Reddit
  • Bookmark "IO Base Class" at Ask
  • Bookmark "IO Base Class" at BlinkList
  • Bookmark "IO Base Class" at blogmarks
  • Bookmark "IO Base Class" at Ma.gnolia
  • Bookmark "IO Base Class" at Netscape
  • Bookmark "IO Base Class" at ppnow
  • Bookmark "IO Base Class" at Rojo
  • Bookmark "IO Base Class" at Shadows
  • Bookmark "IO Base Class" at Simpy
  • Bookmark "IO Base Class" at Socializer
  • Bookmark "IO Base Class" at Spurl
  • Bookmark "IO Base Class" at Tailrank
  • Bookmark "IO Base Class" at Live Bookmarks
  • Bookmark "IO Base Class" at Wists
  • Bookmark "IO Base Class" at Yahoo! Myweb
  • Bookmark "IO Base Class" at BobrDobr
  • Bookmark "IO Base Class" at Memori
  • Bookmark "IO Base Class" at Faves
  • Bookmark "IO Base Class" at Favorites
  • Bookmark "IO Base Class" at Newsvine
  • Bookmark "IO Base Class" at myAOL
  • Bookmark "IO Base Class" at Fark
  • Bookmark "IO Base Class" at RawSugar
  • Bookmark "IO Base Class" at LinkaGoGo
  • Bookmark "IO Base Class" at Mister Wong
  • Bookmark "IO Base Class" at Wink
  • Bookmark "IO Base Class" at BackFlip
  • Bookmark "IO Base Class" at Diigo
  • Bookmark "IO Base Class" at Segnalo
  • Bookmark "IO Base Class" at Netvouz
  • Bookmark "IO Base Class" at DropJack
  • Bookmark "IO Base Class" at Feed Me Links
  • Bookmark "IO Base Class" at funP
  • Bookmark "IO Base Class" at HEMiDEMi
code/arduino/io_base_class.txt · Last modified: 2010/05/26 01:08 by bhagman
Valid CSS Recent changes RSS feed Valid XHTML 1.0