''' Test TMCL GET_FIRMWARE_VERSION via RS232 interface and module ID 1. Created on 02.11.2020 @author: LK ''' from PyTrinamicMicro.platforms.motionpy.connections.rs232_tmcl_interface import rs232_tmcl_interface import logging import re VERSION_PATTERN = "^\d\d\d\dV\d\d\d$" logger = logging.getLogger(__name__) logger.info("Test interface RS232") logger.info("Initializing interface.") interface = rs232_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")
def real(ticks, prescaler, freq): return ((ticks * freq) / (prescaler + 1)) min_ticks = 0 max_ticks = 0 avg_ticks = 0 std_dev_ticks = 0 n = 0 timer = Timer(2) 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
@author: LK ''' from PyTrinamicMicro import PyTrinamicMicro from PyTrinamicMicro.connections.tmcl_host_interface import tmcl_host_interface from PyTrinamicMicro.platforms.motionpy.connections.rs232_tmcl_interface import rs232_tmcl_interface from PyTrinamicMicro.platforms.motionpy.connections.usb_vcp_tmcl_interface import usb_vcp_tmcl_interface from PyTrinamicMicro.TMCL_Bridge import TMCL_Bridge import logging # Prepare Logger PyTrinamicMicro.set_logging_console_enabled(False) logger = logging.getLogger(__name__) logger.info("TMCL Bridge from USB to RS232") logger.info("Initializing interfaces ...") host = usb_vcp_tmcl_interface() module = rs232_tmcl_interface() bridge = TMCL_Bridge(host, [{"module":module}]) 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.")
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() module.close() logger.info("Interfaces closed.") logger.info("Bridge stopped.")
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() module.close() logger.info("Interfaces closed.") logger.info("Bridge stopped.")
@author: LK ''' from PyTrinamicMicro.platforms.motionpy.connections.rs232_tmcl_interface import rs232_tmcl_interface from PyTrinamic.modules.TMCM1161.TMCM_1161 import TMCM_1161 import logging MODULE_ID = 1 GP_BANK = 0 AP_AXIS = 0 logger = logging.getLogger(__name__) logger.info("Test module TMCM1161 parameters via RS232") logger.info("Initializing interface.") interface = rs232_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( "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_0)) logger.info("{}".format(module.getGlobalParameter(module.GPs.timer_1, GP_BANK))) logger.info("Getting global parameter ({}, {}) ...".format(
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")