[Mono-list] C#/Mono Serial port communication

Jon-Eirik Pettersen lists@jonepet.net
Wed, 24 Nov 2004 18:46:00 +0100


Miguel de Icaza wrote:
>>If I just open /dev/rfcomm0 as a normal file and sends an "AT"  , I'm 
>>able to read out "OK" from the file?
> 
> 
> Yes.
> 
> 

I have created a simple application to try this, but it does not seem to 
work.

using System;
using System.IO;

namespace serialchattest {
   class serialchattest {
     static string device = "/dev/rfcomm0";

     static void Main() {
       using (FileStream fs = new FileStream(device, FileMode.Open, 
FileAccess.ReadWrite)) {
         using (StreamReader sr = new StreamReader(fs)) {
           using (StreamWriter sw = new StreamWriter(fs)) {
             sw.WriteLine("AT");
             Console.Write(sr.ReadLine());
           }
         }
       }
     }
   }
}

Result:

Unhandled Exception: System.IO.IOException: Win32 IO returned 
ERROR_SEEK. Path: /dev/rfcomm0
in <0x00083> System.IO.FileStream:FlushBuffer ()
in <0x0004f> (wrapper remoting-invoke-with-check) 
System.IO.FileStream:FlushBuffer ()
in <0x00043> System.IO.FileStream:Flush ()
in <0x00061> System.IO.StreamWriter:Flush ()
in <0x00025> System.IO.StreamWriter:Dispose (bool)
in <0x00010> System.IO.TextWriter:System.IDisposable.Dispose ()
in <0x000f3> serialchattest.serialchattest:Main ()


Unhandled Exception: System.IO.IOException: Win32 IO returned 
ERROR_SEEK. Path: /dev/rfcomm0
in <0x00083> System.IO.FileStream:FlushBuffer ()
in <0x0004f> (wrapper remoting-invoke-with-check) 
System.IO.FileStream:FlushBuffer ()
in <0x00029> System.IO.FileStream:Dispose (bool)
in <0x00013> System.IO.FileStream:Close ()
in <0x0001e> System.IO.StreamReader:Dispose (bool)
in <0x00010> System.IO.TextReader:System.IDisposable.Dispose ()
in <0x00119> serialchattest.serialchattest:Main ()


Unhandled Exception: System.IO.IOException: Win32 IO returned 
ERROR_SEEK. Path: /dev/rfcomm0
in <0x00083> System.IO.FileStream:FlushBuffer ()
in <0x0004f> (wrapper remoting-invoke-with-check) 
System.IO.FileStream:FlushBuffer ()
in <0x00029> System.IO.FileStream:Dispose (bool)
in <0x00013> System.IO.FileStream:Close ()
in <0x0000b> System.IO.Stream:System.IDisposable.Dispose ()
in <0x0013f> serialchattest.serialchattest:Main ()