I'm using .NET Core on an embedded Linux platform with good success so far. I just ran into a problem with trying to open a tty device in raw (noncanonical mode) though. If I was using regular C or C++ I would call cfmakeraw()
after opening the device, but how do I do that from a .NET Core app?
The device I need to work with is a CDC ACM function driver for the USB client connector, i.e. it's a virtual COM port. It appears in my system as /dev/ttyGS0
. I can open the device and then read from it and write to it using this code:
FileStream vcom = new FileStream("/dev/ttyGS0", FileMode.Open);
Because the tty device opens in canonical mode by default I don't receive any characters until the user sends the carriage return character at the end of the line of text. I need to receive each character as it is sent, rather than waiting untill the carriage return is sent, i.e. I need to use raw mode for the tty device.
The code below does not work because .NET Core does not realize that this device is a virtual serial port, so it throws an exception when I try to open it this way. When I open the real UART devices using SerialPort
then they do behave in raw mode as expected.
SerialPort serialPort = new SerialPort("/dev/ttyGS0);