# 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.")
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 = 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
@author: LK ''' from PyTrinamicMicro import PyTrinamicMicro from PyTrinamicMicro.connections.tmcl_host_interface import tmcl_host_interface from PyTrinamicMicro.platforms.motionpy.connections.uart_tmcl_interface import uart_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 UART") logger.info("Initializing interfaces ...") host = usb_vcp_tmcl_interface() module = uart_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.")
# Constants MODULE_ADDRESS = 1 HOST_ADDRESS = 2 MODULE_ID_STRING = "0021" VERSION_STRING = MODULE_ID_STRING + "V100" BUILD_VERSION = 0 # Prepare Logger logger = logging.getLogger(__name__) logger.info("TMCL Slave on UART interface") # Main program logger.info("Initializing interface ...") con = uart_tmcl_interface() slave = TMCL_Slave_Main(MODULE_ADDRESS, HOST_ADDRESS, VERSION_STRING, BUILD_VERSION) logger.info("Interface initialized.") while (not (slave.status.stop)): 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) logger.info("Closing interface ...")