📄 aardvark.bas
字号:
'
' ex. devices are attached to ports 0, 1, 2
' ports 0 and 2 are available, and port 1 is in-use.
' array => 0x0000, 0x8001, 0x0002
'
' If the array is NULL, it is not filled with any values.
' If there are more devices than the array size, only the
' first nmemb port numbers will be written into the array.
'
' Returns the number of devices found, regardless of the
' array size.
Public Function aa_find_devices (ByVal nelem As Long, ByRef devices() As Integer) as Long
If check_version() Then
aa_find_devices = std_aa_find_devices(nelem, devices(0))
Else
aa_find_devices = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Get a list of ports to which Aardvark devices are attached.
'
' This function is the same as aa_find_devices() except that
' it returns the unique IDs of each Aardvark device. The IDs
' are guaranteed to be non-zero if valid.
'
' The IDs are the unsigned integer representation of the 10-digit
' serial numbers.
Public Function aa_find_devices_ext (ByVal nelem As Long, ByRef devices() As Integer, ByRef unique_ids() As Long) as Long
If check_version() Then
aa_find_devices_ext = std_aa_find_devices_ext(nelem, devices(0), unique_ids(0))
Else
aa_find_devices_ext = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Open the Aardvark port.
'
' The port number is a zero-indexed integer.
'
' The port number is the same as that obtained from the
' aa_find_devices() function above.
'
' Returns an Aardvark handle, which is guaranteed to be
' greater than zero if it is valid.
'
' This function is recommended for use in simple applications
' where extended information is not required. For more complex
' applications, the use of aa_open_ext() is recommended.
Public Function aa_open (ByVal port_number As Long) as Long
If check_version() Then
aa_open = std_aa_open(port_number)
Else
aa_open = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Open the Aardvark port, returning extended information
' in the supplied structure. Behavior is otherwise identical
' to aa_open() above. If 0 is passed as the pointer to the
' structure, this function is exactly equivalent to aa_open().
'
' The structure is zeroed before the open is attempted.
' It is filled with whatever information is available.
'
' For example, if the firmware version is not filled, then
' the device could not be queried for its version number.
'
' This function is recommended for use in complex applications
' where extended information is required. For more simple
' applications, the use of aa_open() is recommended.
Public Function aa_open_ext (ByVal port_number As Long, ByRef aa_ext As AardvarkExt) as Long
If check_version() Then
aa_open_ext = std_aa_open_ext(port_number, aa_ext)
Else
aa_open_ext = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Close the Aardvark port.
Public Function aa_close (ByVal aardvark As Long) as Long
If check_version() Then
aa_close = std_aa_close(aardvark)
Else
aa_close = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Return the port for this Aardvark handle.
'
' The port number is a zero-indexed integer.
Public Function aa_port (ByVal aardvark As Long) as Long
If check_version() Then
aa_port = std_aa_port(aardvark)
Else
aa_port = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Return the device features as a bit-mask of values, or
' an error code if the handle is not valid.
Public Function aa_features (ByVal aardvark As Long) as Long
If check_version() Then
aa_features = std_aa_features(aardvark)
Else
aa_features = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Return the unique ID for this Aardvark adapter.
' IDs are guaranteed to be non-zero if valid.
' The ID is the unsigned integer representation of the
' 10-digit serial number.
Public Function aa_unique_id (ByVal aardvark As Long) as Long
If check_version() Then
aa_unique_id = std_aa_unique_id(aardvark)
Else
aa_unique_id = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Return the status string for the given status code.
' If the code is not valid or the library function cannot
' be loaded, return a NULL string.
Public Function aa_status_string (ByVal status As Long) as String
If check_version() Then
aa_status_string = vb_aa_status_string(status)
Else
aa_status_string = vbNullString
End If
End Function
' Enable logging to a file. The handle must be standard file
' descriptor. In C, a file descriptor can be obtained by using
' the ANSI C function "open" or by using the function "fileno"
' on a FILE* stream. A FILE* stream can be obtained using "fopen"
' or can correspond to the common "stdout" or "stderr" --
' available when including stdlib.h
Public Function aa_log (ByVal aardvark As Long, ByVal level As Long, ByVal handle As Long) as Long
If check_version() Then
aa_log = std_aa_log(aardvark, level, handle)
Else
aa_log = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Return the version matrix for the device attached to the
' given handle. If the handle is 0 or invalid, only the
' software and required api versions are set.
Public Function aa_version (ByVal aardvark As Long, ByRef version As AardvarkVersion) as Long
If check_version() Then
aa_version = std_aa_version(aardvark, version)
Else
aa_version = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Configure the device by enabling/disabling I2C, SPI, and
' GPIO functions.
Public Function aa_configure (ByVal aardvark As Long, ByVal config As Long) as Long
If check_version() Then
aa_configure = std_aa_configure(aardvark, config)
Else
aa_configure = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Configure the target power pins.
' This is only supported on hardware versions >= 2.00
Public Function aa_target_power (ByVal aardvark As Long, ByVal power_mask As Byte) as Long
If check_version() Then
aa_target_power = std_aa_target_power(aardvark, power_mask)
Else
aa_target_power = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Sleep for the specified number of milliseconds
' Accuracy depends on the operating system scheduler
' Returns the number of milliseconds slept
Public Function aa_sleep_ms (ByVal milliseconds As Long) as Long
If check_version() Then
aa_sleep_ms = std_aa_sleep_ms(milliseconds)
Else
aa_sleep_ms = AA_INCOMPATIBLE_LIBRARY
End If
End Function
'==========================================================================
' ASYNC MESSAGE POLLING
'==========================================================================
' Polling function to check if there are any asynchronous
' messages pending for processing. The function takes a timeout
' value in units of milliseconds. If the timeout is < 0, the
' function will block until data is received. If the timeout is 0,
' the function will perform a non-blocking check.
Public Function aa_async_poll (ByVal aardvark As Long, ByVal timeout As Long) as Long
If check_version() Then
aa_async_poll = std_aa_async_poll(aardvark, timeout)
Else
aa_async_poll = AA_INCOMPATIBLE_LIBRARY
End If
End Function
'==========================================================================
' I2C API
'==========================================================================
' Free the I2C bus.
Public Function aa_i2c_free_bus (ByVal aardvark As Long) as Long
If check_version() Then
aa_i2c_free_bus = std_aa_i2c_free_bus(aardvark)
Else
aa_i2c_free_bus = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Set the I2C bit rate in kilohertz. If a zero is passed as the
' bitrate, the bitrate is unchanged and the current bitrate is
' returned.
Public Function aa_i2c_bitrate (ByVal aardvark As Long, ByVal bitrate_khz As Long) as Long
If check_version() Then
aa_i2c_bitrate = std_aa_i2c_bitrate(aardvark, bitrate_khz)
Else
aa_i2c_bitrate = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Read a stream of bytes from the I2C slave device.
Public Function aa_i2c_read (ByVal aardvark As Long, ByVal slave_addr As Integer, ByVal flags As Long, ByVal num_bytes As Integer, ByRef data_in() As Byte) as Long
If check_version() Then
aa_i2c_read = std_aa_i2c_read(aardvark, slave_addr, flags, num_bytes, data_in(0))
Else
aa_i2c_read = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Read a stream of bytes from the I2C slave device.
' This API function returns the number of bytes read into
' the num_read variable. The return value of the function
' is a status code.
Public Function aa_i2c_read_ext (ByVal aardvark As Long, ByVal slave_addr As Integer, ByVal flags As Long, ByVal num_bytes As Integer, ByRef data_in() As Byte, ByRef num_read As Integer) as Long
If check_version() Then
aa_i2c_read_ext = std_aa_i2c_read_ext(aardvark, slave_addr, flags, num_bytes, data_in(0), num_read)
Else
aa_i2c_read_ext = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Write a stream of bytes to the I2C slave device.
Public Function aa_i2c_write (ByVal aardvark As Long, ByVal slave_addr As Integer, ByVal flags As Long, ByRef data_out() As Byte) as Long
If check_version() Then
Dim num_bytes As Long
num_bytes = UBound(data_out) - LBound(data_out) + 1
aa_i2c_write = std_aa_i2c_write(aardvark, slave_addr, flags, num_bytes, data_out(0))
Else
aa_i2c_write = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Write a stream of bytes to the I2C slave device.
' This API function returns the number of bytes written into
' the num_written variable. The return value of the function
' is a status code.
Public Function aa_i2c_write_ext (ByVal aardvark As Long, ByVal slave_addr As Integer, ByVal flags As Long, ByRef data_out() As Byte, ByRef num_written As Integer) as Long
If check_version() Then
Dim num_bytes As Long
num_bytes = UBound(data_out) - LBound(data_out) + 1
aa_i2c_write_ext = std_aa_i2c_write_ext(aardvark, slave_addr, flags, num_bytes, data_out(0), num_written)
Else
aa_i2c_write_ext = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Enable/Disable the Aardvark as an I2C slave device
Public Function aa_i2c_slave_enable (ByVal aardvark As Long, ByVal addr As Byte, ByVal maxTxBytes As Integer, ByVal maxRxBytes As Integer) as Long
If check_version() Then
aa_i2c_slave_enable = std_aa_i2c_slave_enable(aardvark, addr, maxTxBytes, maxRxBytes)
Else
aa_i2c_slave_enable = AA_INCOMPATIBLE_LIBRARY
End If
End Function
Public Function aa_i2c_slave_disable (ByVal aardvark As Long) as Long
If check_version() Then
aa_i2c_slave_disable = std_aa_i2c_slave_disable(aardvark)
Else
aa_i2c_slave_disable = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Set the slave response in the event the Aardvark is put
' into slave mode and contacted by a Master.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -