manika87 0 Newbie Poster

I need a coding to execute multiple at commands simultaneously. when first command execute and get the response from the port and then the second command will be executed. how to write the coding. it is possible. i am using siemens gsm modem.

FOR example.

1. AT
OK
2. AT+CPIN?
+CPIN: READY
OK
3. AT+CGMI
SIEMENS
OK
4. AT+CSQ
+CSQ: 27,99
OK

I try the following vb.net coding.

Imports System.IO.Ports
     Public Class Form1
       
            Dim WithEvents serialport1 As New SerialPort("COM13")
            Dim tempstr as String=""
            Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles MyBase.Load
              SerialPort1.BaudRate = 19200
              SerialPort1.Parity = IO.Ports.Parity.None
              SerialPort1.StopBits = IO.Ports.StopBits.One
              SerialPort1.DataBits = 8
              SerialPort1.Open()
           End Sub

           Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
              SerialPort1.Close()
           End Sub

           Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
               tempstr=""
               serialport1.Write("AT" & vbCr)                     
               serialport1.Write("AT+CPIN?" & vbCr)      
               serialport1.Write("AT+CGMI" & vbCr)      
               serialport1.Write("AT+CSQ" & vbCr)                     
           End Sub

           Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
               If tempstr <> "" Then
                  TextBox2.Text += tempstr
               End If
           End Sub

           Private Sub serialport1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialport1.DataReceived
               tempstr = serialport1.ReadExisting
           End Sub
    End Class

when i execute this coding i can't get the correct result because the port response will take some times. how can i identify the time delay. when i use thread.sleep(300) means this is also not correct for my solution. Because the port response will take more than 300 milliseconds?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.