502
Platforms
©2000-2008 Tibbo Technology Inc.
'THE BULLETPROOF WAY...
...
While
wln.task<>PL_WLN_TASK_IDLE
'waiting for the previous task to
complete...
Wend
If
wln.scan("NET1")<>ACCEPTED
Then
'Handle this...
End
If
While
wln.task<>PL_WLN_TASK_IDLE
'waiting for the scan to complete...
Wend
'did we find this network?
If
wln.scanresultssid<>"NET1"
Then
'Network was not found -- handle that...
End
If
'start next task here
One problem with the code in the above examples is that it is, essentially,
blocking. Your application is not doing anything useful while the Wi-Fi interface is
scanning, then idling while the Wi-Fi is associating, and so on.
To take advantage of the event-driven nature of the system, you can base your
Wi-Fi control on the
event which is generated each time
a task is completed. Completed_task argument of the event handler carries the
code of the event that has been completed. Therefore, you can advance through
steps in this manner:
'THIS CODE TAKES FULL ADVANTAGE OF THE EVENT-DRIVEN NATURE OF THE SYSTEM
'-------------------------------------------
Sub
On
_sys_init
...
wln.settxpower(14)
'issue the task and don't wait
End
Sub
'-------------------------------------------
Sub
On
_wln_task_complete(completed_task
As
pl_wln_tasks)
Select
Case
completed task
Case
PL_WLN_TASK_SETTXPOWER:
'here when wln.settxpower completes (we started it in the
on_sys_init)
wln.scan("NET1")
'TX power set, now scan
Case
PL_WLN_TASK_SCAN:
'scan completed, now associate
wln.associate(wln.scanresultbssid,"NET1",wln.scanresultchannel,wln.scanres
ultbssmode)
Case PL_WLN_TASK_ASSOCIATE:
'... continue in this fashion
End
Select
End
Sub
'-------------------------------------------
Sub
On
_wln_event(wln_event
As
pl_wln_events)
'here we catch hardware problems and disassociations -- also
asynchronously
End
Sub
Notice the
in the code above. It allows us to catch "problems".
523
522