import OMLibrary as OM import time #Using original code start_time = time.time() input = input("What alarm value do you want to implement?" ) #Check page 345 in AZ Series book:Maintenance Commands address = '01' fcode = '06' uregaddr = '01' legaddr = str(input) unumreg = '00' lnumreg = '01' numbytes = '' unreg = '' lnreg = '' [ser, ports] = OM.initSerial('USBtoUART') hexval = OM.WriteMultiReg(ser, address, fcode, uregaddr, legaddr, unumreg, lnumreg, numbytes, unreg, lnreg, 0.05) print("--- Program took %s seconds ---" % (time.time() - start_time)) #Using Library function OM.ResetAlarm('USBtoUART', '01', '81') #Alarm reset # OM.ResetAlarm('01','85') #Clear alarm records # OM.ResetAlarm('01','89') # Clearn communcation error records
import OMLibrary as OM import time start_time = time.time() ser = OM.initSerial('USBtoUART') wt = 0.007 addval = '01' #Set Position Example address = addval fcode = '10' uregaddr = '04' #if relative 10, if absolute 04 legaddr = '00' #if relative 48, if absolute 00 unumreg = '00' lnumreg = '02' numbytes = '04' unreg = '0000' lnreg = '000F' #5000steps if ser.isOpen(): print('Open: ' + ser.portstr) else: print("Was closed, now opening") ser.open() # Write to register to do actuation, change alarm settings, etc. # address of the device # '030300800002C401' original checksum hexval = address + fcode + uregaddr + legaddr + unumreg + lnumreg + numbytes + unreg + lnreg # Check Pg 145 in AR series book hexval = OM.crc16(hexval) # ser.write(b"0310040000020400000FFF8f67") ser.write(bytearray.fromhex(hexval)) time.sleep(wt) # ser.flushInput()
import OMLibrary as OM import time import random import sys def randhex(): return str(random.choice("0123456789ABCDEF")) + str( random.choice("0123456789ABCDEF")) print("COMPORT Selection: ", str(sys.argv[1]), "\n") [ser, ports] = OM.initSerial(str(sys.argv[1])) # [ser, ports] = OM.initSerial('COM13') # ser = OM.initSerial('usbserial') wt = 0.07 addval = '01' #Set Position Example address = addval fcode = '10' uregaddr = '00' legaddr = '58' unumreg = '00' lnumreg = '10' numbytes = '20' opernum = '00000000' opertype = '00000022' #Operation type see page 277 in AZ series book posreg = '00FFFF34' velreg = '00000FFE' accelreg = '000ACA00' #max accel is '009ACA00' deccelreg = '000ACA00' #max deccel is '009ACA00'
#Using Library # OM.ReadAlarms('USBtoUART','01') #Mac # OM.ReadAlarms('usbserial','01') #Mac COMPort='COM13' OM.ReadAlarms(COMPort,'01') #Win #Original Read Alarms address='01' fcode='03' uregaddr='00' legaddr='80' unreg='00' lnreg='02' # [ser, ports] = OM.initSerial('USBtoUART') # ser = OM.initSerial('usbserial') [ser, ports] = OM.initSerial(COMPort) #Win i=0 while True: start_time = time.time() [result, ser] = OM.ReadReg(ser, address, fcode, uregaddr, legaddr, unreg, lnreg, 20, 0.007) errorlist = pd.read_csv('OMErrorLookUp.txt') result = result.hex() e = errorlist[errorlist['Code'].str.contains(str(result[12:14]))] print(e) print("--- Program took %s seconds ---" % (time.time() - start_time)) i=i+1 if i >=2: break ser.close() # close port