====== Programming the Serial Port in Mono ====== ===== Note ===== The Mono framework's ''SerialPort'' class [[https://github.com/mono/mono/issues/14118 | does not support the ''DataReceived'' event]], so it may be necessary poll the serial port to receive data, or use one of the following potential workarounds: * [[https://antanas.veiverys.com/mono-serialport-datareceived-event-workaround-using-a-derived-class/|Mono SerialPort.DataReceived Event Workaround – Using a Derived Class]] * [[http://downloads.comfiletech.com/ComfilePi/Comfile.ComfilePi.SerialPortExample.zip|Download a Visual Studio solution]] that implements this workaround * [[http://www.sparxeng.com/blog/software/must-use-net-system-io-ports-serialport#comment-840|If you *must* use .NET System.IO.Ports.SerialPort ]] * Use [[https://github.com/jcurl/RJCP.DLL.SerialPortStream|the RJCP.DLL.SerialPortStream library]], an independent serial port implementation. ===== Example ===== The following example implements a client and a server. ''Server.exe'' runs on a Windows PC, and ''Client.exe'' runs on the ComfilePi. When the commands ''date'' or ''time'' are typed into the client, the server responds with the date and time respectively. | {{:comfilepi:programming_the_serialport:client.png?500|}} | {{:comfilepi:programming_the_serialport:server.png?500|}} | {{ :comfilepi:programming_the_serialport:datetimequery.zip | Download Source Code}}