Hi,
I try to initialize the RS845 serial port. In several examples that I've got to use the
TIOCGRS485 to get the struct and TIOCSRS485 to write the structure back.
Everytime I call the ioctl I receive an Invalid Argument error, which I think means
that it's not supported on PicoCOM4. Do you have an example to initialize the RS485 correctly?
Thanks
Marc
Code
- int initport ( int fd ) {
- struct termios options;
- // Get the current options for the port...
- tcgetattr ( fd, &options );
- // Set the baud rates to 19200...
- cfsetispeed ( &options, B38400 );
- cfsetospeed ( &options, B38400 );
- // Enable the receiver and set local mode...
- //options.c_cflag |= ( CLOCAL | CREAD );
- options.c_cflag = CS8|CREAD|IGNPAR;
- options.c_iflag = 0;
- options.c_oflag = 0;
- // DISABLE this: Echo input characters.
- options.c_lflag &= ~(ICANON);
- options.c_lflag &= ~(ECHO);
- // DISABLE this: If ICANON is also set, the ERASE character
- // erases the preceding input
- // character, and WERASE erases the preceding word.
- options.c_lflag &= ~(ECHOE);
- // DISABLE this: When any of the characters INTR, QUIT, SUSP,
- // or DSUSP are received, generate the corresponding signal.
- options.c_lflag &= ~(ISIG);
- // Minimum number of characters for non-canonical read.
- options.c_cc[VMIN]=1;
- // Timeout in deciseconds for non-canonical read.
- options.c_cc[VTIME]=0;
- struct serial_rs485 rs485conf;
- // Set the new options for the port...
- if (ioctl (fd, TIOCGRS485, &rs485conf) < 0) {
- printf("Error: TIOCGRS485 ioctl not supported.\n");
- }
- /* Enable RS485 mode: */
- rs485conf.flags |= SER_RS485_ENABLED;
- /* Set logical level for RTS pin equal to 1 when sending: */
- //rs485conf.flags |= SER_RS485_RTS_ON_SEND;
- /* or, set logical level for RTS pin equal to 0 when sending: */
- //rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND);
- /* Set logical level for RTS pin equal to 1 after sending: */
- //rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
- /* or, set logical level for RTS pin equal to 0 after sending: */
- //rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND);
- /* Set rts delay before send, if needed: */
- //rs485conf.delay_rts_before_send = ...;
- /* Set rts delay after send, if needed: */
- //rs485conf.delay_rts_after_send = ...;
- /* Set this flag if you want to receive data even whilst sending data */
- //rs485conf.flags |= SER_RS485_RX_DURING_TX;
- int retval = ioctl (fd, TIOCSRS485, &rs485conf);
- if (retval < 0) {
- printf("Error: TIOCSRS485 ioctl not supported.\n");
- }
- tcsetattr ( fd, TCSANOW, &options );
- return 1;
- }