User manual

Programming examples
65 © 2007-2010 Analytica GmbH
Dialog fields
Network address Network address of the AnaGate SPI.
Check address Establishs a connection to the AnaGate SPI with the specified network address
and reads back some device information and global device settings.
Baud rate The baud rate to be used. The value can be set individually.
Signal Level The voltage level for SPI signals to be used.
Aux. Voltage The voltage level of the support voltage to be used.
Clock mode The phase and polarity of the clock signal.
SPI command SPI command to be sent to the connected SPI device. The command has to be
entered as blank-separated hexadecimal byte groups ("05 1F 3A" for example).
Execute command Executes a SPI command and displays the result in the Result dialog field.
Please keep in mind, that the SPI bus is used as full duplex line, this means that
data is written and received parallel. Make sure that you write the same number
of bytes to the bus as you want to receive (in this cace add padding bytes to the
SPI command).
For example is the Read Status Register command of a M25P80 defined as
0x05. The result of the command is a single byte (8 bit) representing the current
value of the Status Register.
7.2.1.2. Getting global device settings
All SPI related functions of the AnaGate API are declared for Visual Basic users in AnaGateSPI.bas
and are read-to-use. The following code snipplet includes some exemplary declarations of the API
functions used below.
Public Declare Function SPIOpenDevice Lib "AnaGateSPIVB6" _
Alias "_SPIOpenDevice@12" (ByRef Handle As Long, _
ByVal TCPAddress As String, _
ByVal Timeout As Long) As Long
Public Declare Function SPICloseDevice Lib "AnaGateSPIVB6" _
Alias "_SPICloseDevice@4" (ByVal Handle As Long) As Long
Public Declare Function SPIGetGlobals Lib "AnaGateSPIVB6" _
Alias "_SPIGetGlobals@20" (ByVal hHandle As Long, _
ByRef nBaudrate As Long, _
ByRef SigLevel As Byte, _
ByRef nAuxVoltage As Byte, _
ByRef nClockMode As Byte) As Long
The event procedure btnCheckAddress_Click is called on click of the Check Address button.
Private Sub btnCheckAddress_Click()
Dim nRC As Long, Data As String, sText As String, I As Long
nRC = SPIOpenDevice(hHandle, Me.IPAddresse.Text, 2000)
1
If nRC <> 0 Then
Me.lblErrorMsg.Caption = "Fehler bei SPIOpenDevice: " & GetErrorMsg(nRC)
Else
Me.lblErrorMsg.Caption = GetAnagateInfo(hHandle)
End If
nRC = SPICloseDevice(hHandle)
2
End Sub