أصف Serialport و Textbox لعرض النتائج
صع في خصائص الـــ serialport
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles Serialport1.DataReceived
ReceivedText(Serialport1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String) 'input from ReadExisting
If Me.TextBox1.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.TextBox1.Text &= [text] 'append text
End If
End Sub
ثم أضف button وصع الآكشن كالتالي :
On Error Resume Next
With Serialport1
.PortName = Comstar.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
.RtsEnable = True
.ReceivedBytesThreshold = 100
.NewLine = vbCr
.ReadTimeout = 100000
.Open()
Console.WriteLine("Open the serial port.")
End With
' Send USSD Command
Serialport1.Write("ATDT," & Chr(34) & "*100#" & Chr(34) & ",15" + Chr(13))
Console.WriteLine("Read the OK response data in the serial port.")
Serialport1.Encoding.GetDecoder()
If Serialport1.ReadExisting = "OK" Then
Serialport1.NewLine = "1"
End If
' Response should be OK
Dim strResponse2 As String
strResponse2 = Serialport1.ReadExisting.Length
' Wait for response
ستعرض الشبكة لك خيارات يمكنك الرد بالتالي :
' Send réponse 2
Serialport1.newline = "ATDT" & Chr(34) & "*100#" & Chr(34) & ",15" + Chr(13)
Console.WriteLine("Read the OK response data in the serial port.")
Serialport1.Encoding.GetDecoder()
If Serialport1.ReadExisting = "OK" Then
Serialport1.NewLine = "1"
End If
' Response should be OK
Dim strResponse2 As String
strResponse2 = Serialport1.ReadExisting.Length
' Wait for response
ملاحظة : Comstar.Text هي Combox ويجب أن تضع كود الخاص بإضافة كل البورت المفتوح لها
صع في خصائص الـــ serialport
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles Serialport1.DataReceived
ReceivedText(Serialport1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String) 'input from ReadExisting
If Me.TextBox1.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.TextBox1.Text &= [text] 'append text
End If
End Sub
ثم أضف button وصع الآكشن كالتالي :
On Error Resume Next
With Serialport1
.PortName = Comstar.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
.RtsEnable = True
.ReceivedBytesThreshold = 100
.NewLine = vbCr
.ReadTimeout = 100000
.Open()
Console.WriteLine("Open the serial port.")
End With
' Send USSD Command
Serialport1.Write("ATDT," & Chr(34) & "*100#" & Chr(34) & ",15" + Chr(13))
Console.WriteLine("Read the OK response data in the serial port.")
Serialport1.Encoding.GetDecoder()
If Serialport1.ReadExisting = "OK" Then
Serialport1.NewLine = "1"
End If
' Response should be OK
Dim strResponse2 As String
strResponse2 = Serialport1.ReadExisting.Length
' Wait for response
ستعرض الشبكة لك خيارات يمكنك الرد بالتالي :
' Send réponse 2
Serialport1.newline = "ATDT" & Chr(34) & "*100#" & Chr(34) & ",15" + Chr(13)
Console.WriteLine("Read the OK response data in the serial port.")
Serialport1.Encoding.GetDecoder()
If Serialport1.ReadExisting = "OK" Then
Serialport1.NewLine = "1"
End If
' Response should be OK
Dim strResponse2 As String
strResponse2 = Serialport1.ReadExisting.Length
' Wait for response
ملاحظة : Comstar.Text هي Combox ويجب أن تضع كود الخاص بإضافة كل البورت المفتوح لها
