Esempio n. 1
0
    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
Esempio n. 2
0
    def sendBoot(self, moduleID=None):
        """
        Send the command for entering bootloader mode. This TMCL command does
        result in a reply.
        """
        # If no module ID is given, use the default one
        if not moduleID:
            moduleID = self._MODULE_ID

        request = TMCL_Request(moduleID, TMCL_Command.BOOT, 0x81, 0x92, 0xA3B4C5D6)

        if self._debug:
            request.dump()

        # Send the request
        self._send(self._HOST_ID, moduleID, request.toBuffer())
 def receive_request(self, host_id=None, module_id=None):
     if (not host_id):
         host_id = self.__host_id
     if (not module_id):
         module_id = self.__module_id
     request = TMCL_Request.from_buffer(self._recv(host_id, module_id))
     if (self.__debug):
         request.dump()
     return request
Esempio n. 4
0
    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
logger = logging.getLogger(__name__)
logger.info("Latency test RS232")

logger.info("Initializing interface.")
interface = rs232_tmcl_interface(data_rate=DATA_RATE)

logger.info("Performing test.")
ticks = (WORST_CASE_LATENCY * PAYLOAD * pyb.freq()[2] * 2) / 1000
prescaler = int(ticks / 0x3fffffff)
period = int((WORST_CASE_LATENCY * PAYLOAD * pyb.freq()[2] * 2) /
             (1000 * (prescaler + 1)))
while (n < N_SAMPLES):
    timer.counter(0)
    timer.init(prescaler=prescaler, period=period, callback=timeout)
    for i in range(0, PAYLOAD):
        interface.send_request_only(TMCL_Request(MODULE_ID, 1, 2, 3, 4, 5),
                                    host_id=HOST_ID,
                                    module_id=MODULE_ID)
    try:
        for i in range(0, PAYLOAD):
            interface.receive_reply(module_id=MODULE_ID, host_id=HOST_ID)
    except:
        pass
    timer.deinit()
    if (not (tout)):
        counter = timer.counter()
        logger.debug("Measured delta ticks: {}".format(counter))
        # update values
        value = (2 * PAYLOAD) / counter
        if (n == 0):
            min_ticks = value
Esempio n. 6
0
from PyTrinamicMicro.TMCL_Bridge import TMCL_Bridge
from PyTrinamic.TMCL import TMCL, TMCL_Request, TMCL_Reply
import logging

# Prepare Logger
logger = logging.getLogger(__name__)
logger.info("Test TMCL_Bridge")

logger.info("Initializing interfaces ...")
host = virtual_tmcl_interface()
modules = [{"module": virtual_tmcl_interface()}]
bridge = TMCL_Bridge(host, modules)
logger.info("Interfaces initialized.")

# Prepare requests
host.send_request_only(TMCL_Request(1, 2, 3, 4, 5))
host.send_request_only(TMCL_Request(3, 2, 3, 4, 5))
host.send_request_only(TMCL_Request(3, TMCL.COMMANDS["TMCL_UF0"], 0, 0,
                                    0))  # stop

# Prepare replies
modules[0]["module"].send_reply(TMCL_Reply(2, 1, 1, 2, 3))

while (not (bridge.process())):
    pass

if (host.data_available()):
    reply = host.receive_reply()
    assert ((reply.reply_address == 2) and (reply.module_address == 1)
            and (reply.status == 1) and (reply.command == 2)
            and (reply.value == 3)), "Received reply does not match sent reply"
Esempio n. 7
0
logger = logging.getLogger(__name__)
logger.info("Latency test RS232")

logger.info("Initializing interface.")
interface = rs232_tmcl_interface(data_rate=DATA_RATE)

logger.info("Performing test.")
ticks = (WORST_CASE_LATENCY * PAYLOAD * pyb.freq()[2] * 2) / 1000
prescaler = int(ticks / 0x3fffffff)
period = int((WORST_CASE_LATENCY * PAYLOAD * pyb.freq()[2] * 2) / (1000 * (prescaler + 1)))
while(n < N_SAMPLES):
    timer.counter(0)
    timer.init(prescaler=prescaler, period=period, callback=timeout)
    for i in range(0, PAYLOAD):
        interface.send_request_only(TMCL_Request(MODULE_ID, 1, 2, 3, 4, 5), host_id=HOST_ID, module_id=MODULE_ID)
    try:
        for i in range(0, PAYLOAD):
            interface.receive_reply(module_id=MODULE_ID, host_id=HOST_ID)
    except:
        pass
    timer.deinit()
    if(not(tout)):
        counter = timer.counter()
        logger.debug("Measured delta ticks: {}".format(counter))
        # update values
        value = (2 * PAYLOAD) / counter
        if(n == 0):
            min_ticks = value
            max_ticks = value
            avg_ticks = value
std_dev_ticks = 0
n = 0
timer = Timer(2)

logger = logging.getLogger(__name__)
logger.info("Latency test CAN")

logger.info("Initializing interface.")
interface = can_tmcl_interface()

logger.info("Performing test.")
while (n < N_SAMPLES):
    timer.counter(0)
    timer.init(prescaler=0, period=16800000, callback=timeout)
    # send invalid (for all modules) TMCL Request
    reply = interface.send_request(TMCL_Request(MODULE_ID, 1, 2, 3, 4, 5),
                                   host_id=HOST_ID,
                                   module_id=MODULE_ID)
    timer.deinit()
    if (not (tout)):
        counter = timer.counter()
        logger.debug("Measured delta ticks: {}".format(counter))
        # update values
        value = counter
        if (n == 0):
            min_ticks = value
            max_ticks = value
            avg_ticks = value
            std_dev_ticks = 0
        else:
            min_ticks = min(min_ticks, value)
Esempio n. 9
0
 def start_application(self):
     # Request without reply
     self.__interface.send_request(
         TMCL_Request(self.__module_id, TMCL_Command.BOOT_START_APPL, 0, 0,
                      0))
Esempio n. 10
0
 def erase_firmware(self, delay=5.0):
     self.__interface.send_request(
         TMCL_Request(self.__module_id, TMCL_Command.BOOT_ERASE_ALL, 0, 0,
                      0))
     time.sleep(delay)
Esempio n. 11
0
 def start_application(self):
     # Request without reply
     self.__interface.send_request(
         TMCL_Request(self.__module_id, TMCL.COMMANDS["BOOT_START_APPL"], 0,
                      0, 0))
Esempio n. 12
0
 def erase_firmware(self, delay=5.0):
     self.__interface.send_request(
         TMCL_Request(self.__module_id, TMCL.COMMANDS["BOOT_ERASE_ALL"], 0,
                      0, 0))
     time.sleep(delay)
Esempio n. 13
0
from PyTrinamicMicro.TMCL_Bridge import TMCL_Bridge
from PyTrinamic.TMCL import TMCL_Command, TMCL_Request, TMCL_Reply
import logging

# Prepare Logger
logger = logging.getLogger(__name__)
logger.info("Test TMCL_Bridge")

logger.info("Initializing interfaces ...")
host = virtual_tmcl_interface()
modules = [{"module": virtual_tmcl_interface()}]
bridge = TMCL_Bridge(host, modules)
logger.info("Interfaces initialized.")

# Prepare requests
host.send_request_only(TMCL_Request(1, 2, 3, 4, 5))
host.send_request_only(TMCL_Request(3, 2, 3, 4, 5))
host.send_request_only(TMCL_Request(3, TMCL_Command.TMCL_UF0, 0, 0, 0))  # stop

# Prepare replies
modules[0]["module"].send_reply(TMCL_Reply(2, 1, 1, 2, 3))

while (not (bridge.process())):
    pass

if (host.data_available()):
    reply = host.receive_reply()
    assert ((reply.reply_address == 2) and (reply.module_address == 1)
            and (reply.status == 1) and (reply.command == 2)
            and (reply.value == 3)), "Received reply does not match sent reply"
else:
Esempio n. 14
0
import re
import struct

VERSION_PATTERN = "^\d\d\d\dV\d\d\d$"

logger = logging.getLogger(__name__)

logger.info("Test TMCL_Slave")

logger.info("Initializing virtual interface.")
host = virtual_tmcl_interface()
res = virtual_tmcl_interface()

# Add virtual commands to interface
host.send_request_only(
    TMCL_Request(1, TMCL.COMMANDS["GET_FIRMWARE_VERSION"],
                 TMCM0960.ENUMs.VERSION_FORMAT_ASCII, 0, 0))
host.send_request_only(
    TMCL_Request(1, TMCL.COMMANDS["GET_FIRMWARE_VERSION"],
                 TMCM0960.ENUMs.VERSION_FORMAT_BINARY, 0, 0))
host.send_request_only(
    TMCL_Request(1, TMCL.COMMANDS["GET_FIRMWARE_VERSION"],
                 TMCM0960.ENUMs.VERSION_FORMAT_BUILD, 0, 0))
host.send_request_only(TMCL_Request(1, TMCL.COMMANDS["TMCL_UF0"], 0, 0,
                                    0))  # stop

slave = TMCL_Slave()

c = 0
while (not (slave.status.stop)):
    assert (c < 4), "TMCL_Slave did not stop on stop command"
    if (host.request_available()):
Esempio n. 15
0
import re
import struct

VERSION_PATTERN = "^\d\d\d\dV\d\d\d$"

logger = logging.getLogger(__name__)

logger.info("Test TMCL_Slave")

logger.info("Initializing virtual interface.")
host = virtual_tmcl_interface()
res = virtual_tmcl_interface()

# Add virtual commands to interface
host.send_request_only(
    TMCL_Request(1, TMCL_Command.GET_FIRMWARE_VERSION,
                 TMCM0960.ENUMs.VERSION_FORMAT_ASCII, 0, 0))
host.send_request_only(
    TMCL_Request(1, TMCL_Command.GET_FIRMWARE_VERSION,
                 TMCM0960.ENUMs.VERSION_FORMAT_BINARY, 0, 0))
host.send_request_only(
    TMCL_Request(1, TMCL_Command.GET_FIRMWARE_VERSION,
                 TMCM0960.ENUMs.VERSION_FORMAT_BUILD, 0, 0))
host.send_request_only(TMCL_Request(1, TMCL_Command.TMCL_UF0, 0, 0, 0))  # stop

slave = TMCL_Slave()

c = 0
while (not (slave.status.stop)):
    assert (c < 4), "TMCL_Slave did not stop on stop command"
    if (host.request_available()):
        logger.debug("Request available.")