// Telerobotics Senior Project
// Webbot 1.0 - Robot Control System
// (c) 2000 Bradley University ECE
// ---------------------------------
// bottag.c - Get a status byte from the robot
// Written by: John Kiolbasa
// Command line syntax:
// bottag [-v]
//
// where: -v verbose output
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int sp;
struct termios tios;
int buff;
int i = 0;
int amt;
int val;
buff = 128+32;
sp = open("/dev/ttyS0", O_RDWR|O_NOCTTY);
if(sp == -1)
{
printf("Error opening serial port.\n");
return 1;
}
tcflush(sp, TCIOFLUSH);
write(sp, &buff, 1);
while(!read(sp, &buff, 1)) {}
while(!read(sp, &val, 1)) {}
printf("%c", val);
if(argc > 1 && argv[1][0] == '-' && argv[1][1] == 'v')
{
printf("Command sent: %d\n", buff);
printf("Value returned: %d\n", val);
}
return 0;
}
syntax highlighted by Code2HTML, v. 0.8.11