Serial Port

>w## Notice > * please include the header file "bwsdk_api.h" when you need to use the serial port `#include "bwsdk_api.h"` >i## data structure ``` /** * @brief defined in system header file MercuryDef.h */ #ifndef BYTE typedef unsigned char BYTE; #endif #ifndef UINT typedef unsigned int UINT; #endif #ifndef ULONG typedef unsigned long ULONG; #endif ``` >i## USBAT_Init ### Prototype `void USBAT_Init(void);` ### Function * USBAT command initialize ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |none||| >i## USBATSend ### Prototype `void USBATSend(BYTE *buff, UINT len);` ### Function * send data ### Parameter |Name|Type|description| |-|-|-| |buff|BYTE *|send data buffer| |len|UINT|send data length| ### Retval |Value|Type|Description| |-|-|-| |none||| >i## USBATGet ### Prototype `INT USBATGet(BYTE *buff, UINT len, ULONG timeout_ms);` ### Function * receive data ### Parameter |Name|Type|description| |-|-|-| |buff|BYTE *|receive data buffer| |len|UINT|need to receive data maxmium length| |timeout_ms|ULONG|timeout millisecond| ### Retval |Value|Type|Description| |-|-|-| |>0|int|receive data length| |<=0|int|fail| >i## USBAT_Deinit ### Prototype `void USBAT_Deinit(void);` ### Function * USBAT command close ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |none||| >s## Example ``` int iLen = 0; char recvBuff[64] = {0}; ///< serial port init USBAT_Init(); DelayMs(15); ///< send data USBATSend("\x02\x00\x00\x03\x01", 5); DelayMs(15); while (1) { iLen = USBATGet((BYTE *)USBATGet, 32, 500); if (iLen > 0) { break; } } USBAT_Deinit(); ```