将 Silverlight 连接到本地计算机的 COM 端口
我一直在寻找一种方法让我的 silverlight 应用程序与本地计算机上的 COM 端口进行通信。 有没有人能够让 Silverlight 成功连接到您本地计算机的 COM 端口? 如果是这样,你能指出我的文档吗?
I have been searching high and low for a way to get my silverlight application talking to the COM port on my local computer. Has anybody out there been able to get Silverlight to successfully connect to the COM port of you local computer? If so can you point me to the documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
Silverlight 无法做到这一点。
为什么不直接使用标准的 .NET 桌面应用程序? 如果您需要通过网络轻松部署,只需使用 Click-Once 进行部署。
This can not be done with Silverlight.
Why not just use a standard .NET desktop app? If you need to easily deploy over the web, just use Click-Once for deployment.
无法访问计算机资源,但可以与套接字进行通信。 因此,您的用户可以安装一个应用程序来侦听端口并与 COM 端口进行通信。
为什么要尝试与 COM 端口通信? 如果您正在寻找网络摄像头支持,请查看 Jonas 的 hack,它使用 Flash 获取网络摄像头输入:
http://jonas.follesoe.no/WebcamInSilverlight2MacGyverStyle.aspx
There's no access to computer resources, but you can communicate with sockets. So it's possible to have your users install an application which listens on a port and communicates with a COM port.
Why are you trying to communicate with a COM port? If you're looking for webcam support, take a look at Jonas's hack which uses Flash to get webcam input:
http://jonas.follesoe.no/WebcamInSilverlight2MacGyverStyle.aspx
您可以通过打开从 Silverlight 控件到本地套接字的套接字连接来完成此操作,该套接字具有 COM 端口访问权限
You can do this by opening a socket connection from your Silverlight control to a local socket which intern have the COM port access
Silverlight 4 使您能够与 COM (ActiveX) 进行通信。 我写了一篇关于如何与支持串口通信的COM库进行通信的博客文章。
http://tech-michael.blogspot.com/ 2009/12/silverlight-talking-to-arduino.html
请注意,提到的 ActiveXperts 对象是商业性的。
Silverlight 4 enables you to communciate with COM (ActiveX). I have written a blog article about how to communicate with a COM library that supports communicating with the serial port.
http://tech-michael.blogspot.com/2009/12/silverlight-talking-to-arduino.html
Note that the ActiveXperts-object mentioned is commercial.
我认为这些人总结得很好 - Silverlight 位于一个严格的沙箱中,您将无法访问 COM 端口或其他本地资源。
因此,让我们开始考虑替代方案:
干杯,
乔纳斯
I think the guys have summed it up nicely - Silverlight is in a tight sandbox and you will not get access to the COM port or other local resources.
So let's start to think about alternatives:
Cheers,
Jonas
您仍然可以在浏览器外运行它并使用像
http://interopcom.codeplex.com/ 这样的包装器(我写的)
问候,
保罗
You can still run it out of browser and utilise a wrapper like
http://interopcom.codeplex.com/ (written by me)
Regards,
Paul
本地计算机是指运行 silverlight 客户端应用程序的计算机吗? Silverlight 运行在安全沙箱中,您能否像这样连接到硬件资源值得怀疑。
By local computer do you mean the computer the silverlight client app is running on? Silverlight runs in a security sandbox, and it is doubtful you can connect to hardware resources like so.
乔恩,
我实际上正在尝试从 Silverlight 读取我的 GPS。 我有一个有趣的概念想要尝试,但我试图实现零安装足迹。
Jon,
I am actually trying to read my GPS from Silverlight. I have an interesting concept that I wanted to try out, but I was trying to go for a zero install footprint.
如果您希望您的应用程序在 Windows 和 Mac 上运行怎么办? Silverlight 是一个很好的解决方案,因为它可以在两者上运行。 如果您必须编写 WPF 应用程序或 ActiveX 控件等,这将再次将您绑定到 Windows。
What if you want your application to run on Windows and Mac? Silverlight is a nice solution since it runs on both. If you have to write a WPF app or an ActiveX control, etc., this will bind you to Windows only again.
您可以将 Silverlight 5 连接到本地通信端口以及任何其他本地资源,但仅限于 Silverlight 应用程序在 Windows(而非 Mac)下运行并且在 Internet 中运行 OOB(浏览器外)或浏览器内时探险家。
完成此操作的方法是创建一个经典 COM 自动化组件,并以完全信任的方式运行应用程序。 您可以设置一个注册表项,以允许 Silverlight 5 应用程序能够在浏览器中以完全信任的方式运行,但必须对应用程序进行签名,并且必须将公钥导入到本地计算机上的受信任发布者。
完成后,Silverlight 支持 AutomactionFactory,允许您访问本地注册的 com 自动化对象。 我们广泛使用此功能; 它非常强大。 在本例中,我们创建了一个 COM 组件来访问 SerialPort 对象,并为其提供了一个方法来返回所有可用端口的列表。
You can connect Silverlight 5 to the local Comm Port as well as any other local resource, but only with the Silverlight application is running under Windows (not Mac) and when running either OOB (out-of-browser) or in-browser in Internet Explorer.
The way this is done is by creating a classic COM automation component, and running the application with Full Trust. There is a registry key you can set to allow Silverlight 5 applications to be able to run with full trust in-browser, but the application must be signed and the public key must be imported to trusted publishers on the local machine.
Once done, Silverlight supports AutomactionFactory, allowing you to access locally registered com automation objects. We use this feature extensively; it is very powerful. In this case we created a COM component that gives access to the SerialPort object, and gave it a method to return a list of all available ports.