Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I am able to connect to the Serial Port and get the data from the serial port through Data Received event handler.

I tried to display the received data in the textbox which is in my WebForm.

My issue is in the Windows(VB.Net) we have the invoke methods, but in the Web application we don't have anything like that to display the data in the WebForm UI Textbox from inside the data received event handler.

Any help on this would be greatly appreciated.

I need this ASAP.

Thanks and Regards
Rajesh.C

What I have tried:

C#
public void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
    SerialPort sp = (SerialPort)sender;
    Textbox1.text = sp.ReadExisting();
}

When I read a Barcode from a Barcode device DataRecivednt Handler is called and the above code get the data from the Serial Port through the device (Sp.ReadExisting) and gets it assigned to the TextBox, But when the DataRecieved Event handler finishes its execution,it comes to the Web Form, but we are not able to see the value in the Textbox
Posted
Updated 22-Jan-17 3:55am
Comments
Richard MacCutchan 22-Jan-17 9:48am    
You cannot do this on a Webform, since the serial reading code runs on the server side, and the TextBox is on the client side.

1 solution

Ummm.... good luck with this. Considering HTTP cannot push content to a client I fail to see how you're going to get this text data from the web server to the client.

You do know how browsers and web servers work, right? HTTP only does something when the browser requests a page from the server then the server sends a response with the requested page. This is referred to as the "request/response" model. The web server cannot send anything to a client (browser) without a request from the client.

Remember, the ASP.NET code you write in C# runs ONLY on the web server, not the client.

You would have to use something like SignalR to send the data to the client (browsers) outside of the HTTP "request/response" pipeline. Your server-side code would normally accumulate a block of data from the serial port and then send that block of data over SignalR, or something similar, to the clients.

You can NOT just set the value of a textbox from the receive handler.

Oh, and using the code you already have, your serial device would have to be attached to the server, not the client. Are you sure this is what you want? If you want the serial device attached to the client instead you cannot use C# code to use the serial port. You would have to use a javascript library, like jUART (Google it).
 
Share this answer
 
v2

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