Serial port with ROS - write only?

asked 2014-11-20 06:45:44 -0500

tomekfasola gravatar image

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.

edit retag flag offensive close merge delete

Comments

Is this a persmission problem? Is your user member of the group "dialout"?

Wolf gravatar image Wolf  ( 2014-11-20 07:50:10 -0500 )edit

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)

tomekfasola gravatar image tomekfasola  ( 2014-11-20 07:59:09 -0500 )edit

Your code doesn't perform any reads.

dornhege gravatar image dornhege  ( 2014-11-20 09:37:52 -0500 )edit
1

For completeness, there is the rosserial stack that allow to communicate with several kind of device through ROS.

Erwan R. gravatar image Erwan R.  ( 2014-11-20 09:57:23 -0500 )edit

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.

William gravatar image William  ( 2014-11-20 12:33:56 -0500 )edit