Fix bugs in read and write methods.
SmartBotKit/serial/master This commit looks good

This commit is contained in:
Marcus Handte
2019-05-06 16:10:08 +02:00
parent 5ae66da6cf
commit 43c51ecdcc
3 changed files with 5 additions and 5 deletions
@@ -317,7 +317,7 @@ public class CDCSerialPort extends AbstractSerialPort {
@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
int read = connection.bulkTransfer(in, buffer, length, 0);
int read = connection.bulkTransfer(in, buffer, offset, length, 0);
if (read < 0) return read;
throwIfNegative(receiveControlTransfer(SERIAL_STATE, 0, statusBuffer), "Failed to read modem status (error: %s).");
interpretModemData(statusBuffer[0], statusBuffer[1]);
@@ -343,7 +343,7 @@ public class CDCSerialPort extends AbstractSerialPort {
@Override
public void write(byte[] buffer, int offset, int length) throws IOException {
while (length > 0) {
int res = connection.bulkTransfer(out, buffer, offset, buffer.length, 0);
int res = connection.bulkTransfer(out, buffer, offset, length, 0);
if (res < 0) throw new IOException(String.format("Failed to write bytes (error: %d)", res));
offset += res;
length -= res;
@@ -376,7 +376,7 @@ public class CP210XSerialPort extends AbstractSerialPort {
@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
int read = connection.bulkTransfer(in, buffer, length, 0);
int read = connection.bulkTransfer(in, buffer, offset, length, 0);
if (read < 0) return read;
interpretModemData(getModemState()[0], getCommStatus()[0]);
return read;
@@ -401,7 +401,7 @@ public class CP210XSerialPort extends AbstractSerialPort {
@Override
public void write(byte[] buffer, int offset, int length) throws IOException {
while (length > 0) {
int res = connection.bulkTransfer(out, buffer, offset, buffer.length, 0);
int res = connection.bulkTransfer(out, buffer, offset, length, 0);
if (res < 0) throw new IOException(String.format("Failed to write bytes (error: %d)", res));
offset += res;
length -= res;
@@ -383,7 +383,7 @@ public class FTDISerialPort extends AbstractSerialPort {
@Override
public void write(byte[] buffer, int offset, int length) throws IOException {
while (length > 0) {
int res = connection.bulkTransfer(out, buffer, offset, buffer.length, 0);
int res = connection.bulkTransfer(out, buffer, offset, length, 0);
if (res < 0) throw new IOException(String.format("Failed to write bytes (error: %d)", res));
offset += res;
length -= res;