dadibarca23
Messages postés71Date d'inscriptionmercredi 3 octobre 2012StatutMembreDernière intervention 6 octobre 2019
-
Modifié par NHenry le 17/02/2016 à 18:56
vb95
Messages postés3416Date d'inscriptionsamedi 11 janvier 2014StatutContributeurDernière intervention31 mai 2023
-
18 févr. 2016 à 21:55
Bonjour,
sa s'est une commande pour vérifier le solde de gsm atacher vb.net
comme j’utilise le BackgroundWorker ne répond pas au le programme afficher :no more port
aider mois svp et merci
Imports AxMmCtlLib
Imports System.ComponentModel
Public Class Form1
Dim strResponse As String = ""
Dim strCommand As String = ""
Dim strFields As String()
Dim Counter1 As Integer = 0
Dim objGsm As Gsm = New Gsm
Dim objSmsConstants As SmsConstants = New SmsConstants
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
chercheports()
End Sub
Sub chercheports()
Dim strDevice As String
Dim strPort As String
' Fill devices Combo
cbxDevices.Items.Clear()
' Gets first TAPI device
strDevice = objGsm.FindFirstDevice()
While (objGsm.LastError = 0)
cbxDevices.Items.Add(strDevice)
' Gets next TAPI device.
strDevice = objGsm.FindNextDevice()
End While
' Add COM ports.
' Gets first COM port.
strPort = objGsm.FindFirstPort()
While (objGsm.LastError = 0)
' LESPORT.cbxDevices3.Items.Add(strPort)
cbxDevices.Items.Add(strPort)
'Gets next COM port.
strPort = objGsm.FindNextPort()
End While
If (cbxDevices.Items.Count > 0) Then
'LESPORT.cbxDevices3.SelectedIndex = 0
cbxDevices.SelectedIndex = 0
Else
' Remove previous text from cbx (happens when a user reopens this forms
' and removed all devices and COM ports)
cbxDevices.Text = String.Empty
End If
'Fill deviceSpeed combo
cbxDeviceSpeed.Items.Clear()
cbxDeviceSpeed.Items.Add(objSmsConstants.GSM_BAUDRATE_115200)
cbxDeviceSpeed.SelectedIndex = 0
End Sub
Sub UpdateResult(ByVal nResult As Integer)
TextBox4.Text = (String.Format("{0}: {1}", nResult, objGsm.GetErrorDescription(objGsm.LastError)))
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BGW.RunWorkerAsync()
End Sub
Private Sub solde()
strCommand = String.Format("AT+CUSD=1," & Chr(34) & "{0}" & Chr(34) & ",15", "*" & "710" & "#")
Dim strName As String = cbxDevices.Text
Dim iDeviceSpeed As Integer
If (Not Integer.TryParse(cbxDeviceSpeed.Text, iDeviceSpeed)) Then
End If
objGsm.Open(strName, "0000", iDeviceSpeed)
If (objGsm.LastError <> 0) Then
If (objGsm.LastError = 36103) Then
MessageBox.Show("Invalid Pin entered: SIM card can be blocked after a number of false attempts in a row.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
If (objGsm.LastError = 0) Then
objGsm.SendCommand(strCommand)
End If
' Reads the response from the GSM Modem
If (objGsm.LastError = 0) Then
strResponse = objGsm.ReadResponse(10000)
End If
If (objGsm.LastError = 0) Then
If (strResponse.Contains("OK")) Then ' Response should be OK
objGsm.SendCommand(String.Empty)
strResponse = objGsm.ReadResponse(10000)
If (objGsm.LastError <> 0) Then
UpdateResult(objGsm.LastError)
Return
End If
If (strResponse.Contains("+CUSD:")) Then
strFields = strResponse.Split(Char.Parse(Chr(34)))
If (strFields.Length > 1) Then
strResponse = strFields(0)
Else
strResponse = strFields(1)
End If
End If
End If
End If
TextBox5.Text = strResponse
UpdateResult(objGsm.LastError)
objGsm.Close()
End Sub
Private Sub BGW_DoWork(sender As Object, e As DoWorkEventArgs) Handles BGW.DoWork
solde()
End Sub
Private Sub BGW_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BGW.RunWorkerCompleted
MsgBox("Mission complete")
End Sub
End Class
EDIT : Ajout des balises de code (la coloration syntaxique). Explications disponibles ici : ICI
Dim strName As String = cbxDevices.Text
Dim iDeviceSpeed As Integer
If (Not Integer.TryParse(cbxDeviceSpeed.Text, iDeviceSpeed)) Then
End If
objGsm.Open(strName, "0000", iDeviceSpeed)
If (objGsm.LastError <> 0) Then
If (objGsm.LastError = 36103) Then
MessageBox.Show("Invalid Pin entered: SIM card can be blocked after a number of false attempts in a row.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
If (objGsm.LastError = 0) Then
objGsm.SendCommand(strCommand)
End If
' Reads the response from the GSM Modem
If (objGsm.LastError = 0) Then
strResponse = objGsm.ReadResponse(10000)
End If
If (objGsm.LastError = 0) Then
If (strResponse.Contains("OK")) Then ' Response should be OK
objGsm.SendCommand(String.Empty)
strResponse = objGsm.ReadResponse(10000)
If (objGsm.LastError <> 0) Then
UpdateResult(objGsm.LastError)
Return
End If
If (strFields.Length > 1) Then
strResponse = strFields(0)
Else
strResponse = strFields(1)
End If
End If
End If
End If
TextBox5.Text = strResponse
UpdateResult(objGsm.LastError)
objGsm.Close()
End Sub
Private Sub BGW_DoWork(sender As Object, e As DoWorkEventArgs) Handles BGW.DoWork
solde()
End Sub
mais aucune réponse
vb95
Messages postés3416Date d'inscriptionsamedi 11 janvier 2014StatutContributeurDernière intervention31 mai 2023165
>
dadibarca23
Messages postés71Date d'inscriptionmercredi 3 octobre 2012StatutMembreDernière intervention 6 octobre 2019 18 févr. 2016 à 18:35
18 févr. 2016 à 13:15
Private Sub solde()
strCommand = String.Format("AT+CUSD=1," & Chr(34) & "{0}" & Chr(34) & ",15", "*" & "710" & "#")
Dim strName As String = cbxDevices.Text
Dim iDeviceSpeed As Integer
If (Not Integer.TryParse(cbxDeviceSpeed.Text, iDeviceSpeed)) Then
End If
objGsm.Open(strName, "0000", iDeviceSpeed)
If (objGsm.LastError <> 0) Then
If (objGsm.LastError = 36103) Then
MessageBox.Show("Invalid Pin entered: SIM card can be blocked after a number of false attempts in a row.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
If (objGsm.LastError = 0) Then
objGsm.SendCommand(strCommand)
End If
' Reads the response from the GSM Modem
If (objGsm.LastError = 0) Then
strResponse = objGsm.ReadResponse(10000)
End If
If (objGsm.LastError = 0) Then
If (strResponse.Contains("OK")) Then ' Response should be OK
objGsm.SendCommand(String.Empty)
strResponse = objGsm.ReadResponse(10000)
If (objGsm.LastError <> 0) Then
UpdateResult(objGsm.LastError)
Return
End If
If (strResponse.Contains("+CUSD:")) Then
strFields = strResponse.Split(Char.Parse(Chr(34)))
If (strFields.Length > 1) Then
strResponse = strFields(0)
Else
strResponse = strFields(1)
End If
End If
End If
End If
TextBox5.Text = strResponse
UpdateResult(objGsm.LastError)
objGsm.Close()
End Sub
Private Sub BGW_DoWork(sender As Object, e As DoWorkEventArgs) Handles BGW.DoWork
solde()
End Sub
mais aucune réponse
18 févr. 2016 à 18:35
A lire avec attention et surtout la partie traitant des Threads avec un BackGroundWorker
http://plasserre.developpez.com/cours/vb-net/
et tu as oublié http://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
Quant à la solution on ne fait pas dans le "tout-cuit" ( voir les règles de ce forum
18 févr. 2016 à 21:55