I'm trying to modify this excellent library
http://husks.wordpress.com/2011/05/23/a-minimal-arduino-library-for-processing-serial-commands/ for processing serial commands to work with software serial port. I modified .h and .cpp files, so here is a beginning of NSSerialCommand.h file (modified library)
#ifndef NSSerialCommand_h
#define NSSerialCommand_h
#include "WProgram.h"
#include <string.h>
#include <..\NewSoftSerial\NewSoftSerial.h>
class NSSerialCommand
{
public:
NSSerialCommand(); // Constructor
void clearBuffer(); // Sets the command buffer to all '\0' (nulls)
char *next(); // returns pointer to next token found in command buffer (for getting arguments to commands)
void readNSSerial(); // Main entry point.
void addCommand(char *, void(*)()); // Add commands to processing dictionary
void addDefaultHandler(void (*function)()); // A handler to call when no valid command received.
private: ...
In NSSerialCommand.cpp I wrote:
#include "WProgram.h"
#include <string.h>
#include <..\NewSoftSerial\NewSoftSerial.h>
#include "NSSerialCommand.h"
NewSoftSerial NSSerial(2, 3);
void NSSerialCommand::readNSSerial()
{
while (NSSerial.available() > 0)
{
int i;
boolean matched;
inChar=NSSerial.read(); // Read single available character, there may be more waiting
...
Main sketch:
#include <NewSoftSerial.h>
#include <NSSerialCommand.h>
NewSoftSerial NSSerial(2, 3); // 2-Rx, 3-Tx
NSSerialCommand SCmd; // The SerialCommand object
void setup()
{
NSSerial.begin(57600);//Start talking with PC
// Setup callbacks for SerialCommand commands
SCmd.addCommand("vel",process_velocity); // Converts two arguments to integers and echos them back
SCmd.addDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?")
NSSerial.println("Ready");
}
void loop()
{
SCmd.readNSSerial(); // We don't do much, just process serial commands
}
The problem that i get an error:
"NSSerialCommand\NSSerialCommand.cpp.o: In function `NSSerialCommand::clearBuffer()':
D:\Development\arduino-0022\arduino-0022\libraries\NSSerialCommand/NSSerialCommand.cpp:45: multiple definition of `NSSerial'
NSS_commands.cpp.o:(.bss.NSSerial+0x0): first defined here"
And it's quit obvious that here is multiple definition of `NSSerial'. But if I try to define SoftSerial port once in a main sketch, i got definition errors in library.cpp and if I try to define port in library.cpp the main sketch don't "see" definition. I'm not familiar with C programming, so I appreciate any help.
Thanks in advance.