[Mono-dev] Mono C# Serial Port problem

PaceyIV paceynet at gmail.com
Tue Jun 10 07:42:05 EDT 2008


Now I try the code below. It works on Microsoft Visual Studio, but not in
mono on Ubuntu.
It compile it, but when I try to run it I get this error:

Unhandled Exception: System.NotImplementedException: The requested feature
is not implemented.
  at System.IO.Ports.SerialPort.set_ReceivedBytesThreshold (Int32 value)
[0x00012] in
  at (wrapper remoting-invoke-with-check)
System.IO.Ports.SerialPort:set_ReceivedBytesThreshold (int)
  at ConsoleApplication1.Program.Main (System.String[] args) [0x0004f] in

So I comment the line!
I think don't work the SerialDataReceivedEventHandler. I can write code to
read the byte from serial and the device respond, but the Serial Data
Received Event newer works on mono.

What's wrong?

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

namespace ConsoleApplication1
    class Program
        static System.IO.Ports.SerialPort rs232;
        static string dati;

        static void Main(string[] args)
            // Setup RS-232
			rs232 = new SerialPort("/dev/ttyUSB0", 9600);
			// for Win
            //rs232 = new SerialPort("COM3", 9600);
            rs232.BaudRate = 9600;
            rs232.Parity = Parity.None;
            rs232.DataBits = 8;
            rs232.StopBits = StopBits.One;
            rs232.Handshake = Handshake.None;
			//rs232.ReadTimeout = 2000;
			//rs232.ReadBufferSize = 1024;
            //rs232.ReceivedBytesThreshold = 1; // This don't work in mono!
            rs232.DataReceived +=
                new SerialDataReceivedEventHandler(rs232_DataReceived); //
This don't work in mono!

            // Open SerialPort
				// Do I really need this?
				// Dealy for my specific device
			catch (System.IO.IOException ioe)

			// survive to Microsoft :)
			//CheckForIllegalCrossThreadCalls = false;
			// Send command to read some date from the device

            string m;
            bool continua = true;
            while (continua)
                m = Console.ReadLine();
                if (m=="q")
                    continua = false;


        static void rs232_DataReceived(object sender,
SerialDataReceivedEventArgs e)
            dati += rs232.ReadExisting();
            if (dati.Contains("$"))

View this message in context: http://www.nabble.com/Mono-C--Serial-Port-problem-tp17241892p17753378.html
Sent from the Mono - Dev mailing list archive at Nabble.com.

More information about the Mono-devel-list mailing list