Skip to content

Commit e056388

Browse files
committed
Fix in arduino protocol
Removed a bug that was reporting a connection timeout when there wasn't one.
1 parent cb8313a commit e056388

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

MLC/GUI/Experiment/ArduinoConfigManager/ArduinoBoardManager.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def start_connection(self):
4343
stopbits=self.STOP_BITS[current_setup["stopbits"]],
4444
bytesize=self.BYTE_SIZE[current_setup["bytesize"]])
4545

46-
print self.__connection_config._asdict()
47-
4846
return SerialConnection(**self.__connection_config._asdict())
4947

5048
def start(self):

MLC/arduino/Firmware/GenericArduinoController.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ GenericArduinoController::GenericArduinoController(Stream &stream): stream_(stre
5353
executor[SET_REPORT_MODE_CMD] = &GenericArduinoController::set_report_mode;
5454
executor[ACTUATE_CMD] = &GenericArduinoController::actuate;
5555
executor[RESET_PINS] = &GenericArduinoController::reset;
56-
executor[VERSION_RESPONSE] = &GenericArduinoController::protocol_version;
56+
executor[PROTOCOL_VERSION] = &GenericArduinoController::protocol_version;
5757
}
5858

5959
void GenericArduinoController::handle_commands()
@@ -86,7 +86,7 @@ void GenericArduinoController::handle_commands()
8686

8787
void GenericArduinoController::add_handler(uint8_t handler_id, int (*handler)(GenericArduinoController* this_, const char*))
8888
{
89-
executor[handler_id] = this_;
89+
executor[handler_id] = handler;
9090
}
9191

9292
// NULL operation
@@ -103,7 +103,7 @@ int GenericArduinoController::protocol_version(GenericArduinoController* this_,
103103
char response[] = { char(VERSION_RESPONSE), char(0x03)};
104104
this_->stream_.write(response, 2);
105105
this_->stream_.write(VERSION, 3);
106-
return 5;
106+
return 2;
107107
}
108108

109109
/**

MLC/arduino/connection/serialconnection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def recv(self, length):
3939
"""
4040
recv = self._connection.read(length)
4141

42-
if recv != length:
42+
if len(recv) != length:
4343
raise serial.SerialTimeoutException
4444
else:
4545
return recv

MLC/arduino/protocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def actuate(self, data):
196196
pos = pos + 2
197197
pos = pos + 1
198198

199-
if self._report_mode == REPORT_MODE.AVERAGE:
199+
if self._report_mode == REPORT_MODES.AVERAGE:
200200
results["A%d" % (pin)] = [
201201
sum(results["A%d" % (pin)]) / (self._read_count + 1)]
202202
else:
@@ -206,7 +206,7 @@ def actuate(self, data):
206206
bool(ord(data[pos + 1 + i / 8]) & (0x01 << (i % 8))))
207207
pos = pos + 1 + self._read_count / 8 + 1
208208

209-
if self._report_mode == "AVERAGE":
209+
if self._report_mode == REPORT_MODES.AVERAGE:
210210
results["D%d" % (pin)] = [
211211
(sum(results["D%d" % (pin)]) * 2) > (self._read_count + 1)]
212212

tests/pocs/test_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#from MLC.arduino.connection import MockConnection
22
from MLC.arduino.connection import SerialConnection
3-
from MLC.arduino.protocol import ArduinoInterface
3+
from MLC.arduino.protocol import ArduinoInterface, REPORT_MODES
44
from MLC.arduino import boards
55
import sys
66
import time
@@ -10,7 +10,7 @@ def actuate(terminal):
1010
arduinoDue = ArduinoInterface(connection, boards.Due)
1111

1212
arduinoDue.reset()
13-
arduinoDue.set_report_mode("BULK", read_count=5, read_delay=100)
13+
arduinoDue.set_report_mode(REPORT_MODES.BULK, read_count=5, read_delay=100)
1414
arduinoDue.add_output(40)
1515
arduinoDue.add_input(64)
1616
arduinoDue.add_input(63)

0 commit comments

Comments
 (0)