Demonstrates the use of a robot packet handler to recieve data from a device attached to the robot microcontroller's auxilliary serial port.This example shows how to use the GETAUX command and how to recieve SERAUX serial port data.
To use this example, you must have the auxilliary serial port AUX1 on the microcontroller (inside the robot) connected to a device that is sending text data.
You can connect AUX1 to a computer through an RS-232 cable with a NULL modem adapter, and run a program such as minicom (Linux) or HyperTerminal (Windows). Then just type to send data to the AUX1 port. Configure minicom or HyperTerminal to have the following serial port settings: 9600 baud 8 data bits, 1 stop bit, no parity No flow control (not hardware, not software)!
This program creates a packet handler function (getAuxPrinter) and adds it to the ArRobot object. All packets recieved from the robot are passed to all packet handlers. getAuxPrinter() checks whether the packet is an SERAUX packet, and if so, prints out the data contained within the packet. If a newline or carriage return character is recieved, then it sends a command to send data back out through the AUX serial port. The packet handler then sends a GETAUX command to the robot to request more data.
#include "Aria.h"
{
char c;
if (packet->
getID() != 0xb0)
return false;
{
if (c == '\r' || c == '\n')
{
putchar('\n');
}
else
putchar(c);
fflush(stdout);
}
return true;
}
int main(int argc, char **argv)
{
argParser.loadDefaultArguments();
{
return 1;
}
if(!conn.connectRobot(robot))
{
return 2;
}
ArLog::log(
ArLog::Normal,
"getAuxExample: Connected to the robot. Sending command to change AUX1 baud rate to 9600...");
return 0;
}
virtual ArTypes::UByte bufToUByte(void)
Gets a ArTypes::UByte from the buffer.
Definition: ArBasePacket.cpp:490
virtual ArTypes::UByte2 getReadLength(void) const
Gets how far into the packet that has been read.
Definition: ArBasePacket.h:170
Use terse logging.
Definition: ArLog.h:61
ArTypes::UByte getID(void)
returns the ID of the packet
Definition: ArRobotPacket.cpp:81
Legacy connector for robot and laser.
Definition: ArSimpleConnector.h:51
bool comInt(unsigned char command, short int argument)
Sends a command to the robot with an int for argument.
Definition: ArRobot.cpp:5634
int, set baud rate for Aux1 - 0=9600, 1=19200, 2=38400, 3=57600, 4=115200
Definition: ArCommands.h:85
void addPacketHandler(ArRetFunctor1< bool, ArRobotPacket * > *functor, ArListPos::Pos position=ArListPos::LAST)
Adds a packet handler to the list of packet handlers.
Definition: ArRobot.cpp:2613
int, requests 1-200 bytes from aux1 serial channel, 0 flush
Definition: ArCommands.h:77
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
static void log(LogLevel level, const char *str,...)
Log a message, with formatting and variable number of arguments.
Definition: ArLog.cpp:93
static void init(SigHandleMethod method=SIGHANDLE_THREAD, bool initSockets=true, bool sigHandleExitNotShutdown=true)
Initialize Aria global data struture and perform OS-specific initialization, including adding OS sign...
Definition: Aria.cpp:128
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
Parse and store program command-line arguments for use by other ARIA classes.
Definition: ArArgumentParser.h:64
static void logOptions(void)
Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())
Definition: Aria.cpp:794
bool comStr(unsigned char command, const char *argument)
Sends a command to the robot with a length-prefixed string for argument.
Definition: ArRobot.cpp:5662
string, send string argument to serial dev connected to aux1
Definition: ArCommands.h:76
static bool parseArgs(void)
Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())
Definition: Aria.cpp:759
Use normal logging.
Definition: ArLog.h:62
virtual ArTypes::UByte2 getLength(void) const
Gets the total length of the packet.
Definition: ArBasePacket.h:165
place item first in the list
Definition: ariaTypedefs.h:70
void run(bool stopRunIfNotConnected, bool runNonThreaded=false)
Starts the instance to do processing in this thread.
Definition: ArRobot.cpp:255
Functor for a global function with 1 parameter and return value.
Definition: ArFunctor.h:1270
Represents the packets sent to the robot as well as those received from it.
Definition: ArRobotPacket.h:41