jcurl / RJCP.DLL.SerialPortStream

SerialPortStream is an independent implementation of System.IO.Ports.SerialPort and SerialStream for better reliability and maintainability. Default branch is 2.x and now has support for Mono with help of a C library.
Microsoft Public License
628 stars 197 forks source link

lost SerialDataReceivedEventHandler #5

Closed nidheg666 closed 8 years ago

nidheg666 commented 8 years ago

the transition from version 1.2 from nuget to 2.x from github, lost SerialDataReceivedEventHandler.

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'SerialDataReceivedEventHandler' could not be found (are you missing a using directive or an assembly reference?) SerialPortCommunication C:\work\C#\SerialPortCommunication\MyComm.cs 300 Active

using RJCP.IO; using RJCP; using RJCP.IO.Ports;

jcurl commented 8 years ago

There is a slight change in the naming of the events to modernise the code base.

Look at this test case:

        [Test]
        [Category("SerialPortStream")]
        public void WaitForRxCharEventOn1Byte()
        {
            using (ManualResetEvent rxChar = new ManualResetEvent(false))
            using (SerialPortStream src = new SerialPortStream(c_SourcePort, 115200, 8, Parity.None, StopBits.One))
            using (SerialPortStream dst = new SerialPortStream(c_DestPort, 115200, 8, Parity.None, StopBits.One)) {
                src.Open(); src.WriteTimeout = c_TimeOut; src.ReadTimeout = c_TimeOut;
                dst.Open(); dst.WriteTimeout = c_TimeOut; dst.ReadTimeout = c_TimeOut;

                dst.ReceivedBytesThreshold = 1;
                dst.DataReceived += (s, a) => { rxChar.Set(); };
                src.WriteByte(0x00);
                Assert.That(rxChar.WaitOne(1000), Is.True);
            }
        }

The type has changed slightly to use Generics: public event EventHandler<SerialDataReceivedEventArgs> DataReceived;

The events are one of the very few changes. Looks like I should update the README.md to note this change.

nidheg666 commented 8 years ago

thanks. It came alive)