Before updating to Windows 10 you may need to return your Pro license. More information here

'SerialDataReceivedEventHandler' is not working.

Please help me. 'SerialDataReceivedEventHandler' is not working.

Tell me. If you know other way.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO.Ports;

namespace SerialPortCtrl {

 public class ComPort
     SerialPort SP = new SerialPort();
     List<string> RevData = new List<string>();

     public ComPort()


     private void SP_DataRecieved(Object sender, SerialDataReceivedEventArgs e)

     private void SP_ErrorRecieved(Object sender, SerialErrorReceivedEventArgs e)
         RevData.Add("Error while receiving data. " + e.ToString()); 
     public string GetData()
         string RevStr = "";
         if ( RevData.Count == 0) return "";
         RevStr = RevData[0];
         return RevStr;

     public bool SendData(string Data)
         if (SP.IsOpen)
             return true;
         else return false;

     public bool Open(string PortName, int BaudRate = 9600, int DataBits = 8)
         SP.PortName = PortName;
         SP.BaudRate = BaudRate;
         SP.DataBits = DataBits;
         SP.Parity = Parity.None;
         SP.StopBits = StopBits.One;
         SP.ReadTimeout = (int)500;
         SP.WriteTimeout = (int)500;
         SP.ReadBufferSize = 4;
         SP.WriteBufferSize = 4;

         SP.DtrEnable = true;
         SP.RtsEnable = true;

         SP.DataReceived += new SerialDataReceivedEventHandler(SP_DataRecieved);
         SP.ErrorReceived += new SerialErrorReceivedEventHandler(SP_ErrorRecieved);
         if (SP.IsOpen) return true; else return false; 

     public void Close()


more ▼

asked Nov 26, 2011 at 05:01 AM

avatar image

1 6 4 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I've come across the same issue trying to get my [arduino][1] to communicate to unity through serial. I think the reason is due to monos implementation of SerialPort is not complete...

After some digging around I found [SerialPort.ReceivedBytesThreshold][2] property:

The number of bytes in the internal input buffer before a DataReceived event is fired. The default is 1.

Remarks: The DataReceived event is also raised if an Eof character is received, regardless of the number of bytes in the internal input buffer and the value of the ReceivedBytesThreshold property.

If you try and log your serial port's ReceivedBytesThreshold property you get this error message:

NotImplementedException: The requested feature is not implemented.

System.IO.Ports.SerialPort.set_ReceivedBytesThreshold (Int32 value) (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:set_ReceivedBytesThreshold (int) GyroSyncBehavior.Start () (at Assets/Scripts/GyroSyncBehavior.cs:23) I'm guessing that the DataReceived event doesn't fire under Unity's .NET 2.0 mono version, but I'm a noob so I might be wrong. [1]: http://www.arduino.cc [2]: http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.receivedbytesthreshold.aspx
more ▼

answered Jun 08, 2012 at 07:35 PM

avatar image


Did you manage to figure this out, I'm having the same problem as you guys right now.

Jul 21, 2012 at 05:44 PM Artifactx

Any workaround for this? I'm having the same issue.

Mar 27 at 06:02 PM Ben BearFish
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Nov 26, 2011 at 05:01 AM

Seen: 2463 times

Last Updated: Mar 27 at 06:02 PM