def send(self, opcode, opType, motor, value, moduleID=None): """ Send a TMCL datagram and read back a reply. This function blocks until the reply has been received """ if not (type(opcode) == type(opType) == type(motor) == type(value) == int): raise TypeError("Expected integer values") # If no module ID is given, use the default one if not moduleID: moduleID = self._MODULE_ID request = TMCL_Request(moduleID, opcode, opType, motor, value) if self._debug: request.dump() # Send the request self._send(self._HOST_ID, moduleID, request.toBuffer()) # Read out the reply reply = TMCL_Reply(self._recv(self._HOST_ID, moduleID)) if self._debug: reply.dump() return reply
def send ( self, address, command, commandType, motorbank, value ): """ Send a message to the specified module. This is a blocking function that will not return until a reply has been received from the module. """ "prepare TMCL request" request = TMCL_Request(address, command, commandType, motorbank, value) if self.debugEnabled: request.dump() "send request, wait, and handle reply" self.serial.write(request.toBuffer()) reply = TMCL_Reply(struct.unpack(TMCL.PACKAGE_STRUCTURE, self.serial.read(TMCL.PACKAGE_LENGTH))) if self.debugEnabled: reply.dump() return reply