Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem in reading data from Com1 Port


I can read data from same application

but now I want to write data from one application and read from another application.

So "All specialists " please help me and give me the solution.

My Current Application is...
using System;
using System.IO.Ports;
using System.Text;

namespace SerialPortExample
{
    class SerialPortProgram
    {
        // Create the serial port with basic settings
        SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

        [STAThread]
        static void Main(string[] args)
        {


            new SerialPortProgram();
        }

        private SerialPortProgram()
        {


           

            // Instatiate this class
            Console.WriteLine("Incoming Data:");


            port.DataReceived += new SerialDataReceivedEventHandler
(port_DataReceived);
            port.ErrorReceived += new SerialErrorReceivedEventHandler
(port_ErrorReceived);
            port.Open();
            port.Write("TEst1");
           Console.WriteLine(port.ReadExisting ());
            port.Close();
            System.Console.ReadKey();

            port.Close();
        }

        private void port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            //Show all the incoming data in the port's buffer
            Console.WriteLine("Character received");
            Console.WriteLine(port.ReadExisting());
        }


        private void port_ErrorReceived(object sender,
SerialErrorReceivedEventArgs e)
        {
            Console.WriteLine("Error");
        }
    }
}



WAITING FOR REALLY

JILANI SHAIKH
Posted
Updated 15-Feb-10 3:13am
v2

1 solution

I don't believe that you can do that with the standard SerialPort, as it only accepts a single connection at a time per port - which is to be expected. The only way to share the port so that two separate applications can access it, one for read, and one for write, would be to write a separate (probably windows service) application which opens the port and feeds the data into and out of the two applications.

Sharing a port in this way is an unusual thing to do - are you sure you need to do this?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900