Hi all,, I am currently developing an app in vb to send sms, however when i try to open the port in which the gsm module is attach it always says "the requested resource is in use" thus I cannot open the port to used. I found it that this occurs when the software of the GSM module is running, I tried closing it but the GSM modem loses its signal and becomes red status. Also in Device Manager it shows two ports for the GSM modem, one is for ZTE NMEA and the other is ZTE Diagnostics Services.
Im unable to use the port for the ZTE NMEA since it seems its currently the one in used,, and tried the other port but no success in sending a message thru vb. However, I can send a message thru the GSM module directly. Is there any workaround on this. thanks in advance.
here is my code:
Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
If SerialPort2.IsOpen = True Then
SerialPort2.Close()
btnConnect.Text = "Connect"
Else
Try
With SerialPort2
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.None
.RtsEnable = True
.DtrEnable = True
.Open()
.WriteLine("AT+CNMI=1,2,0,0,0" & vbCrLf)
End With
MsgBox("Connected")
btnConnect.Text = "Disconnect"
Catch ex As Exception
btnConnect.Text = "Connect"
MsgBox(ex.Message)
End Try
End If
End Sub
Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
Try
With SerialPort2
.WriteLine("AT" & vbCrLf)
Threading.Thread.Sleep(1000)
.WriteLine("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(1000)
.WriteLine("AT+CMGS=" & Chr(34) & txtnum.Text & Chr(34) & vbCr)
Threading.Thread.Sleep(1000)
.WriteLine(txtmssge.Text & Chr(26))
End With
MsgBox("Message Sent")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
What I have tried:
I have tried googling for the solution but they only show codes for sending the SMS thru vb. I tried using both the ports but no luck at all. Its just weird that i cannot close the port and reopen it for used, or does the GSM module cannot be used for this app..