public FtdiChip() {
example.ftdi_init(context);
example.ftdi_usb_open(context, 0x6666, 0x3133);
+ example.ftdi_usb_reset(context);
example.ftdi_set_baudrate(context, 750 * 1000);
example.ftdi_set_line_property(context, 8, 0, 0);
}
return b[0];
}
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
public void flush() {
try {
- byte[] bytes = baos.toByteArray();
- baos = new ByteArrayOutputStream();
- out.write(bytes, 0, bytes.length);
- out.flush();
- } catch (IOException e) { throw new RuntimeException(e); }
+ getOutputStream().flush();
+ } catch (Exception e) { throw new RuntimeException(e); }
}
- public boolean buffered = false;
protected static int mask =
(1<<0) |
(1<<1)// |
}
protected int dbits = 0;
+
+ public boolean buffered = false;
+ public void buffered() { /*buffered = true;*/ }
+ public void buffered(boolean buf) {
+ if (!buf) flush();
+ buffered = buf;
+ }
+
protected synchronized void dbang(int bit, boolean val) {
dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit)));
- if (buffered) {
- baos.write((byte)dbits);
- } else {
- try {
- out.write((byte)dbits);
- out.flush();
- } catch (IOException e) { throw new RuntimeException(e); }
- }
+ try {
+ out.write((byte)dbits);
+ if (!buffered) out.flush();
+ } catch (IOException e) { throw new RuntimeException(e); }
}