Sub ConnectToWiFiPrinter_and_then_Print
' Process for Printing
Dim strDesired_WiFi_SSID As String = "SSID OF THE DESIRED PRINTER GOES HERE"
' See if We are connected
If Not ( wifi.isWifiConnected )Then
' Connect to WiFi
wifi.EnableWifi(True)
' Wait for WiFi Connection
Dim startWaitTime As Long = DateTime.Now
Do Until (wifi.isWifiConnected)
DoEvents
' Make sure we can break out if this is going on forever
If DateTime > startWaitTime + 3000 Then ' check if over 3 seconds
Dim result As Int
result = Msgbox2("Continue to Wait ? ", "Waiting for WiFi", "Yes", "" , "No", Null)
If result = DialogResponse.Positive Then
' User ok to wait, reset startWaitTime for next interval
startWaitTime = DateTime.Now
Else
Msgbox("No WiFi Printer found, Exiting Printing", "WiFi Status")
Return ' Don't bother with printing
' NOTE - append a note to e-mail that Printing failed
' or ask user to write Ticket # down somewhere
End If
End If
Loop ' WiFi.IsOnline
End If
' Scan for the desired printer WiFi
' ' Scan only once in app
' ' After that use Update
' ' WifiScanner.startScan("WifiScanner") ' Will trigger ScanDone ' orriginally passed "Scan"
WifiScanner.updateWifiList
DoEvents
' Go through list of WiFis found and get Entry Number of desired SSID
Dim CommaLocation As Int
Dim tmpString As String
Dim strEntry As String
Dim EntryNumber As Int
EntryNumber = -1
Dim i As Int
For i = 0 To WifiScanner.Wifis.Length - 1
tmpString = WifiScanner.Wifis(i)
CommaLocation = tmpString.IndexOf(",")
strEntry = tmpString.SubString2(0, CommaLocation)
If (strEntry = strDesired_WiFi_SSID ) Then EntryNumber = i
Next
' Abandon Printing if Printer's WiFi is not found
If EntryNumber =-1 Then
Msgbox ("Desired SSID not found, Exiting ", "WiFi Printer lblStatus")
Return
End If
' When WiFi connection is made, check that it is proper SSID
If Not (wifi.SSID = strDesired_WiFi_SSID ) Then
Msgbox("WiFi found but wrong SSID - waiting to connect to Printer", "WiFi Status")
' connect to the desired device
WifiScanner.connectToAP(EntryNumber)
'Wait to connect to this device
startWaitTime = DateTime.Now
Do Until (wifi.SSID = strDesired_WiFi_SSID )
DoEvents
' Make sure we can break out if this is going on forever
If DateTime > startWaitTime + 3000 Then ' check if over 3 seconds
Dim result As Int
result = Msgbox2("Continue to Wait ? ", "Waiting for WiFi", "Yes", "" , "No", Null)
If result = DialogResponse.Positive Then
' User ok to wait, reset startWaitTime for next interval
startWaitTime = DateTime.Now
Else
Msgbox("Desired Printer not found, Exiting Printing", "Printer Access Status")
Return ' Don't bother with printing
' NOTE - append a note to e-mail that Printing failed
' or ask user to write Ticket # down somewhere
End If
End If
Loop
End If
Print ' Goes to print routine
'After Printing, Disconnect from wifi if printer network doesn't have internet
'This allows us to be ready to use Cellular internet elsewhere in the app
If wifi.Isonline = False Then wifi.EnableWifi(False)
End Sub