Beispiel #1
0
# When using a CAN module, Checksum needs to be recalculated.

request_command = 0

def request_callback(request):
    global request_command
    request_command = request.command
    return request

def reply_callback(reply):
    if(request_command != TMCL.COMMANDS["GET_FIRMWARE_VERSION"]):
        reply.calculate_checksum()
    return reply

logger.info("Initializing interfaces ...")
host = uart_tmcl_interface()
module = can_tmcl_interface()
bridge = TMCL_Bridge(host, [{"module":module, "request_callback":request_callback, "reply_callback":reply_callback}])
logger.info("Interfaces initialized.")

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

logger.info("Closing interfaces ...")
host.close()
module.close()
logger.info("Interfaces closed.")

logger.info("Bridge stopped.")
Beispiel #2
0
'''
Test TMCL GET_FIRMWARE_VERSION via CAN interface and module ID 1.

Created on 02.11.2020

@author: LK
'''

from PyTrinamicMicro.platforms.motionpy.connections.can_tmcl_interface import can_tmcl_interface
import logging
import re

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

logger = logging.getLogger(__name__)
logger.info("Test interface CAN")

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

logger.info("Issuing GET_FIRMWARE_VERSION.")
value = interface.getVersionString()
logger.info("Value: {}.".format(value))

assert re.match(VERSION_PATTERN, value), "Invalid version string"
logger.info("Version string valid")
'''
Rotate the motor with TMCM1240 using CAN interface.

Created on 21.10.2020

@author: LK
'''

from PyTrinamic.modules.TMCM1240.TMCM_1240 import TMCM_1240
from PyTrinamicMicro.platforms.motionpy.connections.can_tmcl_interface import can_tmcl_interface
import time

con = can_tmcl_interface()
module = TMCM_1240(con)

module.rotate(50000)
time.sleep(5)
module.stop()

con.close()
@author: LK
'''

from PyTrinamicMicro.platforms.motionpy.connections.can_tmcl_interface import can_tmcl_interface
from PyTrinamic.modules.TMCM1240.TMCM_1240 import TMCM_1240
import logging

MODULE_ID = 1
GP_BANK = 0
AP_AXIS = 0

logger = logging.getLogger(__name__)
logger.info("Test module TMCM1240 parameters via CAN")

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

logger.info("Initializing module.")
module = TMCM_1240(interface)

logger.info("Testing global parameter access.")

logger.info("Getting global parameter ({}, {}) ...".format(
    "timer_0", module.GPs.timer_0))
logger.info("{}".format(module.getGlobalParameter(module.GPs.timer_0,
                                                  GP_BANK)))
logger.info("Getting global parameter ({}, {}) ...".format(
    "timer_1", module.GPs.timer_1))
logger.info("{}".format(module.getGlobalParameter(module.GPs.timer_1,
                                                  GP_BANK)))
logger.info("Getting global parameter ({}, {}) ...".format(
Beispiel #5
0
    request_command = request.command
    return request


def reply_callback(reply):
    if (request_command != TMCL.COMMANDS["GET_FIRMWARE_VERSION"]):
        reply.calculate_checksum()
    return reply


logger.info("Initializing interfaces ...")
host = usb_vcp_tmcl_interface()
modules = [{
    "module": uart_tmcl_interface()
}, {
    "module": can_tmcl_interface(),
    "request_callback": request_callback,
    "reply_callback": reply_callback
}, {
    "module": rs232_tmcl_interface()
}, {
    "module": rs485_tmcl_interface()
}]
bridge = TMCL_Bridge(host, modules)
logger.info("Interfaces initialized.")

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

logger.info("Closing interfaces ...")
host.close()
Beispiel #6
0
def request_callback(request):
    global request_command
    request_command = request.command
    return request


def reply_callback(reply):
    if (request_command != TMCL_Command.GET_FIRMWARE_VERSION):
        reply.calculate_checksum()
    return reply


logger.info("Initializing interfaces ...")
host = uart_tmcl_interface()
modules = [{
    "module": can_tmcl_interface(debug=True),
    "request_callback": request_callback,
    "reply_callback": reply_callback
}, {
    "module": rs232_tmcl_interface(debug=True)
}, {
    "module": rs485_tmcl_interface(debug=True)
}]
bridge = TMCL_Bridge(host, modules)
logger.info("Interfaces initialized.")

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

logger.info("Closing interfaces ...")
host.close()
logger = logging.getLogger(__name__)
logger.info("CAN Logger")


# Callback for received requests
def callback_request(request):
    logger.info(request.disassemble())


# Callback for received replies
def callback_reply(reply):
    logger.info(reply.disassemble())


logger.info("Initializing interface ...")
bus = can_tmcl_interface(host_id=2, module_id=1, can_mode=CanModeSilent())
logger.info("Interface initialized.")

logger.info("Initializing tmcl_analyzer ...")
# Set callback to print disassembled TMCL requests and their replies
# Set measurement window for throughput to 100 ms (not requested but nice to have)
analyzer = tmcl_analyzer(connection_host=bus,
                         connection_module=bus,
                         callback_request=callback_request,
                         callback_reply=callback_reply,
                         measure_window=0.1)
logger.info("tmcl_analyzer initialized.")

logger.info("Start logging.")

# Main loop
Beispiel #8
0
Created on 02.11.2020

@author: LK
'''

from PyTrinamicMicro.platforms.motionpy.connections.can_tmcl_interface import can_tmcl_interface
from PyTrinamicMicro.platforms.motionpy.connections.rs232_tmcl_interface import rs232_tmcl_interface
from PyTrinamicMicro.platforms.motionpy.connections.rs485_tmcl_interface import rs485_tmcl_interface
import logging
import re

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

logger = logging.getLogger(__name__)
logger.info("Test GET_FIRMWARE_VERSION for CAN, RS232 and RS485 interfaces.")

logger.info("Initializing interfaces.")
interfaces = set()
interfaces.add(can_tmcl_interface())
interfaces.add(rs232_tmcl_interface())
interfaces.add(rs485_tmcl_interface())

for interface in interfaces:
    logger.info(
        "Issuing GET_FIRMWARE_VERSION on interface {}.".format(interface))
    value = interface.getVersionString()
    logger.info("Value: {}.".format(value))
    assert re.match(VERSION_PATTERN, value), "Invalid version string"
    logger.info("Version string valid")