All pastes #813502 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-12-12 16:11 UTC
rendered paste body
static int rs485_init_port(rs485_port_t * p)
{
  struct termios oldtio, newtio;

  if (!(p->fd)) {
    /* port needs initialized of fd is NULL */

    svs_debug(cl_d_rs485, "Initializing port %s", p->name);

    p->fd = open(p->name, O_RDWR);

    if (p->fd < 0) {
      g_error("Error opening serial port %s\n", p->name);
      return -1;
    }

    //tcgetattr(fd,&oldtio); /* save current serial port settings */
    bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings */

    /* man termios get more info on below settings */
    newtio.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
    newtio.c_iflag = 0;
    newtio.c_oflag = 0;
    newtio.c_lflag = 0;
    newtio.c_cc[VMIN] = 128;

    /* now clean the modem line and activate the settings for the port */
    tcflush(p->fd, TCIFLUSH);
    tcsetattr(p->fd,TCSANOW,&newtio);

    /* disable read blocking */
    fcntl(p->fd, F_SETFL, FNDELAY);

  }

  return 0;
}