2016/03/16- |
当社の9bit通信対応 USB RS485/422絶縁型変換器(USB-306)対応の制御用DLL(HDL9BITDLL.dll)をVB.NETで利用する方法についての参考ページです。(Vusual Studio 2015によります) |
公開APIのインターフェース定義'------------------------------------------------------------------- '------------------------------------------------------------------- ' HDL9BITDLL.dll 使用 ここから '------------------------------------------------------------------- '------------------------------------------------------------------- 'Returns the number of attached devices with matching IDs. 'デバイス数取得 Private Declare Function HDL9BIT_GetNumUartsA Lib "HDL9BITDLL.dll" _ (ByVal productIDFilter As Int16, '__in_opt uint16_t productIDFilter, ByVal interfaceIDFilter As Byte, '__in_opt uint8_t interfaceIDFilter, ByRef numUarts As Int32 '__out uint32l_t* numUarts ) As Int16 '------------------------------------------------------------------- 'Opens the device specified by the index into the array of available 'devices And returns a handle to it. 'UARTオープン Private Declare Function HDL9BIT_OpenUartA Lib "HDL9BITDLL.dll" _ (ByVal memberIndex As Int32, '__in uint32l_t memberIndex, ByVal productIDFilter As Int16, '__in_opt uint16_t productIDFilter, ByVal interfaceIDFilter As Byte, '__in_opt uint8_t interfaceIDFilter, ByRef uartDeviceObject As IntPtr '__out H9bHandle_t* uartDeviceObject ) As Int16 '------------------------------------------------------------------- 'Returns the current USB Serial Number String. 'デバイス固有番号(シリアル番号)取得 Private Declare Function HDL9BIT_GetOtpSerialNumberString Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef stringLength As Byte, '__out uint8_t* stringLength, ByVal serialString As Byte() 'ByVal __out char* serialString ) As Int16 '------------------------------------------------------------------- 'Returns the currently configures data rate and character format '通信条件の読み込み Private Declare Function HDL9BIT_GetLineCodingA Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef dataRate As Int32, '__out uint32l_t* dataRate, ByRef charFormat As Byte, '__out uint8_t* charFormat, ByRef parityType As Byte, '__out uint8_t* parityType, ByRef dataBits As Byte, '__out uint8_t* dataBits, ByRef flowControl As Byte, '__out uint8_t* flowControl, ByRef gpioMode0 As Byte '__out uint8_t* gpioMode0 ) As Int16 '------------------------------------------------------------------- 'Configures the data rate and character format of a UART channel. '通信条件設定 Private Declare Function HDL9BIT_SetLineCodingA Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal dataRate As Int32, '__in uint32l_t dataRate, ByVal charFormat As Byte, '__in uint8_t charFormat, ByVal parityType As Byte, '__in uint8_t parityType, ByVal dataBits As Byte, '__in uint8_t dataBits, ByVal flowControl As Byte, '__in uint8_t flowControl, ByVal gpioMode0 As Byte '__in uint8_t gpioMode0 ) As Int16 'addressモード時 flowControl = 0x03 'それ以外は flowControl = 0x01 'gpioMode0は0x39固定 '------------------------------------------------------------------- 'Returns the current timeout settings. '送受信タイムアウト時間読み込み Private Declare Function HDL9BIT_GetTimeouts Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef writeTimeout As Int32, '__in* uint32l_t writeTimeout, ByRef readTimeout As Int32 '__in* uint32l_t readTimeout ) As Int16 '------------------------------------------------------------------- 'Sets maximum allowable time for read and write operations. '送受信タイムアウト時間設定 Private Declare Function HDL9BIT_SetTimeouts Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal writeTimeout As Int32, '__in uint32l_t writeTimeout, ByVal readTimeout As Int32 '__in uint32l_t readTimeout ) As Int16 '------------------------------------------------------------------- 'Returns the current setting for the number of bytes in the Rx FIFO 'before flow control is asserted to the remote UART. '受信FIFO動作しきい値読み込み Private Declare Function HDL9BIT_GetUartRxFifoThreshold Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef rxFifoThreshold As Int16 '__out uint16_t* rxFifoThreshold ) As UShort '------------------------------------------------------------------- 'Sets how many bytes will be stored in the local UART's Rx FIFO 'before flow control is asserted to the remote UART. '受信FIFO動作しきい値設定 Private Declare Function HDL9BIT_SetUartRxFifoThreshold Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal rxFifoThreshold As Int16 '__in uint16_t rxFifoThreshold ) As Int16 '------------------------------------------------------------------- 'Close a device handle 'UARTクローズ Private Declare Function HDL9BIT_CloseUart Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr '__in H9bHandle_t uartDeviceObject, ) As UShort '------------------------------------------------------------------- 'Returns the currently configured addresses used by the UART when 'Address Match Mode is enabled. 'AddressModeで使用する設定アドレス取得 Private Declare Function HDL9BIT_GetUartAddress Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef unicastAddress As Byte, '__out uint8_t* unicastAddress, ByRef multicastAddress As Byte '__out uint8_t* multicastAddress ) As Int16 '------------------------------------------------------------------- 'Sets the addresses the UART will respond to when Address Match Mode 'is enabled. 'AddressModeで使用する設定アドレス設定 Private Declare Function HDL9BIT_SetUartAddress Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal unicastAddress As Byte, '__in uint8_t unicastAddress, ByVal multicastAddress As Byte '__in uint8_t multicastAddress ) As Int16 '------------------------------------------------------------------- 'Reads data from a UART handle (USB IN transfers). '受信データ読み込み Private Declare Function HDL9BIT_ReadUart Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal numberOfBytesToRead As Int32, '__in uint32l_t numberOfBytesToRead, ByVal byteBuffer As Byte(), 'ByVal __out uint8_t* byteBuffer, ByRef numberOfBytesReads As Int32 '__out uint32l_t* numberOfBytesRead ) As Int16 '------------------------------------------------------------------- 'Writes data to a UART handle (USB OUT transfers). '送信データ書き込み(送信) Private Declare Function HDL9BIT_WriteUart Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal numberOfBytesToRead As Int32, ' __in uint32l_t numberOfBytesToWrite, ByVal byteBuffer As Byte(), 'ByVal __in uint8_t* byteBuffer, ByRef numberOfBytesReads As Int32 '__out uint32l_t* numberOfBytesWritten ) As Int16 '------------------------------------------------------------------- 'Indicates whether a UART channel is currently enabled for transmit and receive '送受信有効・無効設定確認 Private Declare Function HDL9BIT_IsEnabled Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef numberOfBytesReads As Boolean '__out boolean_t* enabled ) As Int16 '------------------------------------------------------------------- 'Enables a UART channel for transmit and receive '送受信有効・無効設定 Private Declare Function HDL9BIT_EnableUart Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal numberOfBytesReads As Boolean '__in boolean_t enable ) As Int16 '------------------------------------------------------------------- 'Flushes buffers and FIFOs in transmit, receive, or both directions. '送受信バッファを空にする Private Declare Function HDL9BIT_FlushBuffers Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal flushTransmit As Boolean, '__in boolean_t flushTransmit, ByVal flushReceives As Boolean '__in boolean_t flushReceive ) As Int16 '------------------------------------------------------------------- 'Requests a UART to transmit a break signal. 'ブレーク信号送信 Private Declare Function HDL9BIT_SendBreak Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal breakDuration As Byte '__in uint8_t breakDuration ) As Int16 '------------------------------------------------------------------- 'Requests a UART to stop transmitting break. 'ブレーク信号停止 Private Declare Function HDL9BIT_CancelBreak Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr '__in H9bHandle_t uartDeviceObject, ) As Int16 '------------------------------------------------------------------- 'Returns the current USB Manufacturer String. '製造メーカ名取得 Private Declare Function HDL9BIT_GetOtpManufacturerString Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef stringLength As Byte, '__out uint8_t* strlen, ByVal manufacturingString As Byte() 'ByVal __out char* manufacturingString ) As Int16 '------------------------------------------------------------------- 'Returns the current USB Product String. '製品名称取得 Private Declare Function HDL9BIT_GetOtpProductString Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef stringLength As Byte, '__out uint8_t* stringLength, ByVal productString As Byte() 'ByVal__out char* productString ) As Int16 '------------------------------------------------------------------- 'Returns the release version of this API. 'ファームウエアバージョン取得 Private Declare Function HDL9BIT_GetSoftwareAPIAttributes Lib "HDL9BITDLL.dll" _ (ByRef majorVersion As Byte, '__out uint8_t* majorVersion, ByRef minorVersion As Byte, '__out uint8_t* minorVersion, ByRef isReleaseVersion As Boolean '__out boolean_t* isReleaseVersion ) As Int16 '------------------------------------------------------------------- 'Indicates whether a device handle is still open 'オープン状況問い合わせ Private Declare Function HDL9BIT_IsOpen Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef opened As Boolean '__out boolean_t* opened ) As Int16 '------------------------------------------------------------------- '------------------------------------------------------------------- ' HDL9BITDLL.dll 使用 ここまで '------------------------------------------------------------------- '------------------------------------------------------------------- |
定数定義'/****************************************************************************** '* API Return Codes Int16 '******************************************************************************/ Const HDL9BIT_SUCCESS As Int16 = 0 '#define HDL9BIT_SUCCESS 0x00 Const HDL9BIT_ERR_DEVICE_NOT_FOUND As Int16 = 1 '#define HDL9BIT_ERR_DEVICE_NOT_FOUND 0x01 Const HDL9BIT_ERR_INVALID_HANDLE As Int16 = 2 '#define HDL9BIT_ERR_INVALID_HANDLE 0x02 Const HHDL9BIT_ERR_HANDLE_IS_NOT_A_UART As Int16 = 3 '#define HDL9BIT_ERR_HANDLE_IS_NOT_A_UART 0x03 Const HDL9BIT_ERR_INVALID_PARAMETER As Int16 = 4 '#define HDL9BIT_ERR_INVALID_PARAMETER 0x04 Const HDL9BIT_ERR_INVALID_REQUEST_LENGTH As Int16 = 5 '#define HDL9BIT_ERR_INVALID_REQUEST_LENGTH 0x05 Const HDL9BIT_ERR_UART_READ_FAIL As Int16 = &H10 '#define HDL9BIT_ERR_UART_READ_FAIL 0x10 Const HDL9BIT_ERR_UART_WRITE_FAIL As Int16 = &H11 '#define HDL9BIT_ERR_UART_WRITE_FAIL 0x11 Const HDL9BIT_ERR_UART_READ_FAIL_TIME_OUT As Int16 = &H12 '#define HDL9BIT_ERR_UART_READ_FAIL_TIME_OUT 0x12 Const HDL9BIT_ERR_UART_WRITE_FAIL_TIME_OUT As Int16 = &H13 '#define HDL9BIT_ERR_UART_WRITE_FAIL_TIME_OUT 0x13 Const HDL9BIT_ERR_USB_CTRL_PIPE_FAIL As Int16 = &H14 '#define HDL9BIT_ERR_USB_CTRL_PIPE_FAIL 0x14 Const HDL9BIT_ERR_USB_COMMUNICATION_ERROR As Int16 = &H15 '#define HDL9BIT_ERR_USB_COMMUNICATION_ERROR 0x15 Const HDL9BIT_ERR_USB_DEVICE_NOT_SUPPORTED As Int16 = &H16 '#define HDL9BIT_ERR_USB_DEVICE_NOT_SUPPORTED 0x16 Const HDL9BIT_ERR_GENERIC_FAIL As Int16 = &HFF '#define HDL9BIT_ERR_GENERIC_FAIL 0xFF ' '/****************************************************************************** '* API Parameter Encodings '******************************************************************************/ '/* ' * Error Flags returned by HDL9BIT_GetUartAttributes() ' */ Const HDL9BIT_ERROR_FLAG_PARITY As Byte = 1 '#define HDL9BIT_ERROR_FLAG_PARITY 0x01 Const HDL9BIT_ERROR_FLAG_OVERFLOW As Byte = 2 '#define HDL9BIT_ERROR_FLAG_OVERFLOW 0x02 ' '/* ' * Number of data bits. Input to HDL9BIT_SetLineCoding() and ' * output of HDL9BIT_GetLineCoding() ' */ Const HDL9BIT_DATA_BITS_FIVE As Byte = 0 '#define HDL9BIT_DATA_BITS_FIVE 0x00 Const HDL9BIT_DATA_BITS_SIX As Byte = 1 '#define HDL9BIT_DATA_BITS_SIX 0x01 Const HDL9BIT_DATA_BITS_SEVEN As Byte = 2 '#define HDL9BIT_DATA_BITS_SEVEN 0x02 Const HDL9BIT_DATA_BITS_EIGHT As Byte = 3 '#define HDL9BIT_DATA_BITS_EIGHT 0x03 Const HDL9BIT_DATA_BITS_NINE As Byte = 4 '#define HDL9BIT_DATA_BITS_NINE 0x04 ' '/* ' * Parity types. Input to HDL9BIT_SetLineCoding() and ' * output of HDL9BIT_GetLineCoding() ' */ Const HDL9BIT_PARITY_NONE As Byte = 0 '#define HDL9BIT_PARITY_NONE 0x00 Const HDL9BIT_PARITY_ODD As Byte = 1 '#define HDL9BIT_PARITY_ODD 0x01 Const HDL9BIT_PARITY_EVEN As Byte = 2 '#define HDL9BIT_PARITY_EVEN 0x02 Const HDL9BIT_PARITY_MARK As Byte = 3 '#define HDL9BIT_PARITY_MARK 0x03 Const HDL9BIT_PARITY_SPACE As Byte = 4 '#define HDL9BIT_PARITY_SPACE 0x04 ' '/* ' * Character formats. Input to HDL9BIT_SetLineCoding() and ' * output of HDL9BIT_GetLineCoding() ' */ Const HDL9BIT_CHAR_FORMAT_STOP_SHORT As Byte = 0 '#define HDL9BIT_CHAR_FORMAT_STOP_SHORT 0x00 Const HDL9BIT_CHAR_FORMAT_STOP_LONG As Byte = 1 '#define HDL9BIT_CHAR_FORMAT_STOP_LONG 0x01 ' '/* ' * Flow control types. Input to HDL9BIT_SetLineCoding() and ' * output of HDL9BIT_GetLineCoding() ' */ Const HDL9BIT_FLOW_CONTROL_NONE As Byte = 0 '#define HDL9BIT_FLOW_CONTROL_NONE 0x00 Const HDL9BIT_FLOW_CONTROL_HW_RTS_CTS As Byte = 1 '#define HDL9BIT_FLOW_CONTROL_HW_RTS_CTS 0x01 Const HDL9BIT_FLOW_CONTROL_ADDRESS_MODE As Byte = 3 '#define HDL9BIT_FLOW_CONTROL_ADDRESS_MODE 0x03 ' |
使用例・公開されている全てのAPIを使っているサンプルソースです。' 'HDL9BITDLL.dll 使用例 'HuMANDATA LTD. 2016-03-22 BY A.USHIRO ' Public Class Form1 '------------------------------------------------------------------- '------------------------------------------------------------------- ' HDL9BITDLL.dll 使用 ここから '------------------------------------------------------------------- '------------------------------------------------------------------- 'Returns the number of attached devices with matching IDs. 'デバイス数取得 Private Declare Function HDL9BIT_GetNumUartsA Lib "HDL9BITDLL.dll" _ (ByVal productIDFilter As Int16, '__in_opt uint16_t productIDFilter, ByVal interfaceIDFilter As Byte, '__in_opt uint8_t interfaceIDFilter, ByRef numUarts As Int32 '__out uint32l_t* numUarts ) As Int16 '------------------------------------------------------------------- 'Opens the device specified by the index into the array of available 'devices And returns a handle to it. 'UARTオープン Private Declare Function HDL9BIT_OpenUartA Lib "HDL9BITDLL.dll" _ (ByVal memberIndex As Int32, '__in uint32l_t memberIndex, ByVal productIDFilter As Int16, '__in_opt uint16_t productIDFilter, ByVal interfaceIDFilter As Byte, '__in_opt uint8_t interfaceIDFilter, ByRef uartDeviceObject As IntPtr '__out H9bHandle_t* uartDeviceObject ) As Int16 '------------------------------------------------------------------- 'Returns the current USB Serial Number String. 'デバイス固有番号(シリアル番号)取得 Private Declare Function HDL9BIT_GetOtpSerialNumberString Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef stringLength As Byte, '__out uint8_t* stringLength, ByVal serialString As Byte() 'ByVal __out char* serialString ) As Int16 '------------------------------------------------------------------- 'Returns the currently configures data rate and character format '通信条件の読み込み Private Declare Function HDL9BIT_GetLineCodingA Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef dataRate As Int32, '__out uint32l_t* dataRate, ByRef charFormat As Byte, '__out uint8_t* charFormat, ByRef parityType As Byte, '__out uint8_t* parityType, ByRef dataBits As Byte, '__out uint8_t* dataBits, ByRef flowControl As Byte, '__out uint8_t* flowControl, ByRef gpioMode0 As Byte '__out uint8_t* gpioMode0 ) As Int16 '------------------------------------------------------------------- 'Configures the data rate and character format of a UART channel. '通信条件設定 Private Declare Function HDL9BIT_SetLineCodingA Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal dataRate As Int32, '__in uint32l_t dataRate, ByVal charFormat As Byte, '__in uint8_t charFormat, ByVal parityType As Byte, '__in uint8_t parityType, ByVal dataBits As Byte, '__in uint8_t dataBits, ByVal flowControl As Byte, '__in uint8_t flowControl, ByVal gpioMode0 As Byte '__in uint8_t gpioMode0 ) As Int16 'addressモード時 flowControl = 0x03 'それ以外は flowControl = 0x01 'gpioMode0は0x39固定 '------------------------------------------------------------------- 'Returns the current timeout settings. '送受信タイムアウト時間読み込み Private Declare Function HDL9BIT_GetTimeouts Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef writeTimeout As Int32, '__in* uint32l_t writeTimeout, ByRef readTimeout As Int32 '__in* uint32l_t readTimeout ) As Int16 '------------------------------------------------------------------- 'Sets maximum allowable time for read and write operations. '送受信タイムアウト時間設定 Private Declare Function HDL9BIT_SetTimeouts Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal writeTimeout As Int32, '__in uint32l_t writeTimeout, ByVal readTimeout As Int32 '__in uint32l_t readTimeout ) As Int16 '------------------------------------------------------------------- 'Returns the current setting for the number of bytes in the Rx FIFO 'before flow control is asserted to the remote UART. '受信FIFO動作しきい値読み込み Private Declare Function HDL9BIT_GetUartRxFifoThreshold Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef rxFifoThreshold As Int16 '__out uint16_t* rxFifoThreshold ) As UShort '------------------------------------------------------------------- 'Sets how many bytes will be stored in the local UART's Rx FIFO 'before flow control is asserted to the remote UART. '受信FIFO動作しきい値設定 Private Declare Function HDL9BIT_SetUartRxFifoThreshold Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal rxFifoThreshold As Int16 '__in uint16_t rxFifoThreshold ) As Int16 '------------------------------------------------------------------- 'Close a device handle 'UARTクローズ Private Declare Function HDL9BIT_CloseUart Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr '__in H9bHandle_t uartDeviceObject, ) As UShort '------------------------------------------------------------------- 'Returns the currently configured addresses used by the UART when 'Address Match Mode is enabled. 'AddressModeで使用する設定アドレス取得 Private Declare Function HDL9BIT_GetUartAddress Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef unicastAddress As Byte, '__out uint8_t* unicastAddress, ByRef multicastAddress As Byte '__out uint8_t* multicastAddress ) As Int16 '------------------------------------------------------------------- 'Sets the addresses the UART will respond to when Address Match Mode 'is enabled. 'AddressModeで使用する設定アドレス設定 Private Declare Function HDL9BIT_SetUartAddress Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal unicastAddress As Byte, '__in uint8_t unicastAddress, ByVal multicastAddress As Byte '__in uint8_t multicastAddress ) As Int16 '------------------------------------------------------------------- 'Reads data from a UART handle (USB IN transfers). '受信データ読み込み Private Declare Function HDL9BIT_ReadUart Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal numberOfBytesToRead As Int32, '__in uint32l_t numberOfBytesToRead, ByVal byteBuffer As Byte(), 'ByVal __out uint8_t* byteBuffer, ByRef numberOfBytesReads As Int32 '__out uint32l_t* numberOfBytesRead ) As Int16 '------------------------------------------------------------------- 'Writes data to a UART handle (USB OUT transfers). '送信データ書き込み(送信) Private Declare Function HDL9BIT_WriteUart Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal numberOfBytesToRead As Int32, ' __in uint32l_t numberOfBytesToWrite, ByVal byteBuffer As Byte(), 'ByVal __in uint8_t* byteBuffer, ByRef numberOfBytesReads As Int32 '__out uint32l_t* numberOfBytesWritten ) As Int16 '------------------------------------------------------------------- 'Indicates whether a UART channel is currently enabled for transmit and receive '送受信有効・無効設定確認 Private Declare Function HDL9BIT_IsEnabled Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef numberOfBytesReads As Boolean '__out boolean_t* enabled ) As Int16 '------------------------------------------------------------------- 'Enables a UART channel for transmit and receive '送受信有効・無効設定 Private Declare Function HDL9BIT_EnableUart Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal numberOfBytesReads As Boolean '__in boolean_t enable ) As Int16 '------------------------------------------------------------------- 'Flushes buffers and FIFOs in transmit, receive, or both directions. '送受信バッファを空にする Private Declare Function HDL9BIT_FlushBuffers Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal flushTransmit As Boolean, '__in boolean_t flushTransmit, ByVal flushReceives As Boolean '__in boolean_t flushReceive ) As Int16 '------------------------------------------------------------------- 'Requests a UART to transmit a break signal. 'ブレーク信号送信 Private Declare Function HDL9BIT_SendBreak Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByVal breakDuration As Byte '__in uint8_t breakDuration ) As Int16 '------------------------------------------------------------------- 'Requests a UART to stop transmitting break. 'ブレーク信号停止 Private Declare Function HDL9BIT_CancelBreak Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr '__in H9bHandle_t uartDeviceObject, ) As Int16 '------------------------------------------------------------------- 'Returns the current USB Manufacturer String. '製造メーカ名取得 Private Declare Function HDL9BIT_GetOtpManufacturerString Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef stringLength As Byte, '__out uint8_t* strlen, ByVal manufacturingString As Byte() 'ByVal __out char* manufacturingString ) As Int16 '------------------------------------------------------------------- 'Returns the current USB Product String. '製品名称取得 Private Declare Function HDL9BIT_GetOtpProductString Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef stringLength As Byte, '__out uint8_t* stringLength, ByVal productString As Byte() 'ByVal__out char* productString ) As Int16 '------------------------------------------------------------------- 'Returns the release version of this API. 'ファームウエアバージョン取得 Private Declare Function HDL9BIT_GetSoftwareAPIAttributes Lib "HDL9BITDLL.dll" _ (ByRef majorVersion As Byte, '__out uint8_t* majorVersion, ByRef minorVersion As Byte, '__out uint8_t* minorVersion, ByRef isReleaseVersion As Boolean '__out boolean_t* isReleaseVersion ) As Int16 '------------------------------------------------------------------- 'Indicates whether a device handle is still open 'オープン状況問い合わせ Private Declare Function HDL9BIT_IsOpen Lib "HDL9BITDLL.dll" _ (ByVal uartDeviceObject As IntPtr, '__in H9bHandle_t uartDeviceObject, ByRef opened As Boolean '__out boolean_t* opened ) As Int16 '------------------------------------------------------------------- '------------------------------------------------------------------- ' HDL9BITDLL.dll 使用 ここまで '------------------------------------------------------------------- '------------------------------------------------------------------- '/****************************************************************************** '* API Return Codes Int16 '******************************************************************************/ Const HDL9BIT_SUCCESS As Int16 = 0 '#define HDL9BIT_SUCCESS 0x00 Const HDL9BIT_ERR_DEVICE_NOT_FOUND As Int16 = 1 '#define HDL9BIT_ERR_DEVICE_NOT_FOUND 0x01 Const HDL9BIT_ERR_INVALID_HANDLE As Int16 = 2 '#define HDL9BIT_ERR_INVALID_HANDLE 0x02 Const HHDL9BIT_ERR_HANDLE_IS_NOT_A_UART As Int16 = 3 '#define HDL9BIT_ERR_HANDLE_IS_NOT_A_UART 0x03 Const HDL9BIT_ERR_INVALID_PARAMETER As Int16 = 4 '#define HDL9BIT_ERR_INVALID_PARAMETER 0x04 Const HDL9BIT_ERR_INVALID_REQUEST_LENGTH As Int16 = 5 '#define HDL9BIT_ERR_INVALID_REQUEST_LENGTH 0x05 Const HDL9BIT_ERR_UART_READ_FAIL As Int16 = &H10 '#define HDL9BIT_ERR_UART_READ_FAIL 0x10 Const HDL9BIT_ERR_UART_WRITE_FAIL As Int16 = &H11 '#define HDL9BIT_ERR_UART_WRITE_FAIL 0x11 Const HDL9BIT_ERR_UART_READ_FAIL_TIME_OUT As Int16 = &H12 '#define HDL9BIT_ERR_UART_READ_FAIL_TIME_OUT 0x12 Const HDL9BIT_ERR_UART_WRITE_FAIL_TIME_OUT As Int16 = &H13 '#define HDL9BIT_ERR_UART_WRITE_FAIL_TIME_OUT 0x13 Const HDL9BIT_ERR_USB_CTRL_PIPE_FAIL As Int16 = &H14 '#define HDL9BIT_ERR_USB_CTRL_PIPE_FAIL 0x14 Const HDL9BIT_ERR_USB_COMMUNICATION_ERROR As Int16 = &H15 '#define HDL9BIT_ERR_USB_COMMUNICATION_ERROR 0x15 Const HDL9BIT_ERR_USB_DEVICE_NOT_SUPPORTED As Int16 = &H16 '#define HDL9BIT_ERR_USB_DEVICE_NOT_SUPPORTED 0x16 Const HDL9BIT_ERR_GENERIC_FAIL As Int16 = &HFF '#define HDL9BIT_ERR_GENERIC_FAIL 0xFF ' '/****************************************************************************** '* API Parameter Encodings '******************************************************************************/ '/* ' * Error Flags returned by HDL9BIT_GetUartAttributes() ' */ Const HDL9BIT_ERROR_FLAG_PARITY As Byte = 1 '#define HDL9BIT_ERROR_FLAG_PARITY 0x01 Const HDL9BIT_ERROR_FLAG_OVERFLOW As Byte = 2 '#define HDL9BIT_ERROR_FLAG_OVERFLOW 0x02 ' '/* ' * Number of data bits. Input to HDL9BIT_SetLineCoding() and ' * output of HDL9BIT_GetLineCoding() ' */ Const HDL9BIT_DATA_BITS_FIVE As Byte = 0 '#define HDL9BIT_DATA_BITS_FIVE 0x00 Const HDL9BIT_DATA_BITS_SIX As Byte = 1 '#define HDL9BIT_DATA_BITS_SIX 0x01 Const HDL9BIT_DATA_BITS_SEVEN As Byte = 2 '#define HDL9BIT_DATA_BITS_SEVEN 0x02 Const HDL9BIT_DATA_BITS_EIGHT As Byte = 3 '#define HDL9BIT_DATA_BITS_EIGHT 0x03 Const HDL9BIT_DATA_BITS_NINE As Byte = 4 '#define HDL9BIT_DATA_BITS_NINE 0x04 ' '/* ' * Parity types. Input to HDL9BIT_SetLineCoding() and ' * output of HDL9BIT_GetLineCoding() ' */ Const HDL9BIT_PARITY_NONE As Byte = 0 '#define HDL9BIT_PARITY_NONE 0x00 Const HDL9BIT_PARITY_ODD As Byte = 1 '#define HDL9BIT_PARITY_ODD 0x01 Const HDL9BIT_PARITY_EVEN As Byte = 2 '#define HDL9BIT_PARITY_EVEN 0x02 Const HDL9BIT_PARITY_MARK As Byte = 3 '#define HDL9BIT_PARITY_MARK 0x03 Const HDL9BIT_PARITY_SPACE As Byte = 4 '#define HDL9BIT_PARITY_SPACE 0x04 ' '/* ' * Character formats. Input to HDL9BIT_SetLineCoding() and ' * output of HDL9BIT_GetLineCoding() ' */ Const HDL9BIT_CHAR_FORMAT_STOP_SHORT As Byte = 0 '#define HDL9BIT_CHAR_FORMAT_STOP_SHORT 0x00 Const HDL9BIT_CHAR_FORMAT_STOP_LONG As Byte = 1 '#define HDL9BIT_CHAR_FORMAT_STOP_LONG 0x01 ' '/* ' * Flow control types. Input to HDL9BIT_SetLineCoding() and ' * output of HDL9BIT_GetLineCoding() ' */ Const HDL9BIT_FLOW_CONTROL_NONE As Byte = 0 '#define HDL9BIT_FLOW_CONTROL_NONE 0x00 Const HDL9BIT_FLOW_CONTROL_HW_RTS_CTS As Byte = 1 '#define HDL9BIT_FLOW_CONTROL_HW_RTS_CTS 0x01 Const HDL9BIT_FLOW_CONTROL_ADDRESS_MODE As Byte = 3 '#define HDL9BIT_FLOW_CONTROL_ADDRESS_MODE 0x03 ' ' メッセージ表示用 ' Private Sub memo(ByVal msg As String) RichTextBox_mon.AppendText(msg) RichTextBox_mon.AppendText(vbNewLine) RichTextBox_mon.ScrollToCaret() End Sub ' ret 表示用 Private Sub memo_ret(ByVal msg As String, ByVal ret As Integer) If ret = 0 Then RichTextBox_mon.ForeColor = Color.Black RichTextBox_mon.AppendText("*" + msg + " OK") Else RichTextBox_mon.ForeColor = Color.Red RichTextBox_mon.AppendText("*" + msg + " (" + Str(ret) + ") ----error!!!!") End If RichTextBox_mon.AppendText(vbNewLine) RichTextBox_mon.ScrollToCaret() End Sub Dim Handle9B As IntPtr Dim isOpenUart As Boolean Dim serialString(1000) As Byte Dim s_len As UShort Public Sub New() ' この呼び出しはデザイナーで必要です。 InitializeComponent() ' InitializeComponent() 呼び出しの後で初期化を追加します。 End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button_devno.Click Dim numUarts As Byte Dim ret As Int16 Dim memberIndex As Int32 Dim productIDFilter As UShort Dim interfaceIDFilter As Byte Dim manufacturingString(512) As Byte Dim ss1 As String Dim majorVersion As Byte Dim minorVersion As Byte Dim isReleaseVersion As Boolean While 1 '------------------------------------------------------------------- 'Returns the release version of this API. 'ファームウエアバージョン取得 ret = HDL9BIT_GetSoftwareAPIAttributes( majorVersion, '__out uint8_t* majorVersion, minorVersion, '__out uint8_t* minorVersion, isReleaseVersion '__out boolean_t* isReleaseVersion ) memo_ret("GetSoftwareAPIAttributes", ret) memo("majorVersion = " + Str(majorVersion)) memo("minorVersion = " + Str(majorVersion)) If isReleaseVersion Then memo("sReleaseVersion = 1") Else memo("sReleaseVersion = 0") End If '------------------------------------------------------------------- 'Returns the number of attached devices with matching IDs. 'デバイス数取得 ret = HDL9BIT_GetNumUartsA( productIDFilter, '__in_opt uint16_t productIDFilter, interfaceIDFilter, '__in_opt uint8_t interfaceIDFilter, numUarts '__out uint32l_t* numUarts ) memo_ret("HDL9BIT_GetNumUartsA", ret) Label_devn.Text = "Device=" + Str(numUarts) '------------------------------------------------------------------- 'Opens the device specified by the index into the array of available 'devices And returns a handle to it. 'UARTオープン memberIndex = 0 'ここでは最初の1つをオープンする productIDFilter = &H4001 interfaceIDFilter = 0 ret = HDL9BIT_OpenUartA( memberIndex, '__in uint32l_t memberIndex, productIDFilter, '__in_opt uint16_t productIDFilter, 0, '__in_opt uint8_t interfaceIDFilter, Handle9B '__out H9bHandle_t* uartDeviceObject ) memo_ret("HDL9BIT_OpenUartA", ret) If ret <> HDL9BIT_SUCCESS Then memo("Openできません") Exit While End If '------------------------------------------------------------------- 'Returns the current USB Manufacturer String. '製造メーカ名取得 ret = HDL9BIT_GetOtpManufacturerString( Handle9B, '__in H9bHandle_t uartDeviceObject, s_len, '__out uint8_t* strlen, manufacturingString 'ByVal __out char* manufacturingString ) memo_ret("HDL9BIT_GetOtpSerialNumberString", ret) ss1 = "[" & System.Text.Encoding.GetEncoding(1252).GetString(manufacturingString) ss1 = ss1.Substring(0, ss1.IndexOf(vbNullChar)) + "]" memo("manufacturingString =" + ss1) '------------------------------------------------------------------- 'Returns the current USB Serial Number String. 'デバイス固有番号(シリアル番号)取得 ret = HDL9BIT_GetOtpSerialNumberString( Handle9B, '__in H9bHandle_t uartDeviceObject, s_len, '__out uint8_t* stringLength, serialString 'ByVal __out char* serialString ) 'Handle9B, s_len, Serialnom) memo_ret("HDL9BIT_GetOtpSerialNumberString", ret) ss1 = "[" + System.Text.Encoding.GetEncoding(1252).GetString(serialString) ss1 = ss1.Substring(0, ss1.IndexOf(vbNullChar)) + "]" memo("Serial nomber =" + ss1) '------------------------------------------------------------------- 'Returns the current timeout settings. '送受信タイムアウト時間読み込み Dim writeTimeout As Int32 Dim readTimeout As Int32 ret = HDL9BIT_GetTimeouts( Handle9B, '__in H9bHandle_t uartDeviceObject, writeTimeout, '__out uint32l_t* readTimeout readTimeout '__out uint32l_t* readTimeout ) memo_ret("HDL9BIT_GetTimeouts", ret) '------------------------------------------------------------------- 'Sets maximum allowable time for read and write operations. '送受信タイムアウト時間設定 writeTimeout = 100 readTimeout = 2000 ret = HDL9BIT_SetTimeouts( Handle9B, '__in H9bHandle_t uartDeviceObject, writeTimeout, '__out uint32l_t* readTimeout readTimeout '__out uint32l_t* readTimeout ) memo_ret("HDL9BIT_SetTimeouts", ret) '------------------------------------------------------------------- 'Returns the currently configures data rate and character format '通信条件の読み込み Dim dataRate As Int32 Dim charFormat As Byte Dim parityType As Byte Dim dataBits As Byte Dim flowControl As Byte Dim gpioMode0 As Byte ret = HDL9BIT_GetLineCodingA( Handle9B, '__in H9bHandle_t uartDeviceObject, dataRate, '__out uint32l_t* dataRate, charFormat, '__out uint8_t* charFormat, parityType, '__out uint8_t* parityType, dataBits, '__out uint8_t* dataBits, flowControl, '__out uint8_t* flowControl, gpioMode0 '__out uint8_t* gpioMode0 ) memo_ret("HDL9BIT_GetLineCodingA", ret) '------------------------------------------------------------------- 'Configures the data rate and character format of a UART channel. '通信条件設定 dataBits = HDL9BIT_DATA_BITS_NINE '9bitモード指定 parityType = HDL9BIT_PARITY_NONE dataRate = 12000000 flowControl = HDL9BIT_FLOW_CONTROL_ADDRESS_MODE gpioMode0 = &H39 'addressモード時 flowControl = 0x03 'それ以外は flowControl = 0x01 'gpioMode0は0x39固定 ret = HDL9BIT_SetLineCodingA( Handle9B, '__in H9bHandle_t uartDeviceObject, dataRate, '__in uint32l_t dataRate, charFormat, '__in uint8_t charFormat, parityType, '__in uint8_t parityType, dataBits, '__in uint8_t dataBits, flowControl, '__in uint8_t flowControl, gpioMode0 '__in uint8_t gpioMode0 ) memo_ret("HDL9BIT_SetLineCodingA", ret) '------------------------------------------------------------------ 'Returns the currently configured addresses used by the UART when 'Address Match Mode is enabled. 'AddressModeで使用する設定アドレス取得 Dim unicastAddress As Byte Dim multicastAddress As Byte ret = HDL9BIT_GetUartAddress( Handle9B, '__in H9bHandle_t uartDeviceObject, unicastAddress, '__out uint8_t* unicastAddress, multicastAddress '__out uint8_t* multicastAddress ) memo_ret("HDL9BIT_GetUartAddress", ret) '------------------------------------------------------------------- 'Sets the addresses the UART will respond to when Address Match Mode 'is enabled. 'AddressModeで使用する設定アドレス設定 unicastAddress = &H55 multicastAddress = &H80 ret = HDL9BIT_SetUartAddress( Handle9B, '__in H9bHandle_t uartDeviceObject, unicastAddress, '__in uint8_t unicastAddress, multicastAddress '__in uint8_t multicastAddress ) memo_ret(" HDL9BIT_SetUartAddress", ret) ss1 = "0x" + unicastAddress.ToString("X2") memo("unicastAddress = " + ss1) ss1 = "0x" + multicastAddress.ToString("X2") memo("multicastAddress = " + ss1) '------------------------------------------------------------------- 'Returns the current setting for the number of bytes in the Rx FIFO 'before flow control is asserted to the remote UART. '受信FIFO動作しきい値読み込み Dim rxFifoThreshold As Int16 ret = HDL9BIT_GetUartRxFifoThreshold( Handle9B, '__in H9bHandle_t uartDeviceObject, rxFifoThreshold '__out uint16_t* rxFifoThreshold ) '------------------------------------------------------------------- 'Sets how many bytes will be stored in the local UART's Rx FIFO 'before flow control is asserted to the remote UART. '受信FIFO動作しきい値設定 rxFifoThreshold = 450 ret = HDL9BIT_SetUartRxFifoThreshold( Handle9B, ' __in H9bHandle_t uartDeviceObject, rxFifoThreshold '__in uint16_t rxFifoThreshold ) '------------------------------------------------------------------- 'Indicates whether a device handle is still open 'オープン状況問い合わせ Dim opened As Boolean opened = False isOpenUart = opened ret = HDL9BIT_IsOpen( Handle9B, opened '__out boolean_t* opened ) memo_ret("HDL9BIT_IsOpen", ret) If ret <> HDL9BIT_SUCCESS Then memo("Openしていません") Exit While End If isOpenUart = opened ' '-- end loop Exit While End While End Sub Private Sub Button_breakON_Click(sender As Object, e As EventArgs) Handles Button_breakON.Click While 1 Dim ret As Int16 If Not isOpenUart Then memo("Openしていません") Exit While End If ' '------------------------------------------------------------------- 'Requests a UART to transmit a break signal. 'ブレーク信号送信 Dim breakDuration As Byte breakDuration = 0 ret = HDL9BIT_SendBreak( Handle9B, '__in H9bHandle_t uartDeviceObject, breakDuration '__in uint8_t breakDuration ) memo_ret("HDL9BIT_SendBreak", ret) '-- end loop Exit While End While End Sub Private Sub Button_breakOFF_Click(sender As Object, e As EventArgs) Handles Button_breakOFF.Click While 1 Dim ret As Int16 If Not isOpenUart Then memo("Openしていません") Exit While End If ' '------------------------------------------------------------------- 'Requests a UART to stop transmitting break. 'ブレーク信号停止 ret = HDL9BIT_CancelBreak( Handle9B '__in H9bHandle_t uartDeviceObject, ) memo_ret("HDL9BIT_CancelBreak", ret) ' '-- end loop Exit While End While End Sub Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click While 1 Dim ret As Int16 If Not isOpenUart Then memo("Openしていません") Exit While End If ' '------------------------------------------------------------------- 'Close a device handle 'UARTクローズ ret = HDL9BIT_CloseUart( Handle9B '__in H9bHandle_t uartDeviceObject, ) memo_ret("HDL9BIT_CloseUart", ret) '-- end loop Exit While End While isOpenUart = False End Sub Private Sub Button_send_Click(sender As Object, e As EventArgs) Handles Button_send.Click While True If Not isOpenUart Then memo("Openしていません") Exit While End If ' Dim ret As Int16 Dim byteBuffer(1024) As Byte Dim numberOfBytesToWrite As Int32 Dim numberOfBytesWritten As Int32 '相手アドレス Dim address32 As Int32 Dim address As Byte address32 = Convert.ToInt32(TextBox_adress.Text, 16) address = address32 And &HFF '送信テキスト Dim s_text As String s_text = TextBox_stext.Text Dim byteBuffertemp(1024) As Byte byteBuffertemp = System.Text.Encoding.ASCII.GetBytes(s_text) Dim i As Integer byteBuffer(i) = address i = i + 1 byteBuffer(i) = 1 i = i + 1 For j As Integer = 0 To s_text.Length - 1 byteBuffer(i) = byteBuffertemp(j) byteBuffer(i + 1) = 0 i = i + 2 Next numberOfBytesToWrite = s_text.Length * 2 + 2 '------------------------------------------------------------------- 'Writes data to a UART handle (USB OUT transfers). '送信データ書き込み(送信) numberOfBytesToWrite = 128 ret = HDL9BIT_WriteUart( Handle9B, '__in H9bHandle_t uartDeviceObject, numberOfBytesToWrite, ' __in uint32l_t numberOfBytesToWrite, byteBuffer, 'ByVal __in uint8_t* byteBuffer, numberOfBytesWritten '__out uint32l_t* numberOfBytesWritten ) '------------------------------------------------------------------ ' 受信 '------------------------------------------------------------------- 'Reads data from a UART handle (USB IN transfers). '受信データ読み込み Dim numberOfBytesToRead As Int32 Dim numberOfBytesRead As Int32 numberOfBytesToRead = 256 memo(".....wait recieve..") ret = HDL9BIT_ReadUart( Handle9B, '__in H9bHandle_t uartDeviceObject, numberOfBytesToRead, ' __in uint32l_t numberOfBytesToRead, byteBuffer, ' __out uint8_t* byteBuffer, numberOfBytesRead ' __out uint32l_t* numberOfBytesRead ) If ret = HDL9BIT_SUCCESS Or ret = HDL9BIT_ERR_UART_READ_FAIL_TIME_OUT Then If Not numberOfBytesRead = 0 Then Dim rx_text As String rx_text = System.Text.Encoding.ASCII.GetString(byteBuffer) rx_text = BitConverter.ToString(byteBuffer) rx_text = rx_text.Substring(0, numberOfBytesRead * 3 - 1) memo("RXD=" + rx_text) End If End If memo(".....return") 'loop end Exit While End While End Sub End Class |
弊社ではプログラミングに関数サポートを行う立場ではございませんが、USB-306を操作する上での具体的なご質問があればメールにてお問い合わせをお願いいたします。 |
メールでのご質問はこちらへどうぞ |