serial communication
Im having problems when reading the package from my usb port, It seems the data package is not correctly capture. I am following : http://www.ros.org/wiki/cereal_port. by a slight modification:
#define REPLY_SIZE 8
#define TIMEOUT 1000
int main(int argc, char** argv)
{
ros::init(argc, argv, "example_node");
ros::NodeHandle n;
cereal::CerealPort device;
char reply[REPLY_SIZE];
// int reference;
try{ device.open("/dev/ttyUSB0", 57600); }
catch(cereal::Exception& e)
{
ROS_FATAL("Failed to open the serial port!!!");
ROS_BREAK();
}
ROS_INFO("The serial port is opened.");
ros::Rate r(1);
while(ros::ok())
{
// Send 'R' over the serial port
//device.write("A"); replacing by the data sent by the Maxbotix usb sensor
// Get the reply, the last value is the timeout in ms
//int cereal::CerealPort::read(char * buffer, int max_length, int timeout)
try{ device.read(reply, REPLY_SIZE, TIMEOUT); }
catch(cereal::TimeoutException& e)
{
ROS_ERROR("Timeout!");
}
ROS_INFO("Got this reply: %s", reply);
// reference = atoi (reply);
ros::spinOnce();
r.sleep();
}
}
so instead of sending character A, I am reading data sent by a Maxbotix USB ultrasonic sensor. But the output displayed is not correct, there is a mismatch. I am presuming i need to synronize when the sensor is sending data( start and end data) as the Maxbotix usb sensor keeps monitoring and updating its sensor reading.
Should I use : bool startReadStream(boost::function<void(char*, int)> f)
as to determine when to start to read and when to stop.
Looking forward to any comment. Thanks
I have managed to solved the problem. Do I need to delete this thread as no one is responding?
You're allowed to answer your own question - I'd go ahead and answer with what your solution was, in case it'll help somebody else.