SetInterfaceEvent Procedure

Sets an event procedure that will be called when a specified interface event occurs.

Syntax

[ lStatus = ] SetInterfaceEvent ( enInterfaceType, lAddress, enCauseMask, proc )

The SetInterfaceEvent procedure syntax has the following parts:

 

Name

Type

Description

lStatus

Val Long

Status: 0 = successful, -1 = error.

enInterfaceType

Val enumAInterfaceType

Type of interface

lAddress

Val Long

Address of the interface

enCauseMask

Val enumAInterfaceEvents

Mask value describing what kind of procedure to call

proc

Val Proc

The interface event procedure/callback that will be called by ATEasy when the event occurs

Where

enumAInterfaceType can be one of the following:

 

Name

Value

Description

aioNone

0

None (Not applicable)

aioGpib

1

GPIB

aioCom

2

COM

aioVxi

3

VXI

aioFile

4

File (Not applicable)

aioIsa

5

ISA (Not applicable)

aioWinSock

6

Winsock

aioUsb

7

USB (v7.0)

enumAInterfaceEvents can be one or a combination of the following values:

 

Name

Value

Description

aioComBreak

0x00001

Break

aioComCts

0x00002

Cts

aioComDsr

0x00004

Dsr

aioComErr

0x00008

Err

aioComRing

0x00010

Ring

aioComRlsd

0x00020

Rlsd

aioComRxChar

0x00040

Rx Char

aioComRxFlag

0x00080

Rx Flag

aioComTxEmpty

0x00100

Tx Empty

aioGpibSRQ

0x00001

SRQ

aioGpibError

0x00002

Error

aioWsAccept

0x00001

Accept

aioWsClose

0x00002

Close

aioWsConnect

0x00004

Connect

aioWsRead

0x00008

Read

aioWsWrite

0x00010

Write

aioWsErrorAccept

0x00020

Accept error

aioWsErrorClose

0x00040

Close error

aioWsErrorConnect

0x00080

Connect error

aioWsErrorRead

0x00100

Read error

aioWsErrorWrite

0x00200

Write Error

aioUsbSRQ

0x1

SRQ (v7.0)

aioUsbError

0x2

Error (v7.0)

 Comments

The lAddress is the address of the interface, for example, 1 for COM 1 (aioCom), gpib board address for aioGpib and socket handle for aioWinSock :

 

Name

Address (range)

Example

aioGpib

GPIB Board Number (1–9).

Must be in the following hexadecimal format: 0xBB0000, where
BB - Board Number (1–9)

 0x10000

aioCom

COM port number, COM 1–COM 256 (1–256)

1

aioVxi

VXI device's logical address (1–255)

1

aioWinSock

Socket handle : (1) one that created as socket=WsCreate(...) or (2) you can get sock handle through driver shortcut - its InterfaceInfo(adriverInfoWinSockSocket)

socket

The proc parameter must be declared as module procedure as follows:

InterfaceEventProc (enInterfaceType, lAddress, lCause)

The InterfaceEventProc procedure syntax has the following parts:

 

Name

Type

Description

enInterfaceType

Val enumAInterfaceType

Type of interface

lAddress

Val Long

Address of the interface

enCause

Val enumAInterfaceEvents

The cause of the call

Multiple calls with the same interface type and address and procedure will re-set the events that will cause the procedure to be called. Calling the procedure with event mask set to 0 will disable and will not cause the proc parameter to be called anymore (since no events cause is specified). Calling the function with the proc parameter set to NoProcedure will disable and remove all procedures called for the specified address.

You can also use the driver OnInterface module events to handle interface events that are specific to the driver shortcut interface type.

Example

The following example sets an interface event that will be called when a win socket client request to connect or send data to the server socket:

SetInterfaceEvent(aioWinSock, m_socketServer, aioWsAccept or aioWsReceive, OnServerEvent)

.

.

.

Procedure OnServerEvent(lInterfaceType, lAddress, lCause)

lInterfaceType : Val Long

lAddress : Val Long

lCause : Val Long

s : String

{

if lCause and aioWsAccept

 

! close prev connection

WsClose(m_socket)

!accept new client connection request

m_socket=WsAccept(lAddress, 50)

 

! start receiving using interface event

SetInterfaceEvent(aioWinSock, m_socket, aioWsRead, ProcReceive)

 

else if lCause and aioWsReceive

 

!accept client connection request

WsReceive(lAddress, 50, ,s)

print s

 

endif

}

See the WSChatIE.prj example in the ATEasy Drivers folder for a complete example.

See Also

Comm Procedures, EnableInterrupt, GPIB Procedures, Winsock Procedures, InterfaceInfo, enumADriverInfo, OnInterface