首页 \ 问答 \ 使用vb.net查找gsm调制解调器com端口(find gsm modem com port using vb.net)

使用vb.net查找gsm调制解调器com端口(find gsm modem com port using vb.net)

如何使用vb.net找到gsm调制解调器com端口? 我写这段代码:

Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.IO.Ports

Public Class Form1
'connect your mobile/GSM modem to PC,
'then go in device manager and check under ports which COM port has been slected
'if say com1 is there then put com2 in following statement
Dim SMSEngine As New SMSCOMMS("COM5")
Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    SMSEngine.Open() 'open the port
    SMSEngine.SendSMS() 'send the SMS

End Sub
End Class
Public Class SMSCOMMS
Private WithEvents SMSPort As SerialPort
Private SMSThread As Thread
Private ReadThread As Thread
Shared _Continue As Boolean = False
Shared _ContSMS As Boolean = False
Private _Wait As Boolean = False
Shared _ReadPort As Boolean = False
Public Event Sending(ByVal Done As Boolean)
Public Event DataReceived(ByVal Message As String)

Public Sub New(ByRef COMMPORT As String)
    'initialize all values
    SMSPort = New SerialPort
    With SMSPort
        .PortName = COMMPORT
        .BaudRate = 19200
        .Parity = Parity.None
        .DataBits = 8
        .StopBits = StopBits.One
        .Handshake = Handshake.RequestToSend
        .DtrEnable = True
        .RtsEnable = True
        .NewLine = vbCrLf
    End With
End Sub
Public Function SendSMS() As Boolean
    If SMSPort.IsOpen = True Then
        'sending AT commands
        SMSPort.WriteLine("AT")
        SMSPort.WriteLine("AT+CMGF=1" & vbCrLf) 'set command message format to text mode(1)
        SMSPort.WriteLine("AT+CMGS=""+628988397877""" & vbCrLf) ' enter the mobile number whom you want to send the SMS
        _ContSMS = False
        SMSPort.WriteLine("SUCCESS" & vbCrLf & Chr(26)) 'SMS sending
        SMSPort.Close()
    End If
End Function

Public Sub Open()
    If Not (SMSPort.IsOpen = True) Then
        SMSPort.Open()
    End If
End Sub

Public Sub Close()
    If SMSPort.IsOpen = True Then
        SMSPort.Close()
    End If
End Sub
End Class

但是在这段代码中:

Dim SMSEngine As New SMSCOMMS("COM5")

我需要知道我的调制解调器gsm连接了哪个com端口,所以我需要能够自动找到com端口的代码,有人能帮帮我吗?

非常感谢你。
nb:我使用visual basic 2012(vb.net)


how to find gsm modem com port using vb.net? i writing this code :

Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.IO.Ports

Public Class Form1
'connect your mobile/GSM modem to PC,
'then go in device manager and check under ports which COM port has been slected
'if say com1 is there then put com2 in following statement
Dim SMSEngine As New SMSCOMMS("COM5")
Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    SMSEngine.Open() 'open the port
    SMSEngine.SendSMS() 'send the SMS

End Sub
End Class
Public Class SMSCOMMS
Private WithEvents SMSPort As SerialPort
Private SMSThread As Thread
Private ReadThread As Thread
Shared _Continue As Boolean = False
Shared _ContSMS As Boolean = False
Private _Wait As Boolean = False
Shared _ReadPort As Boolean = False
Public Event Sending(ByVal Done As Boolean)
Public Event DataReceived(ByVal Message As String)

Public Sub New(ByRef COMMPORT As String)
    'initialize all values
    SMSPort = New SerialPort
    With SMSPort
        .PortName = COMMPORT
        .BaudRate = 19200
        .Parity = Parity.None
        .DataBits = 8
        .StopBits = StopBits.One
        .Handshake = Handshake.RequestToSend
        .DtrEnable = True
        .RtsEnable = True
        .NewLine = vbCrLf
    End With
End Sub
Public Function SendSMS() As Boolean
    If SMSPort.IsOpen = True Then
        'sending AT commands
        SMSPort.WriteLine("AT")
        SMSPort.WriteLine("AT+CMGF=1" & vbCrLf) 'set command message format to text mode(1)
        SMSPort.WriteLine("AT+CMGS=""+628988397877""" & vbCrLf) ' enter the mobile number whom you want to send the SMS
        _ContSMS = False
        SMSPort.WriteLine("SUCCESS" & vbCrLf & Chr(26)) 'SMS sending
        SMSPort.Close()
    End If
End Function

Public Sub Open()
    If Not (SMSPort.IsOpen = True) Then
        SMSPort.Open()
    End If
End Sub

Public Sub Close()
    If SMSPort.IsOpen = True Then
        SMSPort.Close()
    End If
End Sub
End Class

but in this code :

Dim SMSEngine As New SMSCOMMS("COM5")

i need to know which com port that my modem gsm was connected, so i need code that can automatically find com port, can someone help me please?

thank you very much.
nb : i use visual basic 2012 (vb.net)


原文:https://stackoverflow.com/questions/12728428
更新时间:2023-06-26 09:06

最满意答案

您正在使用ASP.NET Web API 2的教程,但您选择的项目模板适用于ASP.NET Core。 这是两种不同的野兽。 要学习本教程,您应该从“ASP.NET 4.6.1”区域中选择“Web API”模板,或者使用ASP.NET Core教程

ASP.NET Core( 以前称为ASP.NET 5 )专为多平台开发而设计,并与MVC6一起运行。 官方文档中有一个很好的概念性概述。 以下是与此问题相关的一小部分内容:

在ASP.NET 5中,我们进行了许多架构更改,使核心Web框架更加精简和模块化。 ASP.NET 5不再基于System.Web.dll,而是基于一组精心设计且考虑周全的NuGet包,允许您优化您的应用程序以满足您的需求。

在Core中,所有控制器(包括API控制器)都从Controller基类继承。 DNXCORE50不支持您尝试添加的程序集,因为它们不是跨平台的。


You're using a tutorial for ASP.NET Web API 2, but the project template you've selected is for ASP.NET Core. These are two different beasts. To follow the tutorial, you should select the "Web API" template from the "ASP.NET 4.6.1" area, or use a tutorial for ASP.NET Core.

ASP.NET Core (previous called ASP.NET 5) is designed for multi-platform development and runs with MVC6. There's a nice conceptual overview in the official documentation. Here's a small snippet of it relevant to this question:

With ASP.NET 5 we are making a number of architectural changes that make the core web framework much leaner and more modular. ASP.NET 5 is no longer based on System.Web.dll, but is instead based on a set of granular and well factored NuGet packages allowing you to optimize your app to have just what you need.

In Core, all controllers (including API controllers) inherit from the Controller base class. The assemblies you're trying to add are not supported in DNXCORE50 as they are not cross-platform.

相关问答

更多
  • 对于你的场景,你需要创建一个自定义的IHttpActionResult 。 以下是我从OkNegotiatedContentResult派生的示例,它运行Content-Negotiation并设置Ok状态代码。 public class CustomOkResult : OkNegotiatedContentResult { public CustomOkResult(T content, ApiController controller) : base(cont ...
  • 匿名类型问题的原因是它们是内部类型而不是公共的,所以你的测试不能使用它们。 如果您将一个InternalsVisibleTo属性添加到您的webapi项目中,您将能够通过动态引用结果及其内容,例如: [TestMethod] public void TestGetOrderInfo() { var controller = new OrderController(_repo); dynamic results = controller.GetOrderInfo(46); dynami ...
  • 您可能会决定不使用IHttpActionResult因为您现有的代码构建了一个不符合其中一个已禁止响应的HttpResponseMessage 。 然而,您可以使用ResponseMessage的canned响应将HttpResponseMessage调整为IHttpActionResult 。 花了我一段时间来弄清楚这一点,所以我想发布,显示你不必选择一个或另一个: public IHttpActionResult SomeAction() { IHttpActionResult response; ...
  • 如果要自定义响应消息形状,则需要编写自己的操作结果。 我们想为简单的空404提供最常见的响应消息形状,但我们也希望保持尽可能简单的结果; 使用动作结果的主要优点之一是使您的动作方法更容易进行单元测试。 我们对动作结果越多的属性,您的单元测试需要考虑的更多事情,以确保操作方法正在做您期望的。 我经常想要提供自定义消息的能力,所以请随时记录一个错误,以便我们考虑在将来的版本中支持该操作结果: https : //aspnetwebstack.codeplex.com/workitem/list/advanced ...
  • 取像这样工作 身体方法 每种访问响应主体的方法都会返回一个Promise,当关联的数据类型准备就绪时,Promise将被解析。 text() - 以String形式产生响应文本 json() - 产生JSON.parse(responseText)的结果 blob() - 产生一个Blob arrayBuffer() - 产生一个ArrayBuffer formData() - 产生可以转发到另一个请求的FormData 我认为你需要 return fetch(URL, config) .the ...
  • 来自asp.net web api应用程序的每条消息都会返回一个http状态代码。 一个exception是昂贵的,所以,如果你把它传递给web api,框架应该知道如何领导这个并且改变为http message结果。 没有极端的区别。 web api中的void action方法将返回与200 - OK不同的东西200 - OK如果代码抛出exception则返回200 - OK实际上,我认为它比带结果类型的方法更昂贵,因为asp.net框架需要获取异常并将其更改像我之前说过的那样http message ...
  • 尝试这个 更改您的Get方法以返回"HttpResponseMessage" Public Function [Get](id As Int32) As HttpResponseMessage If Not Remit.IsWithinRemit(id) Then Return Request.CreateResponse(HttpStatusCode.Forbidden, "This data is not within your r ...
  • 您正在使用ASP.NET Web API 2的教程,但您选择的项目模板适用于ASP.NET Core。 这是两种不同的野兽。 要学习本教程,您应该从“ASP.NET 4.6.1”区域中选择“Web API”模板,或者使用ASP.NET Core教程 。 ASP.NET Core( 以前称为ASP.NET 5 )专为多平台开发而设计,并与MVC6一起运行。 官方文档中有一个很好的概念性概述。 以下是与此问题相关的一小部分内容: 在ASP.NET 5中,我们进行了许多架构更改,使核心Web框架更加精简和模块化。 ...
  • 你自己提到了 - 你可以为Ok创建一个重载。 以下是一个完整的例子。 我个人认为单行返回更具可读性。 但它的确有效。 是的 ,它会增加一些开销,因为下面的解决方案使用Action来处理void方法。 但它可以做到 ......而且,await await-part显示了一些代码味道。 为了清楚起见,我调用了我的方法MyOk而不是实际覆盖Ok 。 public class FooController : ApiController { [HttpGet] public async Task
  • HttpContext.Current.IsDebuggingEnabled 此属性实际上查看web.config配置设置及其仅在HttpContext中。 以下应该工作: var cfg =(System.Web.Configuration.CompilationSection)ConfigurationManager.GetSection("system.web/compilation"); if (cfg.Debug) { ... } HttpContext.Current.IsDebugging ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)