无法在C#Web应用程序的串行端口中显示文本框中的接收数据 [英] Not able to display the received data in textbox from serial port in the C# web application

查看:84
本文介绍了无法在C#Web应用程序的串行端口中显示文本框中的接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我能够连接到串口并通过数据接收事件处理程序从串口获取数据。



我试图在我的WebForm文本框中显示收到的数据。



我的问题在Windows中( VB.Net)我们有调用方法,但是在Web应用程序中,我们没有类似的东西在数据接收事件处理程序内部显示WebForm UI文本框中的数据。



如果对此有任何帮助,将不胜感激。



我需要尽快这样。



谢谢和问候

Rajesh.C



我尝试过:



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:

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

推荐答案

嗯....祝你好运。考虑到HTTP无法将内容推送到客户端,我无法看到您将如何从Web服务器向客户端获取此文本数据。



您知道如何浏览器和Web服务器工作,对吗? HTTP仅在浏览器从服务器请求页面时执行某些操作,然后服务器发送带有请求页面的响应。这被称为请求/响应模型。没有来自客户端的请求,Web服务器无法向客户端(浏览器)发送任何内容。



请记住,您在C#中编写的ASP.NET代码仅在Web服务器,而不是客户端。



您必须使用SignalR之类的东西将数据发送到HTTP请求/响应之外的客户端(浏览器)管道。您的服务器端代码通常会从串口累积一个数据块,然后通过SignalR或类似的东西将该数据块发送给客户端。



你不能只从接收处理程序设置文本框的值。



哦,使用你已经拥有的代码,你的串口设备必须连接到服务器,而不是客户端。你确定这是你想要的吗?如果您希望串行设备连接到客户端,则不能使用C#代码来使用串行端口。您必须使用javascript库,例如jUART(Google it)。
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).


这篇关于无法在C#Web应用程序的串行端口中显示文本框中的接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆