Declare Function CANCloseDevice Lib "AnaGateCAN" (ByVal Handle As Int32) As Int32
Public Delegate Sub CAN_CALLBACK(ByVal ID As Int32, ByVal Buffer As IntPtr, _
Declare Function CANSetCallback Lib "AnaGateCAN" (ByVal Handle As Int32, _
Sub CANCallback( ByVal ID As Int32, ByVal Buffer As IntPtr, _
Dim Bytes as Byte(8)
System.Runtime.InteropServices.Marshal.Copy(Buffer, Bytes, 0, Bufferlen )
Console.Out.Write( "CAN-ID=" )
Console.Out.Write( ID )
Console.Out.Write( ",Data=" )
For I As Int32 = 0 To BufferLen - 1
Console.Out.Write( Bytes(I) )
Next
End Sub
Function Main(ByVal CmdArgs() As String) As Integer
'Opens the single CAN port of a AnaGate CAN
Dim RC as Int32 = CANOpenDevice(Handle, 0, 1, 400, 0, "192.168.1.254", 1000)
If RC = 0 Then
CANSetCallback( Handle, AddressOf CANCallback )
End If
If RC = 0 Then
CANCloseDevice( Handle )
End If
End Function
7.3.2. SPI Console-Anwendung VB.NET
Das folgende Programmierbeispiel für VB.NET zeigt, wie eine Verbindung mit dem
AnaGate SPI aufgebaut wird und Daten auf den SPI-Bus gesendet bzw. empfangen
werden.
Anmerkung
Der vollständige Quellcode des vorliegenden Beispiels ist auf der jedem
Gerät beiliegenden CD-ROM im Verzeichnispfad Samples/SPI-VB.NET zu
finden.
Sub Main()
Dim hHandle As Int32, nIndex As Integer
Dim BufferWrite(100) As Byte, BufferRead(100) As Byte
Dim nBaudrate As Int32 = 5000000 ' 500kBit
Dim nSigLevel As Byte = 2
Dim nAuxVoltage As Byte = 0 ' support voltage is +3.3V.
Dim nClockMode As Byte = 3
Dim nRC = SPIOpenDevice(hHandle, "192.168.1.254", 5000)
If nRC <> 0 Then
Programmier-Beispiele
ByVal Bufferlen As Int32, ByVal Flags as Int32, _
ByVal Handle as Int32)
ByVal Bufferlen As Int32, ByVal Flags as Int32, _
ByVal Handle as Int32)
' +3.3V for the signals.
' CPHA=1 and CPOL=1.
86
ByVal MonitorOn As Int32, _
ByVal PortNumber As Int32, _
ByVal TCPAddress As String, _
ByVal Timeout As Int32) As Int32
ByVal MyCB As CAN_CALLBACK) As Int32
1
© 2007-2015 Analytica GmbH