问题描述
有人知道如何在 Android 中使用 controlTransfer 设置奇偶校验吗?
Anybody knows how to set the parity with the controlTransfer in Android?
我在任何地方都找不到此方法参数的解释 - 只是参考中的一些通用信息.
I can't find the explanation of this method's parameters anywhere - just some generic info in the ref.
我发现的一个例子是:
conn.controlTransfer(0x40, 0x04, 0x0008, 0, null, 0, 0); //data bit 8, parity none, stop bit 1, tx off
但我需要更改奇偶校验.有人有想法吗?
But I need to change the parity. Anybody has an idea?
非常感谢!
推荐答案
您可以定义位组合来创建自己的配置(奇偶校验、停止位和数据位).
You can define the combination of bits to create your own configuration (parity, stop bit & data bit).
conn.controlTransfer(0x40, 0x04, 0x0008, 0, null, 0, 0);
第一个参数 - 0x40 - 请求设置或获取控制数据
1st parameter - 0x40 - request to set or get control data
#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40
第二个参数 - 0x04 - 要设置或获取的数据类型
2nd parameter - 0x04 - type of data to be set or get
#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——是要传递的实际数据.
Third parameter - 0x0008 - data bit 8, parity none, stop bit 1, tx off - Is the actual data to be passed.
第三个参数是一个 16 位的数据,可以由下面定义的常量组成:
The third parameter is a 16 bit data which can be formed from the constants defined below:
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
*/
更多详情请参考以下链接:
Please refer the below links for more details:
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
这篇关于使用 controlTransfer 方法设置奇偶校验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!