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.
One example I found says:
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?
Many thanks!
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);
1st parameter - 0x40 - request to set or get control data
#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40
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 */
Third parameter - 0x0008 - data bit 8, parity none, stop bit 1, tx off - Is the actual data to be passed.
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)
For baud rate :
* 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With