0

我用 Visual Basic 2010 Express 构建了一个 DLL。它建立在 VB 4.0 框架之上。构建后,我在管理员命令提示符下运行:

C:\windows\...v4.0.30319\RegAsm C:\...\bin\release\ClassLibrary1.dll

COM-visible 复选框已被选中。但是我的其他程序无法连接到它,标题中提到了错误消息。

类库仅包含 1 个类。它在 SMSCOMMS.vb 中:

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

Public Class SMSCOMMS
  Private WithEvents SMSPort As SerialPort
  Private SMSThread As Thread
  Private ReadThread As Thread
  Shared _ReadPort As Boolean = False
  Public Event Sending(ByVal Done As Boolean)
  Public Event DataReceived(ByVal Message As String)
  Public Sub New()
  End Sub
  Public Sub initPort(ByVal COMMPORT As String)
    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 testFunction() As Integer
    Return 1
  End Function

  Public Function SendSMS(ByVal receiver As String, ByVal message As String) As Boolean
    If SMSPort.IsOpen = True Then
      'sending AT commands
      SMSPort.WriteLine("AT+CMGF=1" & Chr(13)) 'set command message format to text mode(1)
      'SMSPort.WriteLine("AT+CSCA=+639170000130" & Chr(13)) 'set service center address (which varies for service providers (idea, airtel))
      SMSPort.WriteLine("AT+CMGS=" & Chr(34) & receiver & Chr(34) & Chr(13)) ' enter the mobile number whom you want to send the SMS
      SMSPort.WriteLine(message & Chr(26)) 'SMS sending
      SMSPort.Close()
      Return True
    End If
    Return False
  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
4

1 回答 1

0

我改用了 Visual Basic 2012。Com interop 有一个复选框。

于 2013-05-19T14:39:26.217 回答