コード例 #1
0
@author: LK
'''

from PyTrinamicMicro.platforms.motionpy2.connections.can_tmcl_interface import can_tmcl_interface
from PyTrinamic.modules.TMCM1270.TMCM_1270 import TMCM_1270
import logging

MODULE_ID = 1
GP_BANK = 0
AP_AXIS = 0

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

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

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

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

logger.info("Getting global parameter ({}, {}) ...".format(
    "CANBitrate", module.GPs.CANBitrate))
logger.info("{}".format(
    module.getGlobalParameter(module.GPs.CANBitrate, GP_BANK)))
logger.info("Getting global parameter ({}, {}) ...".format(
    "CANSendId", module.GPs.CANSendId))
logger.info("{}".format(
    module.getGlobalParameter(module.GPs.CANSendId, GP_BANK)))
logger.info("Getting global parameter ({}, {}) ...".format(
コード例 #2
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()
コード例 #3
0
ファイル: version.py プロジェクト: trinamic/PyTrinamicMicro
Created on 02.11.2020

@author: LK
'''

from PyTrinamicMicro.platforms.motionpy2.connections.can_tmcl_interface import can_tmcl_interface
from PyTrinamicMicro.platforms.motionpy2.connections.rs232_tmcl_interface import rs232_tmcl_interface
from PyTrinamicMicro.platforms.motionpy2.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 = [
    can_tmcl_interface(),
    rs232_tmcl_interface(),
    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")
コード例 #4
0
from PyTrinamicMicro import PyTrinamicMicro
import struct
import logging
import time

# Prepare Logger
PyTrinamicMicro.set_logging_console_enabled(False)
logger = logging.getLogger(__name__)
logger.info("TMCL Slave on USB_VCP interface")

# Main program
lin = None
logger.info("Initializing interface ...")
con = usb_vcp_tmcl_interface()
slave = tmcl_slave_demo()
module = TMCM_1270(can_tmcl_interface())
module.setMaxAcceleration(0, 100000)
logger.info("Interface initialized.")

t = 0

while (not (slave.status.stop)):
    # Handle connection
    if (con.request_available()):
        logger.debug("Request available.")
        request = con.receive_request()
        if (not (slave.filter(request))):
            continue
        logger.debug("Request for this slave detected.")
        reply = slave.handle_request(request)
        con.send_reply(reply)
コード例 #5
0
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
コード例 #6
0
'''
Update firmware of attached board via CAN.

Created on 19.10.2020

@author: LK
'''

from PyTrinamicMicro.platforms.motionpy2.connections.can_tmcl_interface import can_tmcl_interface
from PyTrinamicMicro.tmcl_bootloader import *
import logging
import time

FIRMWARE = "firmware.hex"
MODULE_ID = 1

con = can_tmcl_interface()
con.sendBoot()
time.sleep(3.0)
boot = tmcl_bootloader(con, MODULE_ID)
boot.update_firmware(open(FIRMWARE, "rt"),
                     start=True,
                     checksum_error=False,
                     verify_hex=True,
                     verify_bootloader=True)
コード例 #7
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()
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()
コード例 #8
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.")