# Change XYZ to the UID of your CAN Bricklet 2.0

setup:
	# Configure transceiver for loopback mode
	publish '{"baud_rate": 1000000, "sample_point": 625, "transceiver_mode": "loopback"}' to tinkerforge/request/can_v2_bricklet/XYZ/set_transceiver_configuration

	# Handle incoming frame read callbacks
	subscribe to tinkerforge/callback/can_v2_bricklet/XYZ/frame_read
		if a message arrives:
			# message contains frame_type as int with symbols, identifier as int and data as int array
			if frame_type == "standard_data"
				print "Frame Type: Standard Data"
			elseif frame_type == "standard_remote"
				print "Frame Type: Standard Remote"
			elseif frame_type == "extended_data"
				print "Frame Type: Extended Remote"
			elseif frame_type == "extended_remote"
				print "Frame Type: Extended Remote"
			endif

			print "Identifier: " + identifier
			print "Data: " + data
			print "\n"
		endif
	endsubscribe

	publish '{"register": true}' to tinkerforge/register/can_v2_bricklet/XYZ/frame_read # Register frame_read callback

	# Enable frame read callback
	publish '{"enabled": true}' to tinkerforge/request/can_v2_bricklet/XYZ/set_frame_read_callback_configuration

	# Write standard data frame with identifier 1742 and 3 bytes of data
	publish '{"frame_type": "standard_data", "identifier": 1742, "data": [42,23,17]}' to tinkerforge/request/can_v2_bricklet/XYZ/write_frame

cleanup:
	# If you are done, run this to clean up
	publish '{"enabled": false}' to tinkerforge/request/can_v2_bricklet/XYZ/set_frame_read_callback_configuration
