谁能告诉我下面两种波特率设置方法是什么意思?
第一种是网上的:
private boolean configUsb(int paramInt)
{
byte[] arrayOfByte = new byte[8];
connection.controlTransfer(192, 95, 0, 0, arrayOfByte, 8, 1000);
connection.controlTransfer(64, 161, 0, 0, null, 0, 1000);
long l1 = 1532620800 / paramInt;
for (int i = 3; ; i--) {
if ((l1 <= 65520L) || (i <= 0)) {
long l2 = 65536L - l1;
int j = (short) (int) (0xFF00 & l2 | i);
int k = (short) (int) (0xFF & l2);
connection.controlTransfer(64, 154, 4882, j, null, 0, 1000);
connection.controlTransfer(64, 154, 3884, k, null, 0, 1000);
connection.controlTransfer(192, 149, 9496, 0, arrayOfByte, 8, 1000);
connection.controlTransfer(64, 154, 1304, 80, null, 0, 1000);
connection.controlTransfer(64, 161, 20511, 55562, null, 0, 1000);
connection.controlTransfer(64, 154, 4882, j, null, 0, 1000);
connection.controlTransfer(64, 154, 3884, k, null, 0, 1000);
connection.controlTransfer(64, 164, 0, 0, null, 0, 1000);
return true;
}
l1 >>= 3;
}
}
第二种是H34驱动里的:
public boolean SetConfig(int baudRate, byte dataBit, byte stopBit, byte parity, byte flowControl){
int value = 0;
int index = 0;
char valueHigh = 0, valueLow = 0, indexHigh = 0, indexLow = 0;
switch(parity) {
case 0: /*NONE*/
valueHigh = 0x00;
break;
case 1: /*ODD*/
valueHigh |= 0x08;
break;
case 2: /*Even*/
valueHigh |= 0x18;
break;
case 3: /*Mark*/
valueHigh |= 0x28;
break;
case 4: /*Space*/
valueHigh |= 0x38;
break;
default: /*None*/
valueHigh = 0x00;
break;
}
if(stopBit == 2) {
valueHigh |= 0x04;
}
switch(dataBit) {
case 5:
valueHigh |= 0x00;
break;
case 6:
valueHigh |= 0x01;
break;
case 7:
valueHigh |= 0x02;
break;
case 8:
valueHigh |= 0x03;
break;
default:
valueHigh |= 0x03;
break;
}
valueHigh |= 0xc0;
valueLow = 0x9c;
value |= valueLow;
value |= (int)(valueHigh << 8);
switch(baudRate) {
case 50:
indexLow = 0;
indexHigh = 0x16;
break;
case 75:
indexLow = 0;
indexHigh = 0x64;
break;
case 110:
indexLow = 0;
indexHigh = 0x96;
break;
case 135:
indexLow = 0;
indexHigh = 0xa9;
break;
case 150:
indexLow = 0;
indexHigh = 0xb2;
break;
case 300:
indexLow = 0;
indexHigh = 0xd9;
break;
case 600:
indexLow = 1;
indexHigh = 0x64;
break;
case 1200:
indexLow = 1;
indexHigh = 0xb2;
break;
case 1800:
indexLow = 1;
indexHigh = 0xcc;
break;
case 2400:
indexLow = 1;
indexHigh = 0xd9;
break;
case 4800:
indexLow = 2;
indexHigh = 0x64;
break;
case 9600:
indexLow = 2;
indexHigh = 0xb2;
break;
case 19200:
indexLow = 2;
indexHigh = 0xd9;
break;
case 38400:
indexLow = 3;
indexHigh = 0x64;
break;
case 57600:
indexLow = 3;
indexHigh = 0x98;
break;
case 115200:
indexLow = 3;
indexHigh = 0xcc;
break;
case 230400:
indexLow = 3;
indexHigh = 0xe6;
break;
case 460800:
indexLow = 3;
indexHigh = 0xf3;
break;
case 500000:
indexLow = 3;
indexHigh = 0xf4;
break;
case 921600:
indexLow = 7;
indexHigh = 0xf3;
break;
case 1000000:
indexLow = 3;
indexHigh = 0xfa;
break;
case 2000000:
indexLow = 3;
indexHigh = 0xfd;
break;
case 3000000:
indexLow = 3;
indexHigh = 0xfe;
break;
default: // default baudRate "9600"
indexLow = 2;
indexHigh = 0xb2;
break;
}
index |= 0x88 |indexLow;
index |= (int)(indexHigh << 8);
Uart_Control_Out(161, value, index);
/* if(flowControl == 1) {
Uart_Tiocmset(UartModem.TIOCM_DTR | UartModem.TIOCM_RTS, 0x00);
}*/
return true;
}
}
int DEFAULT_TIMEOUT=1000;
public int Uart_Control_Out(int request, int value, int index)
{
int retval = 0;
retval = connection.controlTransfer(64,
request, value, index, null, 0, DEFAULT_TIMEOUT);
L.add("64,"+ request+","+value+","+index+","+null+",0, "+DEFAULT_TIMEOUT);
return retval;
}
以上两种都是可行的,第二种加了其他设置