#id RefGoExtensionExampleEvt.py 2023-03-20 oh # Fullmo MovingCap CODE - micropython example. # original file name: refGoExtensionExampleEvt.py # requires turnTRACK firmware v50.00.05.05_RE higher # This example shows how to mimic the original XENAX protocol events @H, @S1, @S2.. # Note: This is for demonstration purposes. For practical applications, # calling the text-based "refgo" interface 10 times per milliseconds is a waste # of CPU time, but it demonstrates how fast MovingCap can run micropython code, # even if it includes string processing. # With events enabled and used, the main loop is processed in around 0.125 milliseconds. import sys import mccom import refgo counter = 0 ret = 0 lasttime = sys.time() evtActive = 0 oldTsValue = -1 tsValue = 0 mccom.open("refgo", 0) cmd = "" while (1): cmd = mccom.read(0, 0) if cmd is not None: if (cmd == "EVT1"): evtActive = 1 mccom.write(0, 0, "@H\r\n") elif (cmd == "EVT0"): evtActive = 0 oldTsValue = -1 # always finish with prompt ret = mccom.write(0, 0, ">") if evtActive == 1: # create a "@S" event from the TS (Tell Status) return value tsValue = refgo.cmd("TS") if tsValue is not None: if (tsValue != oldTsValue): oldTsValue = tsValue ret = mccom.write(0, 0, "@S" + str(tsValue) + "\r\n>") counter += 1 if (counter == 100000): print ("Performance info: " + str(counter) + " loops needed " + str(sys.time() - lasttime) + " milliseconds") lasttime = sys.time() counter = 0