无法在asp.net中打开COM端口
我按照这篇文章发送 SMS 它是一个 winform 应用程序..我有将所有 Dll 引用到我的 asp.net 应用程序......
我使用 aspx 页面来检测连接到 PC 的移动设备......但它总是显示 COM 'n' Port 无法打开
.....
using SMS;
using GsmComm.GsmCommunication;
using GsmComm.PduConverter;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GsmCommMain comm = new GsmCommMain(6, 9600, 300);
comm.Open();
if (!comm.IsConnected())
{
Response.Write("No Phone Connected");
}
else
{
SmsSubmitPdu pdu = new SmsSubmitPdu("test", "+919999999999", "");
CommSetting.comm.SendMessage(pdu);
}
}
}
编辑:
我使用 Visual Studio 附带的 Web 开发服务器...如果转到控制面板 ->电话和调制解调器 ->调制解调器
我可以看到我的手机已连接到 com6...
我已经测试了 winform 应用程序,它工作正常...
这是答案吗?
ASP.NET 页面应该可以工作。 这里发生的事情是 当您单击 open_com 按钮时, ASP.NET 页面回发给自身, 执行事件处理程序,即打开 港口。然后当页面完成时 处理回发,是 卸载。此时COM1 对象也被破坏。
I following this article for sending SMS it is a winform application.. I have referenced all the Dll's to my asp.net application.....
I use an aspx page to detect a mobile device connected to a PC..... But it alwys shows COM 'n' Port could not be opened
.....
using SMS;
using GsmComm.GsmCommunication;
using GsmComm.PduConverter;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GsmCommMain comm = new GsmCommMain(6, 9600, 300);
comm.Open();
if (!comm.IsConnected())
{
Response.Write("No Phone Connected");
}
else
{
SmsSubmitPdu pdu = new SmsSubmitPdu("test", "+919999999999", "");
CommSetting.comm.SendMessage(pdu);
}
}
}
EDIT:
I use the web development server that ships with Visual Studio... If go to Control Panel -> Phones & Modems -> Modems
i could see my mobile connected in com6...
i have tested the winform application it works fine...
Is this the answer?
ASP.NET pages are supposed to work.
What is happening over here is that
when you click on open_com button, the
ASP.NET page posts back to itself,
executes the event handler i.e., opens
the port. Then when the page finishes
processing the post back, it is
unloaded. At this point the COM1
objects is also destroyed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用哪个网络服务器?如果它是 Visual Studio 附带的 Web 开发服务器?然后它应该可以工作了。如果您想让它与 IIS 一起工作,您需要使用模拟或在具有管理员权限的不同安全上下文中运行 ASP.net 工作进程。
还要首先尝试在控制台应用程序中测试您的示例。
Which webserver are you using? If its the web development server that ships with Visual Studio? Then it should be working. If you want to get it working with IIS you need to use impersonation or run the ASP.net worker process in a different security context with admin privileges.
Also try to test your sample in a console application first.
这很可能是权限。
除非您使用模拟,否则该站点将以具有非常低权限的 ASPnet 用户身份运行。将站点设置为模拟管理员用户,或将站点设置为以高权限用户身份运行。
或者,我个人的建议是使用在线服务,例如 http://www.clickatell.com/发送和接收短信。它更容易,更便宜,而且更强大。
It's most likely permissions.
Unless you are using impersonation the site will run as the ASPnet user which has very low privileges. Either set the site to impersonate an admin user, or set the site to run as a high priviledge user.
Alternatively, and my personal recommendation, rather use an online service like http://www.clickatell.com/ to send and receive SMSes. It's a heck of a lot easier, it's cheaper, and it's more robust.