从Web应用程序读取串行端口数据 [英] Read serial port data from web application

查看:86
本文介绍了从Web应用程序读取串行端口数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某种情况下,我们需要集成称重机并使用在MVC中创建的Web应用程序读取值。现在我们所拥有的代码在主机与客户端相同的情况下工作。

当我们在任何其他服务器上部署应用程序时,问题是

串行端口,因为它的元数据只显示当前计算机。



我尝试过:



我已经通过一些资源说明Windows应用程序或ActiveX会做什么。但我的查询是,

ActiveX是浏览器特定的,即只有IE

以及我在云上托管的Web应用程序将如何与Windows应用程序交互?



任何建议或示例都会有所帮助!

问候

解决方案

如果你正在推动这个网站对于选定的客户端,您可以执行诸如编写响应HTTP请求的Windows服务并与硬件端口交互并将HTTP响应发送回调用客户端之类的操作。这样你的网页可以使用普通的jQuery ajax来查询服务并获取数据然后它可以像普通的那样传递给你的服务器代码(另一个ajax调用或表单提交)。



它仍将客户端限制为Windows并需要客户端安装服务,但它是开发ActiveX应用程序或jaca applet或其他任何东西的替代方法。


Web应用程序是一个非常糟糕的选择。除非通过串行端口进行通信的规模直接连接到Web服务器,否则您无法与规模通信。正如您现在可能已经想到的那样,浏览器中的客户端javascript无法访问PC的串行端口。 Javascript只能与其他Web服务器通信。



现在,这个想法不会让您完全重写您的应用程序以支持重写的客户端。 />


您编写的Windows应用程序或服务可以访问串行端口。该应用程序可以与规模通信并从中接收数据,但也可以充当Web服务器,提供它接收的数据,甚至可以接受来自客户端javascript代码的命令。您的客户端代码只能使用其正常操作(如GET和POST)通过HTTP与Web服务器通信。没有任何迹象表明客户端代码无法与客户端上运行的Web服务器通信。


另一种方法是使用rs232到etherenet转换器虚拟化串口,但是你必须知道客户端计算机的IP。



Moxa串口设备服务器

There is a scenario in which we need to integrate Weighing machine and read the value using a web application created in MVC. Now the code we have in place works when the host is same as the client.
When we deploy the application on any other server, then the issue is the
Serial Port as its meta data says only reads for the current computer.

What I have tried:

I have gone through a few resources which say a windows application or ActiveX would do. But my query is,
ActiveX is browser specific i.e. only IE
and How would my web application hosted on cloud would interact with the windows application?

Any suggestions or example would help!
Regards

解决方案

If you're pushing this site out to selected clients then you could do something like write a Windows Service that responds to HTTP requests and interacts with the hardware ports and sends an HTTP response back to the calling client. That way your webpage could use normal jQuery ajax to query the service and get data back that it can then pass to your server code like normal (another ajax call or a form submission).

It will still limit the client to Windows and need the clients to install a service, but it's an alternative to developing an ActiveX app or jaca applet or whatever.


A web application was a very poor choice. Unless the scale, communicating over a serial port, is directly connected to the web server you can't talk to the scale. As you've probably figured out by now, client-side javascript in a browser has no access to the PC's serial ports. Javascript can only talk to other web servers.

Now, here's an idea that doesn't involve you completely rewriting your application to support a rewritten client-side.

You write a Windows application or Service, which will have access to the serial ports. The app can talk to the scale and receive data from it but will also act as a web server, serving up the data it receives and can even accept commands from your client javascript code. You client code can only talk to web servers over HTTP using its normal operations like GET and POST. There's nothing that says the client-side code cannot talk to a web server running on the client itself.


Another way could be virtualizing your serial ports using a rs232 to etherenet converter, but you must know the client computers IP's.

Moxa Serial device servers


这篇关于从Web应用程序读取串行端口数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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