I've written a small server component in .NET 4.0 that uses the TcpListener, Socket, NetworkStream and SerialPort classes, all of which are in the System.dll assembly (v4.0.30319).
It runs as a command line application, so doesn't have any UI requirements.
Its currently running in Windows and my current goal is to get it working on Linux. One way to do this would be to use the latest version of Mono. Does anyone have any hints or gotchas which I should look out for - is this feasible?
Any suggestions greatly appreciated, thanks.
Structure of the application:
- Listen on a TCP port for a client connection, accept when needed.
- Main loop :-
- Read data frames from the serial port.
- Forward the data frames to the client over TCP.
- Receive various commands from the client over TCP, and act on them as required.
UPDATE:
I've ported a stub program which only implemented the basic functions of TcpListener, Socket, NetworkStream, TcpClient and SerialPort.
It worked fine apart from the SerialPort's DataReceived event handler, which doesn't get called by Mono. The solution was simply to poll the port at a regular interval. Another minor change required was to not access the 'ReceivedBytesThreshold' property of the serial port; trying to set this in mono will throw an 'Unsupported feature' exception.
Ubuntu VM
I installed it inside a VirtualBox VM of Ubuntu Desktop 12.04, including serial port mapping from the host (Win7) to guest OS which worked fine to map COM1 to /dev/ttyS0. A final note, you have to run the resulting application as superuser (sudo) or else it complains about serial port permissions at runtime.
Raspberry Pi
I have also just got this working under Mono on a Raspberry Pi single board computer with some help from our hardware engineer who created a custom extension board to talk to the RPi's onboard UART (via GPIO). The OS you need to run is the "soft float" Debian distribution, available on the Raspberry Pi download section. Installing Mono on it is a breeze, using the apt-get package manager. The serial port name in this case is /dev/ttyAMA0.