[Mono-dev] System.IO.Ports.SerialPort not loading when running app

Shawn Singh radesh.singh at rfsmart.com
Tue Aug 16 15:56:12 EDT 2005


List,

 

I'm writing an app that should collect data on /dev/ttyS0 and push it
out to a web service. The code for the app is included in this message.
Here is the error that I am getting:

 

** (Program.exe:13337): WARNING **: The class System.IO.Ports.SerialPort
could not be loaded, used in /export/home/shawn/src/c#/v2/Program.exe
(token 0x01000002). 
 
Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object

 

I've got Mono v1.1.8.3 running on Mandrake Linux 9.2.

 

Source code:

 

Here is my source code:

 
Here is a copy of my source code: 
 
// Part 1:  COM Listener & Data Receiver 
/*      
  This code will watch for the COM Port to be open 
  and when it is, it will read data from it into memory. 
 
  When the port is closed, the data will be pushed to the 
  web service (Part 2 is the push) 
*/ 
 
using System.IO.Ports;        // NOT available in VS .NET 2003 
                                      // IS provided with VS .NET 2005 
                                      // TO work with MONO, you need to
have at least Mono v1.1.8 
 
// Part 2:  POST to Web Service 


/* 
  Transfer data that was captured from the COM Port 
  to the specified web service. 
*/ 
 
using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Net; 
using System.Net.Sockets; 
using System.Text; 
using System.Web; 
 
namespace rfidapp 
{ 
 /// <summary> 
 /// Summary description for Class1. 
 /// </summary> 
    class Program 
    { 
   /// <summary> 
   /// The main entry point for the application. 
   /// </summary> 
   [STAThread] 
   static void Main(string[] args) 
   { 
  try
// begin serial port stuff 
  { 
      // Listen & Receive 
 
      string devName = "/dev/ttyS0";     // COM1 
      int readTimeOut = 300;   
      byte rawDTA; 
      string rXDTA = "thisizenishilizerdtuh"; 
 
      SerialPort COMPort = new SerialPort(devName); 
      COMPort.ReadTimeout = readTimeOut; 
 
      for (; ; ) 
      { 
     while (COMPort.IsOpen) 
     { 
    rawDTA = (byte)COMPort.ReadByte(); 
    rXDTA += ((char)rawDTA); 
     } 
 
     if (COMPort.IsOpen) 
    COMPort.Close();
// end serial port stuff
 
     // Post 
     if (!rXDTA.Contains("thisizenishilizerdtuh"))      // something to
prevent this code from being executed
     { 
    string uri = "http://smartserver/rfidlistener";     // bogus name
    byte[] bytes = new System.Text.UnicodeEncoding().GetBytes(rXDTA); 
 
    WebRequest request = WebRequest.Create(uri); 
    request.Method = "POST"; 
    request.ContentType = "text/html"; 
    request.ContentLength = bytes.Length; 
 
 
    Stream output = request.GetRequestStream(); 
    output.Write(bytes, 0, bytes.Length); 
    output.Close(); 
    WebResponse response = request.GetResponse(); 
    Console.WriteLine(response.ToString()); 
     } 
     Console.WriteLine("Listening for data ..."); 
      } 
  } 
  catch (Exception e) 
  { 
      Console.WriteLine("Error: " + e.Message.ToString()); 
  } 
   } 
    } 
} 

 

Any thoughts?

 

Thank you,

 

Shawn Singh

Programmer, RFSmart

Jacksonville, FL 32256

904-399-8500 ext. 1667

shawn.singh at rfsmart.com

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050816/768b3260/attachment.html 


More information about the Mono-devel-list mailing list