2

Are the settings altered by functions from termios.h kept after file is closed and open again?

I want to use serial communication in a higher level language (Racket) which exposes only reading and writing to/from file ports, but none of the additional functionality (termios, ioctl, fnctl). I can use FFI to bind those additional functions and use them, but then I need to close given file and open it again to read/write with Racket functionality - hence my question.

3
  • After the closing of which file??
    – peterh
    Feb 1, 2015 at 22:19
  • After calling close on a file descriptor used to alter the serial communication settings
    – Bartosz
    Feb 2, 2015 at 8:32
  • What is "FFI"? Foreign function interface? Sep 27, 2021 at 23:56

1 Answer 1

2

Most termios settings such as baud rate are retained even when a serial port is closed. However, closing a serial port does have some effects which you might not want, such as de-asserting DTR.

However, you should be able to hold the serial port open in your application and avoid any unwated effects, including avoiding loss of any changes to settings that might get reset on close. Just open the port in Racket first; then use FFI functionality to do whatever ioctl and fcntl you need, which might involve opening the serial port a second time and closing the second reference; then use the reference you originally opened from Racket. Moreover, you might even be able to instead obtain the file descriptor directly from Racket and use it for FFI without opening the serial port a second time — I'm not sure about that because I don't know what Racket is.

2
  • Thanks, to be honest I just assumed it won't be possible to open the port second time...
    – Bartosz
    Feb 2, 2015 at 8:33
  • (unwatedunwanted) Sep 27, 2021 at 23:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .