1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 11:44:53 +08:00
serial/src/test_serial.cpp

43 lines
929 B
C++
Raw Normal View History

2011-03-16 08:03:54 -05:00
#include <string>
#include <iostream>
#include "serial.h"
Serial *serial;
std::string toHex(std::string input) {
std::stringstream ss;
for(unsigned int i = 0; i != input.length(); i++) {
2011-03-16 08:03:54 -05:00
char temp[4];
sprintf(temp, "%.2X", input[i]);
ss << " ";
if(input[i] == 0x0A)
ss << "LF";
else if(input[i] == 0x0D)
ss << "NL";
else
ss << input[i];
ss << " " << std::hex << temp;
}
return ss.str();
};
int main(int argc, char **argv)
{
std::string port("/dev/tty.usbserial-A900cfJA");
// std::string port("/dev/tty.usbmodemfa141");
2011-03-16 08:03:54 -05:00
serial = new Serial(port, 9600, 250);
2011-03-16 08:03:54 -05:00
int count = 0;
while (count != 30) {
// serial->write("Testing.");
2011-03-16 08:03:54 -05:00
std::string result = serial->read(1);
std::cout << ">" << result << std::endl;
// count += 1;
2011-03-16 08:03:54 -05:00
}
return 0;
2011-03-18 19:02:32 -05:00
}