All Classes Namespaces Files Functions Variables Enumerations Enumerator
libs/range_sensor/scip_samples/scip_20_scip.cpp
00001 
00012 #include "SerialDevice.h"
00013 #include "ScipUtils.h"
00014 #include "DetectOS.h"
00015 #include <cstdlib>
00016 #include <cstdio>
00017 
00018 using namespace qrk;
00019 
00020 
00022 int main(int argc, char *argv[])
00023 {
00024   // Change the port name appropriately
00025 #if defined(WINDOWS_OS)
00026   const char device[] = "COM3";
00027 #elif defined(LINUX_OS)
00028   const char device[] = "/dev/ttyACM0";
00029 #else
00030   const char device[] = "/dev/tty.usbmodem1d11";
00031 #endif
00032 
00033   SerialDevice con;
00034   if (! con.connect(device, 19200)) {
00035     printf("SerialDevice::connect: %s\n", con.what());
00036 #if defined(WINDOWS_OS)
00037     printf("Hit return key.\n");
00038     getchar();
00039 #endif
00040     exit(1);
00041   }
00042 
00043   // Call SCIP2.0 and display the response.
00044   enum { Timeout = 200, BufferMax = 64 + 1 };
00045   char buffer[BufferMax];
00046 
00047   for (int i = 0; i < 2; ++i) {
00048     con.send("SCIP2.0\n", 8);
00049 
00050     int n = con.receive(buffer, BufferMax, Timeout);
00051     for (int j = 0; j < n; ++j) {
00052       char ch = buffer[j];
00053       if (isprint(ch)) {
00054         printf("%c", ch);
00055       } else {
00056         printf("[%02x]\n", static_cast<unsigned char>(ch));
00057       }
00058     }
00059     printf("\n");
00060   }
00061 
00062 #if defined(WINDOWS_OS)
00063   printf("Hit return key.\n");
00064   getchar();
00065 #endif
00066 
00067   return 0;
00068 }