[Mono-dev] Mono 2.4 Windows - SerialPort.BytesToRead NullReferenceException

Rytis Ilciukas (rick) zibalas at gmail.com
Wed Apr 29 02:50:51 EDT 2009


I'm trying to run a very simple SerialPort test app (see the code below) on
Windows using Mono and i get

System.NullReferenceException: Object reference not set to an instance of an
obj
ect
  at (wrapper managed-to-native)
System.IO.Ports.WinSerialStream:ClearCommError
(int,uint&,System.IO.Ports.CommStat&)
  at System.IO.Ports.WinSerialStream.get_BytesToRead () [0x00000]
  at System.IO.Ports.SerialPort.get_BytesToRead () [0x00000]
  at (wrapper remoting-invoke-with-check)
System.IO.Ports.SerialPort:get_BytesTo
Read ()
  at PortGrindTest.Program.ThreadFunction () [0x00000]

I've searched the forum and only found posts dating back to 2008 and Mono
1.x So here's my 2ct. It seems that Mono is still very very unstable :( By
the way maybe this isn't the place to post bugs? 

Code:
                    SerialPort port = new SerialPort("COM6");
                    port.ReadTimeout = 2000;
                    port.WriteTimeout = 1000;
                    Console.WriteLine("Thread {0} opened port",
Thread.CurrentThread.ManagedThreadId);
                    lock (this)
                    {
                        port.Open();
                    }
                    try
                    {
                        port.WriteLine("ATE");
                        port.WriteLine("AT");
                        do
                        {
                            string line = port.ReadLine();
                            Console.WriteLine("Received {0}", line);
                        } while (port.BytesToRead != 0);
                    }
                    catch (TimeoutException e)
                    {
                        Console.WriteLine("Thread {0} {1} {2}",
Thread.CurrentThread.ManagedThreadId, freePort.Name, e.Message);
                    }
-- 
View this message in context: http://www.nabble.com/Mono-2.4-Windows---SerialPort.BytesToRead-NullReferenceException-tp23291526p23291526.html
Sent from the Mono - Dev mailing list archive at Nabble.com.



More information about the Mono-devel-list mailing list