Esempio n. 1
0
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
ser = OM.initSerial('USBtoUART')
wt = 0.007
addval = '03'
#Set Operation Mode
print('Set position')
address = addval
fcode = '10'
uregaddr = '05'
legaddr = '00'
unumreg = '00'
lnumreg = '02'
numbytes = '04'
unreg = '0000'
lnreg = '0001'  # 0 Incremental and 1 for Absolute
OM.WriteMultiReg(ser, address, fcode, uregaddr, legaddr, unumreg, lnumreg,
                 numbytes, unreg, lnreg, wt)

time.sleep(wt)

#Set Position Register Value
print('Set position')
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 = 'FFFF'  #5000steps
OM.WriteMultiReg(ser, address, fcode, uregaddr, legaddr, unumreg, lnumreg,