Click here to Skip to main content
15,881,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI
I am working on an application In VB.Net using AT commands to detect Comport, IMEI, IMSI, Mobile Model etc. of all Mobile Devices connected Via USB with Computer.

I want to display list of each Comport mapped with its IMEI,etc.
Like:-

Com1 Model IMEI IMSI

Com2 Model ImEI IMSI

..........so on.........

So, please explain how to proceed.

I used below code:-
VB
Imports System.Windows
Imports System.IO.Ports

Public Class Form1

    Dim SerialPort As New System.IO.Ports.SerialPort
    Private lsp As New List(Of SerialPort)
    Dim scana As Boolean

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        For Each sname As String In My.Computer.Ports.SerialPortNames
            lsp.Add(My.Computer.Ports.OpenSerialPort(sname))
        Next
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        scana = True
        
            For Each sp As SerialPort In lsp
                My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Temp + "\MobileConnect.log", "", False)

                My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Temp + "\MobileConnect.log", "Current Modem:" + ControlChars.NewLine, True)
                sp.WriteLine("ATI3" + Chr(13))
                Threading.Thread.Sleep(100)

                My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Temp + "\MobileConnect.log", "IMEI:" + ControlChars.NewLine, True)
                sp.WriteLine("AT+CGSN" + Chr(13))
                Threading.Thread.Sleep(1000)

                My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Temp + "\MobileConnect.log", "IMSI:" + ControlChars.NewLine, True)
                sp.WriteLine("AT+CIMI" + Chr(13))
                Threading.Thread.Sleep(100)

                RichTextBox2.Text = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Temp + "\MobileConnect.log")
                scana = False
            Next
            
            Label4.Text = "Scanning Finished"


        Catch
            Label4.Text = "Scanning Error"
            scana = False
        End Try
    End Sub

Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
        If scana = True Then
            My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Temp + "\TMobMgr.log", SerialPort.ReadExisting, True)
        End If
End Sub
End Class




When running, code doesn't execute after line- sp.WriteLine("ATI3" + Chr(13))
Please check

Thanks,

Jatin
Posted
Updated 2-Apr-13 1:54am
v3
Comments
[no name] 2-Apr-13 9:13am    
Probably because you are just blindly sending commands to the serial ports without setting them up, opening them for communication, or knowing that the device attached to the serial port supports the commands you are sending to it.
jatin77 3-Apr-13 11:01am    
Okay..Please Guide how to open the communication port and about setting up the Port.
Also when i detect the available COM ports , i got Two Com Ports(one sending,one receiving) for each Mobile Device. When i send command to receiving Com Port, it works.
So,how to determine the receiving Com Port?

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