Serial port with ROS - write only?
I am trying to communicate with a device by using a serial port and I have encountered a problem - with every library I have tried using so far (serial, Qextserialport, boost) it is the same. What happens is that I can send commands but I cannot receive any data.
I know that the device works properly because the same code executed as Qt project, without ROS, causes the device to send a response and I can observe this response, either in Qt by port->read
(or similar command), or in terminal such as cutecom. While running a ROS program, there is no output. However I am sure the commands are correct (I can for example send a command to change digital outputs of my device and confirm in cutecom that they have changed).
Hence my question - does serial port communication work in a different way in these two examples (Qt and ROS)? Can ROS be blocking the reading from the port in some way? Maybe should I use longer timeouts?
Here is my code:
int main(int argc, char **argv){
ros::init(argc,argv,"device");
ros::Time::init();
ros::Rate loop_rate(1);
QextSerialPort *port;
PortSettings settings = {BAUD57600, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
port = new QextSerialPort("/dev/ttyACM0", settings, QextSerialPort::Polling);
if(port->open(QIODevice::ReadWrite) == true)
{
qDebug() << "OK";
}
while(ros::ok())
{
commandCnt = 0;
commandArray[commandCnt++] = NF_COMMAND_ReadDigitalInputs; // this is my command array
txCnt = NF_MakeCommandFrame(&NFComBuf, txBuf, commandArray, commandCnt, 48); // command frame
if(port->write((const char*)txBuf, txCnt))
qDebug() << "Commands sent";
ros::spinOnce();
loop_rate.sleep();
}}
I would be greatly appreciated if you could give me a hint where the problem can be.
Asked by tomekfasola on 2014-11-20 07:45:44 UTC
Comments
Is this a persmission problem? Is your user member of the group "dialout"?
Asked by Wolf on 2014-11-20 08:50:10 UTC
Yes, my user is in the "dialout" group. It looks very strange to me because I think that if it was a permission problem, it would rather block writing to the port, not reading. Writing works perfectly, the commands are correct but there is just no response (no data appears in cutecom)
Asked by tomekfasola on 2014-11-20 08:59:09 UTC
Your code doesn't perform any reads.
Asked by dornhege on 2014-11-20 10:37:52 UTC
For completeness, there is the rosserial stack that allow to communicate with several kind of device through ROS.
Asked by Erwan R. on 2014-11-20 10:57:23 UTC
What @dornhege said, the code you posted does not do any reading. ROS should not affect how you serial port works. Many projects use either rosserial or my serial package to read and write from serial ports while also using ROS.
Asked by William on 2014-11-20 13:33:56 UTC