Esempio n. 1
0
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'
Esempio n. 2
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
import OMLibrary as OM
import time
start_time = time.time()

#Read Feedback Commands
postype = input("What value to monitor?")
address = '01'
fcode = '03'
uregaddr = '00'
legaddr = postype  #CC for Feedback Position, C6 for Command Position, C8 for speed, CE for feedback speed
unreg = '00'
lnreg = '02'
[ser, ports] = OM.initSerial('USBtoUART')
[result, ser] = OM.ReadReg(ser, address, fcode, uregaddr, legaddr, unreg,
                           lnreg, 20, 0.007)
out = result.hex()
outnew = out[6:14]
print("Monitor: " + str(postype) + ":" + str(int(outnew, 16)))
ser.close()
print("--- Program took %s seconds ---" % (time.time() - start_time))
Esempio n. 4
0
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
start_time = time.time()

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'
import OMLibrary as OM
import time
import serial
start_time = time.time()

#Read Alarms
address = '03'
fcode = '01'
uregaddr = '00'
legaddr = '80'
unreg = '00'
lnreg = '02'
# Open Serial Port with non-blocking handshake
devtitle = OM.serial_ports('USBtoUART')
# [ser, ports] = OM.initSerial('USBtoUART')

# print("--- Program took serial ports %s seconds ---" % (time.time() - start_time))
print(devtitle)
ser = serial.Serial(str(devtitle[0]),
                    19200,
                    parity=serial.PARITY_EVEN,
                    rtscts=1)  # timeout for 30ms
ser.open()
# Write to register to request for information about a register
# '030300800002C401' original checksum for alarm codes
hexval = address + fcode + uregaddr + legaddr + unreg + lnreg  ##Check Pg 144 in AR series book
hexval = OM.crc16(hexval)
ser.write(bytearray.fromhex(hexval))
out = ser.read(9)
print('Output: ' + str(out))
ser.close()  # close port
import OMLibrary as OM
import time
import pandas as pd
#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: