如何从用户的串行端口读取网页? [英] How can a web page read from the user's serial port?

查看:273
本文介绍了如何从用户的串行端口读取网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从头重新实现现有的系统。

I have to re-implement an existing system from scratch.

有一点,当用户导航到某个网页时,服务器必须从用户的串行端口读取数据。

At one point, when the user navigates to a certain web page the server must read data from the user's serial port.

目前,网页有一个ActiveX控件;当页面被加载时,ActiveX控件调用到用户PC上的COM DLL,它从串行端口读取数据。

Currently, the web page has an ActiveX control; when the page is loaded the ActiveX control calls into a COM DLL on the user's PC which reads data from the serial port.

系统是10岁。是否有任何更好的方式,我可以实现这一点?

The system is 10 years old. Is there any "better" way that I could implement this?

例如,技术在过去十年中发展。这个解决方案似乎只能在MS IE,现在有大约26%的市场份额。

For instance, technology has move on in the last ten years. And this solution seems only to work in MS IE, which now has a market share of about 26%

@ EuroMicelli说我会假设你有一个很好的理由从一个Web浏览器,而不是本机应用程序运行您的应用程序。我不知道,因为我不在周围的时间计划(和设计它的公司现在已经停止)。

[Update] @ EuroMicelli said "I'm going to assume that you have a very good reason to run your app from a web browser, instead of a native app". I don't know as I wasn't around when the orignal project was planned (and the company which designed it is now defunct).

也许他们不想最终用户直接与数据库连接?或许基于浏览器是一个新的流行语?我,personaly,没有问题的桌面应用程序(因为我发现他们更容易实现),但也许我们应该考虑保持基于浏览器? (此外,我可以自己处理桌面应用程序;它只是基于浏览器从COM端口读取,这导致我提供奖金; - )

Perhaps they didn't want the end user interfacing directly with the database? Perhaps "browser based" was a new buzzword back then? I, personaly, have no problem with a desktop app (as I find them easier to implement), but maybe we should consider remaining browser based? (besides, I can handle the desktop app myself; it's only browser based reading from teh COM port that leads me to offer a bonus ;-)

推荐答案

有一件事是肯定的,你永远不能与本地机器硬件通信,而不在本地机器上安装一些特殊的二进制文件(并以适当的权限运行)。但是,这并不意味着您需要使用ActiveX组件,并保持与Internet Explorer。当然,您也可以为市场中的每个浏览器开发一个组件。

One thing for sure, you will never be able to communicate with the local machine hardware without installing some special binaries (and run it with appropriate privileges) on the local machine. However, that doesn't mean you necessary need to use an ActiveX component and stay stuck with Internet Explorer. Of course, you could also develop a component for every browser in the market.

我建议另一种方法:


  • 编写Windows服务(我假设您的计算机运行Windows),使用必要的权限配置它。您将必须在机器上安装某些东西。该服务可以用任何语言实现。

  • 向其添加HTTP(S)服务器功能。您可以在这里使用很多技术,从WCF到WebAPI。

  • 通过HTTP发布您自己的通信协议。您可以使用JSON,Ajax,WebSockets,SignalR等。

  • 编写一个与市场上大多数浏览器兼容的Javascript文件,因此您只需要编写一次成为您的串行COM API。您可以支持所有具有Javascript和Ajax功能的浏览器( XmlHttpRequest ),只有一个代码库。

  • Write a Windows Service (I assume your machine runs Windows), configure it with necessary privileges. You will have to install something on the machine anyway. The service can be implemented in any language.
  • Add HTTP(S) server capabilities to it. You can use a lot of technologies here from WCF to WebAPI.
  • Invent your own communication protocol over HTTP. You could use JSON, Ajax, WebSockets, SignalR, etc.
  • Write a Javascript file that will be compatible with most browsers on the market - so you only have to write that once - that will become your Serial COM API. You can support all browsers with Javascript and Ajax capabilities (XmlHttpRequest), with only one code base.

下面是它的样子:

Here is how it would look like:

这篇关于如何从用户的串行端口读取网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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