tags:

views:

507

answers:

3

am doing some surveillance project... i need to make some serialport data communication between two systems ... here i could find available com ports in my system through which i need to send and receive some data...is it possible in .net framework 1.1 ? is there is any option?

System.IO.Ports is not available .net 1.1

A: 

Are you constrained to .NET 1.1? If .NET 2.0 is available to you, you can use the SerialPort.GetPortNames method to retrieve a list of serial ports on the local host. The SerialPort class is in the System.IO.Ports namespace.

Brandon E Taylor
System.IO.Ports is not in .net 1.1
Rex Logan
Right. I will edit my post accordingly.
Brandon E Taylor
+1  A: 

For .net 1.1 I used OpenNETCF.IO.Serial because serial support was added to .net in version 2.0. It is for the compact framework but I used it for both compact devices and regular windows apps. You get the source code so you can modify it yourself which is what I did.

It basically creates a c# wrapper around the serial function imported out of kernel32.dll.

You might also want to have a look at How to capture a serial port that disappears because the usb cable gets unplugged

Here is the code that I used to call it

     using OpenNETCF.IO.Serial;

     public static Port port;
     private DetailedPortSettings portSettings;
     private Mutex UpdateBusy = new Mutex();

     // create the port
     try
     {
        // create the port settings
        portSettings = new HandshakeNone();
        portSettings.BasicSettings.BaudRate=BaudRates.CBR_9600;

        // create a default port on COM3 with no handshaking
        port = new Port("COM3:", portSettings);

        // define an event handler
        port.DataReceived +=new Port.CommEvent(port_DataReceived);

        port.RThreshold = 1;    
        port.InputLen = 0;   
        port.SThreshold = 1;    
        try
        {
           port.Open();
        }
        catch
        {
           port.Close();
        }
     }
     catch
     {
        port.Close();
     }

     private void port_DataReceived()
     {

        // since RThreshold = 1, we get an event for every character
        byte[] inputData = port.Input;

        // do something with the data
        // note that this is called from a read thread so you should 
        // protect any data pass from here to the main thread using mutex
        // don't forget the use the mutex in the main thread as well
        UpdateBusy.WaitOne();
        // copy data to another data structure
        UpdateBusy.ReleaseMutex();

     }

     private void port_SendBuff()
     {
        byte[] outputData = new byte[esize];
        crc=0xffff;
        j=0;
        outputData[j++]=FS;
        //  .. more code to fill up buff
        outputData[j++]=FS;
        // number of chars sent is determined by size of outputData
        port.Output = outputData;
     }

     // code to close port
     if (port.IsOpen)
     {
        port.Close();
     }
     port.Dispose();
Rex Logan
+1  A: 

When I needed to do some serial port work back in 1.1, I found an article written by Noah Coad that uses the MSComm OCX control and that ended up working for me. You can find his article at http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=320. Good luck!

scwagner