You are not logged in.

#1 2016-02-18 19:12:53

kometonja
Member
Registered: 2012-12-28
Posts: 10

Serial port read/open error in C, Linux

I am having trouble setting correct settings for serial port opening. The information I have is following:

  • Synchronization: Asynchronous method

  • Communication method: Full duplex transmission

  • Communication speed: 9600 bps (bits per second)

  • Transmission code: 8-bit data

  • Data configuration: Start bit 1, data 8-bit + parity 1, stop bit 1

  • Error control: Horizontal (CRC) and vertical (even number) parities

  • 1 byte configuration PC should not use a control signal (DTR, DSR, RTS and CTS) at the time of this connection.


What I have is something like:

bool configurePort(void)   {
    struct termios port_settings;
    bzero(&port_settings, sizeof(port_settings));

    tcgetattr(fd, &port_settings);

    cfsetispeed(&port_settings, B9600);
    cfsetospeed(&port_settings, B9600);

    port_settings.c_cflag &= ~CSIZE;
    port_settings.c_cflag |= CS8;

    // parity bit
    //port_settings.c_cflag &= ~PARENB;
    //port_settings.c_cflag &= ~PARODD;
    // hardware flow
    port_settings.c_cflag &= ~CRTSCTS;
    // stop bit
    //port_settings.c_cflag &= ~CSTOPB;

    port_settings.c_iflag = IGNBRK;
    port_settings.c_iflag &= ~(IXON | IXOFF | IXANY);
    port_settings.c_lflag = 0;
    port_settings.c_oflag = 0;

    port_settings.c_cc[VMIN] = 1;   
    port_settings.c_cc[VTIME] = 0;
    port_settings.c_cc[VEOF] = 4;   

    tcsetattr(fd, TCSANOW, &port_settings);


    return true;
}

Tried various modifications but nothing seems to work.

The device is connected over USB-serial (ttyUSB0) and I have permissions. It opens device, sends (?) data but never gets anything back...

Can someone point me what should be done?

Offline

Board footer

Powered by FluxBB