Click here to Skip to main content
15,937,735 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends I want to Communicate serial port from Client side.
I have a written code in asp.net but that is executing fine from server side. see code.
SerialPort serial = new SerialPort();
    public string recieved_data;
    //public static string strtemp = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
       
    }

    private void Recieve(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {
        // Collecting the characters received to our 'buffer' (string).
        try
        {
            if (serial.IsOpen == false)
                serial.Open();
            if (serial.IsOpen == true)
            {
                recieved_data = serial.ReadExisting();
                clsData.strData = recieved_data;
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.Message.ToString();
        }
    }
    protected void btnStart_Click(object sender, EventArgs e)
    {
        try
        {
            serial.PortName = "COM1"; //Com Port Name
            serial.BaudRate = 9600; //COM Port Sp
            serial.Handshake = System.IO.Ports.Handshake.None;
            serial.Parity = Parity.None;
            serial.DataBits = 8;
            serial.StopBits = StopBits.One;
            serial.ReadTimeout = 200;
            serial.WriteTimeout = 50;
            if (serial.IsOpen == true)
                serial.Close();
            serial.Open();
            //Sets button State and Creates function call on data recieved
            serial.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(Recieve);
        }
        catch (Exception exp)
        {
            lblMessage.Text = exp.Message.ToString();
        }
    }
    protected void btnStop_Click(object sender, EventArgs e)
    {
        serial.Close();
    }   
}
[Serializable]
public  class clsData
{
    public static string strData = "";
    public static string getclsData()
    {
        return strData;
    }
}

I want to execute this code in Client Side without active-x.....
Please any body can solve this problem.
Posted
Updated 13-Dec-10 19:21pm
v2
Comments
Toniyo Jackson 14-Dec-10 1:22am    
Always put your code inside code block.
fjdiewornncalwe 14-Dec-10 11:24am    
What is the problem you are trying to solve with this solution? If we could understand the reasoning behind the problem you are solving, we could perhaps point you in the direction of a feasible solution. This one won't work as described by Dave's answer below.

1 solution

You can't. In an ASP.NET app, all the C# code you write only executes on the server side.

You'd have to write some component, either ActiveX, Silverlight, Java, ... ini order to do what you want. The code you have right now in your code-behind is completely useless.
 
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