293
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
Each time the socket state changes an
event is generated.
Unlike many other events, this one can be generated again and again before the
on_sock_event handler is invoked, so event queue can contain multiple such
events. A separate event is generated for each new state the socket enters.
The on_sock_event "brings" two arguments with it -- one is called "newstate",
another one -- "newstatesimple". These arguments contains the state of the socket
at the moment when the on_sock_event was generated.
Newstate and newstatesimple arguments have been introduced in Tibbo Basic
V2.0
. Before, their role was played by two read-only properties --
and
. These properties are no longer available.
Here is one example of how on_sock_event can be used. Supposing, when
connection is established we need to open the serial port and when it is no longer
established close the serial port and clear the data from its TX and RX buffers:
sub
on_sock_event(newstate
as
pl_sock_state,newstatesimple
as
pl_sock_state_simple)
if
newstatesimple= PL_SSTS_EST
then
ser.enabled= YES
'connection has been established- open port
else
if
ser.enabled= YES
then
'connection is NOT established? Close and
clear the port if it is opened!
ser.enabled= N0
ser.txclear
ser.rxclear
end
if
end
if
end
sub
Sock.state and sock.statesimple read-only properties
There is also a pair of read-only properties-
and
-
that allows you to check current socket state (as opposed to the state that was at
the moment of on_sock_event generation).
Here is an example of how you can use this. Supposing, you want to "play" an LED
pattern that depends on the current state of the socket. Here is how you do this:
sub
on_pat
'this event is generated each time a pattern finishes playing
select
case
sock.statesimple
case
PL_SSTS_EST:
'connection is established- Green LED on
pat.set(
"GGGGGGGGGGGGGGGG"
,NO)
case
PL_SSTS_ARP:
'ARP in progress- Green LED blinks
pat.set(
"G-G-G-G-G-G-G-G-"
,NO)
case
PL_SSTS_PO:
'connection is being established- green LED goes
'blink-blink-blink'
pat.set(
"----------G-G-G-"
,NO)
case
PL_SSTS_AO:
'connection is being established- green LED goes
'blink-blink-blink'
pat.set(
"----------G-G-G-"
,NO)
case
else
:
'connection is closed or being closed- green LED is
'blink-blink'
pat.set(
"------------G-G-"
,NO)
end
select
end
sub
Understanding who you are talking to
343
332
332
355
358