Skip navigation links
Technology For Tomorrow
Android SDK Flow
Technology For Tomorrow
UART(1/2)
宣告 HidToUart 物件, 帶入appName
m_hidToUart= new HidToUart(MainActivity.this,
DEFINE_ACTION_USB_PERMISSION)
註冊USB device 插拔通知
m_intentFilter = new IntentFilter(DEFINE_ACTION_USB_PERMISSION);
m_intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
m_intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
if(broadCastUsbReceiver != null)
registerReceiver(broadCastUsbReceiver, m_intentFilter);
確認權限
if(false == m_hidToUart.hasPermissionByDeviceIndex(0))
m_hidToUart.askPermissionByDeviceIndex(0);
Technology For Tomorrow
UART(2/2)
開啟裝置並設定裝置
nRes = m_hidToUart.openDeviceByIndex(index);//index start at 0
nRes = m_hidToUart.setUartConfig(index, m_uartSettingObject);
// BaudRate/StopBit/ParityType/DataBit/FlowControl
進行讀寫
nRes = m_hidToUart.uartWrite(index, byTempWriteBuffer,
byTempWriteBuffer.length, 1000); //write
nRes = m_hidToUart.uartRead(index, byTempReadBuffer,
byTempReadBuffer.length, 1000); //read
關閉裝置
m_hidToUart.closeDevice(index);
列舉裝置
m_nUsbDeviceCount = m_hidToUart.enumDevices(m_nDeviceVid);
Technology For Tomorrow
I2C(1/2)
宣告 HidToI2c 物件, 帶入appName
m_hidToI2c = new HidToI2c(MainActivity.this,
DEFINE_ACTION_USB_PERMISSION)
註冊USB device 插拔通知
m_intentFilter = new IntentFilter(DEFINE_ACTION_USB_PERMISSION);
m_intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
m_intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
if(broadCastUsbReceiver != null)
registerReceiver(broadCastUsbReceiver, m_intentFilter);
確認權限
if(false == m_hidToI2c.hasPermissionByDeviceIndex(0))
m_hidToI2c.askPermissionByDeviceIndex(0);
Technology For Tomorrow
I2C(2/2)
列舉裝置
m_nUsbDeviceCount = m_hidToI2c.enumDevices(m_nDeviceVid);
開啟裝置且設定頻率
nRes = m_hidToI2c.openDeviceByIndex(0);
nRes = m_hidToI2c.setI2cFrequency(index, (byte) m_nClockDivider);
設定DeviceAddress
nRes = m_hidToI2c.setI2cDeviceAddress(index, byDeviceAddr);
進行讀寫並確認I2C狀態
(Follow I2C Protocol WaveForm發送I2C讀寫命令)
nRes = m_hidToI2c.i2cWrite(index,I2cSetting.TransferType.I2C_START_STOP, byTemp, nHidWritePacketSize,
100);
nStatus = m_hidToI2c.getI2cStatus(index);
nRes = m_hidToI2c.i2cRead(index, I2cSetting.TransferType.I2C_START_STOP, byTempData, nRecvLength,
100);
關閉裝置
m_hidToI2c.closeDevice(index);
Technology For Tomorrow
SPI(1/2)
註冊USB device 插拔通知
m_intentFilter = new IntentFilter(DEFINE_ACTION_USB_PERMISSION);
m_intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
m_intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
if(broadCastUsbReceiver != null)
registerReceiver(broadCastUsbReceiver, m_intentFilter);
確認權限
if(false == m_hidToSpi .hasPermissionByDeviceIndex(0))
m_hidToSpi.askPermissionByDeviceIndex(0);
宣告 HidToSpi 物件, 帶入appName
m_hidToSpi = new HidToSpi(MainActivity.this,
DEFINE_ACTION_USB_PERMISSION)
Technology For Tomorrow
SPI(2/2)
列舉裝置
m_nUsbDeviceCount = m_hidToSpi.enumDevices(m_nDeviceVid);
開啟裝置且設定頻率
nRes = m_hidToSpi.openDeviceByIndex(0);
nRes = m_hidToSpi.setSpiFrequency(index, (byte)m_nClockDivider,
SpiSetting.SPI_MODE.SPI_MODE3);
進行讀寫
(Follow SPI Protocol WaveForm發送SPI命令與資料)
nRes = m_hidToSpi.spiWrite(index, gChipSelect, csControl, byRegData,
byRegData.length, 100);
nRes = m_hidToSpi.spiRead(index, gChipSelect, csControl, byData, nRecvLength, 100);
關閉裝置
m_hidToSpi.closeDevice(index);