Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB.NET
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
                    '.PortName = Trim(Mid(ComboBox1.Text, 1, 5))
                    .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) 'send whatever data that it receives to serial port  
                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) 'Instruct the GSM / GPRS modem to operate in SMS text mode
                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..
Posted
Updated 20-Dec-16 6:08am

1 solution

Serial ports are exclusive. While a serial port is opened by an application, it can't be opened anymore by another (or even the same) application.

The solution coming into mind for your problem is performing the same tasks as the GSM module software to initialise the modem. Then you don't need that software anymore and can send your SMS.

Regarding the diagnostics port you should consult the modem manual. But it is rather improbable that it can be used to send SMS. Such ports are usually providing only status information.
 
Share this answer
 
Comments
kenchidag 3-Jan-17 19:51pm    
Thanks Jochen Arndt, much appreciated. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900