Note that there are some explanatory texts on larger screens.

plurals
  1. POSerial.readline - out of memory
    primarykey
    data
    text
    <p>I am reading from an Arduino, which is sending text through the USB port. The Arduino sends the status of it's outputs every second. On the command received event I set a couple of checkboxes (either shutter open or mains on, or lights on) and also it outputs the data it received to a multiline text box.<br> Anyway.... it all works, for a few seconds, then slows down and eventually after about 10 minutes I get a Out of Memory exception. I cant figure out whats going wrong, I assume its in the class that reads the serial data - so here is that code, can anybody see anything wrong?</p> <pre><code>using System; using System.IO.Ports; namespace WOCA.Core.SerialComms { internal class ArduinoCommunicator : ICommunicator { public event EventHandler&lt;CommsEventsArg&gt; CommandReceived; internal ArduinoCommunicator(string comPort) { Port = new SerialPort(comPort) {BaudRate = 9600, DtrEnable = true}; Port.DataReceived += PortOnDataReceived; } private SerialPort Port { get; set; } public bool IsOpen { get; set; } public void Open() { try { if (!Port.IsOpen) { Port.Open(); IsOpen = true; } else { throw new InvalidSerialCommsException("Serial port already open"); } } catch (Exception ex) { throw new InvalidSerialCommsException("Serial Port error: " + ex.Message); } } public void Close() { try { if (Port.IsOpen) { Port.Close(); IsOpen = false; } else { throw new InvalidSerialCommsException("Serial port not open"); } } catch (Exception) { throw new InvalidSerialCommsException("Serial port error"); } } public void SendCommand(string command) { try { if (Port.IsOpen) { Port.Write(command); } else { throw new InvalidSerialCommsException("Serial port not open"); } } catch (Exception) { throw new InvalidSerialCommsException("Serial port error, the command has not been sent"); } } private void PortOnDataReceived(object sender, SerialDataReceivedEventArgs serialDataReceivedEventArgs) { SerialPort serialPort = sender as SerialPort; if (serialPort != null) { string command = serialPort.ReadLine(); command = command.Remove(command.Length-1,1); CommsEventsArg args = new CommsEventsArg(command); OnCommandReceived(args); } } protected virtual void OnCommandReceived(CommsEventsArg e) { EventHandler&lt;CommsEventsArg&gt; handler = CommandReceived; if (handler != null) { handler(this, e); } } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload