有人知道如何在Android中设置与controlTransfer的奇偶校验吗?
我找不到这个方法的参数的解释-只有一些通用的信息在ref.
我发现的一个例子是:
conn.controlTransfer(0x40, 0x04, 0x0008, 0, null, 0, 0); //data bit 8, parity none, stop bit 1, tx off
但是我需要改变奇偶校验。有人知道吗?
多谢!
您可以定义位的组合来创建您自己的配置(奇偶校验,停止位&数据位)。
conn.controlTransfer(0x40, 0x04, 0x0008, 0, null, 0, 0);
第一个参数- 0x40 -请求设置或获取控制数据
#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40
第二个参数- 0x04 -要设置或获取的数据类型
#define FTDI_SIO_RESET 0 /* Reset the port */
#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */
#define FTDI_SIO_SET_FLOW_CTRL 2 /* Set flow control register */
#define FTDI_SIO_SET_BAUD_RATE 3 /* Set baud rate */
#define FTDI_SIO_SET_DATA 4 /* Set the data characteristics of the port */
#define FTDI_SIO_GET_MODEM_STATUS 5 /* Retrieve current value of modern status register */
#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */
#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */
第三个参数—0x0008—数据位8,无奇偶校验,停止位1,tx off—实际要传递的数据。
第三个参数是一个16位数据,可以由下面定义的常量组成:
Bits 0 to 7 -- Number of data bits
Bits 8 to 10 -- Parity
0 = None
1 = Odd
2 = Even
3 = Mark
4 = Space
Bits 11 to 13 -- Stop Bits
0 = 1
1 = 1.5
2 = 2
Bit 14
1 = TX ON (break)
0 = TX OFF (normal state)
Bit15 -- Reserved
#define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA
#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8)
#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8)
#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8)
#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8)
#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8)
#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11)
#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11)
#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11)
#define FTDI_SIO_SET_BREAK (0x1 << 14)
波特率:
* Value Baud Rate speed
* 0×2710 300
* 0×1388 600
* 0x09C4 1200
* 0x04E2 2400
* 0×0271 4800
* 0×4138 9600
* 0x80D0 14400
* 0x809C 19200
* 0xC04E 38400
* 0×0034 57600
* 0x001A 115200
* 0x000D 230400
* 0×4006 460800
* 0×8003 921600
*/
详情请参考以下连结:
http://read.pudn.com/downloads181/sourcecode/embed/842049/usb/serial/ftdi_sio.h__.htm http://www.mev.co.uk/pages/Support/USB-Baud-Spoof.html