Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seg-fault within Yarp when creating SerialPort #504

Closed
Arikae opened this issue Jun 12, 2015 · 2 comments
Closed

Seg-fault within Yarp when creating SerialPort #504

Arikae opened this issue Jun 12, 2015 · 2 comments

Comments

@Arikae
Copy link

Arikae commented Jun 12, 2015

Hi,

we ran into a problem within yarp when creating our own SerialPort for reading from an external device.

This is the stacktrace:


Thread #3 [HapticGloveTele] 15858 [core: 0](Suspended : Signal : SIGSEGV:Segmentation fault)
SerialPort::SerialPortImpl::HandlePosixSignal() at 0x7ffff79d182a
0x7ffff79d1bfd
() at 0x7ffff6a21eb0
accept() at syscall-template.S:81 0x7ffff6ae59ad
ACE_SOCK_Acceptor::accept(ACE_SOCK_Stream&, ACE_Addr_, ACE_Time_Value_, bool, bool) const at 0x7ffff6576429
yarp::os::impl::SocketTwoWayStream::open() at 0x7ffff774ed22
yarp::os::impl::TcpFace::read() at 0x7ffff7753833
yarp::os::impl::PortCore::run() at 0x7ffff76dd915
theExecutiveBranch() at 0x7ffff775677b
ACE_OS_Thread_Adapter::invoke() at 0x7ffff655bb16
start_thread() at pthread_create.c:309 0x7ffff60580a5
clone() at clone.S:111 0x7ffff6ae4cfd


The simpllified code that leads to the failure, when executed is the following:

std::string DEVICE_NAME = "/dev/ttyACM1";
SerialPort serial(DEVICE_NAME);
serial.Open(SerialPort::BAUD_115200, SerialPort::CHAR_SIZE_8,
SerialPort::PARITY_NONE, SerialPort::STOP_BITS_1,
SerialPort::FLOW_CONTROL_NONE);
if (serial.IsOpen() == true) {
printf("Serial Port is Open!\n");
} else {
printf("Error: Could not open serial port");
}

while (true) {
if (serial.IsDataAvailable()) {
next_byte = serial.ReadByte();

            if(next_byte == startByte) {
                         flyReadyToPopulate = true;
            }

             if(flyReadToPopulate) {
                         doSomething();
                         flyReadyToPopulate = false; 
            }
            else {
                         usleep(10);
            }
    }

}

Here we open a Serialport to an external device that is connected via USB but after some readings, we get the segmentation fault.
It tells us that yarp is doing something internally with SerialPort that we might have crashed.
Does anyone has a suggestion what the problem might be?

Regards
Lars

@apaikan
Copy link
Collaborator

apaikan commented Jun 14, 2015

Hi Lars,

Are you using yarp serial device somewhere else? YARP cannot interfere with any devices or system calls of the system if they are not explicitly called from YARP. My guess is that the problem is coming from somewhere else in your code which causes memory fault.
Anyway, have you tried to use the Yarp serial device interface instead of yours? I have been using it for different small projects and it seems it is working fine!

       #include <yarp/dev/SerialInterfaces.h>
       #include <yarp/dev/PolyDriver.h>

        PolyDriver driver;
        ISerialDevice *iSerial;
        Property prop;        
        prop.put("device", "serialport");
        prop.put("comport", "/dev/ttyACM1");
        prop.put("baudrate", 115200);
        prop.put("paritymode", "NONE");
        prop.put("databits", 8);
        prop.put("readtimeoutmsec", 1000);
        prop.put("verbose", 0);

        driver.open(prop);
        if(!driver.isValid()){
            fprintf(stderr, "Error opening PolyDriver check parameters\n");
            return false;
        }

        driver.view(iSerial);  
        if(!iSerial) {
            fprintf(stderr, "Error opening serial driver. Device not available\n");
            return false;
        }

...

        char data;        
        iSerial->receiveChar(data);
...

@Arikae
Copy link
Author

Arikae commented Jun 15, 2015

Thanks!
Problem is gone and works like a charm now :)

@Arikae Arikae closed this as completed Jun 15, 2015
@pattacini pattacini changed the title Segmentationfault within Yarp Seg-fault within Yarp when creating SerialPort Jun 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants