LCRControllerCode/KLCCommandLibTest.py

230 lines
8.0 KiB
Python
Raw Permalink Normal View History

# NOTE: This script was initially intended to be as an example for the x32 Windows operating system.
# TODO: Remove this script in future updates of the repository.
2024-10-30 11:50:26 +00:00
import time
try:
from KLCCommandLib64 import *
except OSError as ex:
print("Warning:",ex)
def main():
print("*** KLC device python example ***")
try:
devs = klcListDevices()
print(devs)
if(len(devs)<=0):
print('There is no devices connected')
exit()
klc = devs[0]
sn = klc[0]
print("connect ", sn)
hdl = klcOpen(sn, 115200, 3)
if(hdl<0):
print("open ", sn, " failed")
exit()
if(klcIsOpen(sn) == 0):
print("klcIsOpen failed")
klcClose(hdl)
exit()
# ------------ Example Disable/Enable global output -------------- #
klcSetEnable(hdl,2)
print("set output to enable")
if(klcSetEnable(hdl, 1)<0):
print("klcSetEnable failed")
en=[0]
if(klcGetEnable(hdl, en)<0):
print("klcGetEnable failed")
else:
print("klcGetEnable ", en)
# ---------------------------------------------------------------- #
# ------------ Example Present1 mode ----------------------------- #
print("Enable V1")
klcSetChannelEnable(hdl, 1)
print("set vol1 to 5.0")
if(klcSetVoltage1(hdl, 5)<0):
print("klcSetVoltage1 failed")
vol1=[0]
if(klcGetVoltage1(hdl, vol1)<0):
print("klcGetVoltage1 failed")
else:
print("klcGetVoltage1 ", vol1)
print("set freq 1 to 2005")
if(klcSetFrequency1(hdl, 2005)<0):
print("klcSetFrequency1 failed")
freq1=[0]
if(klcGetFrequency1(hdl, freq1)<0):
print("klcGetFrequency1 failed")
else:
print("klcGetFrequency1 ", freq1)
# ---------------------------------------------------------------- #
# ------------ Example Present2 mode ----------------------------- #
print("Enable V2")
klcSetChannelEnable(hdl, 2)
print("set vol2 to 10.0")
if(klcSetVoltage2(hdl, 10)<0):
print("klcSetVoltage2 failed")
vol2=[0]
if(klcGetVoltage2(hdl, vol2)<0):
print("klcGetVoltage2 failed")
else:
print("klcGetVoltage2 ", vol2)
print("set freq 2 to 3005")
if(klcSetFrequency2(hdl, 3005)<0):
print("klcSetFrequency2 failed")
freq2=[0]
if(klcGetFrequency2(hdl, freq2)<0):
print("klcGetFrequency2 failed")
else:
print("klcGetFrequency2 ", freq2)
# ---------------------------------------------------------------- #
# ------------ Example Switching mode ---------------------------- #
print("set to sw mode")
if(klcSetChannelEnable(hdl, 3)<0):
print("klcSetChannelEnable failed")
print("set sw frequency to 99")
if(klcSetSWFrequency(hdl, 99)<0):
print("klcSetSWFrequency failed")
swf=[0]
if(klcGetSWFrequency(hdl, swf)<0):
print("klcGetSWFrequency failed")
else:
print("klcGetSWFrequency ", swf)
# ---------------------------------------------------------------- #
time.sleep(5)
# ------------ Example Mode in mode ------------------------------ #
print("set input mode to enable")
if(klcSetInputMode(hdl, 1)<0):
print("klcSetInputMode failed")
im=[0]
if(klcGetInputMode(hdl, im)<0):
print("klcGetInputMode failed")
else:
print("klcGetInputMode ", im)
print("set mode in frequency")
if(klcSetFrequency1(hdl, 5000)<0):
print("klcSetFrequency1 failed")
# ---------------------------------------------------------------- #
# ------------ Example Trigger mode ------------------------------ #
print("set trigger mode to Pin 1")
if(klcSetTrigIOConfigure(hdl, 2)<0):
print("klcSetTrigIOConfigure failed")
trigger=[0]
if(klcGetTrigIOConfigure(hdl, trigger)<0):
print("klcGetTrigIOConfigure failed")
else:
print("klcGetTrigIOConfigure ", trigger)
# ---------------------------------------------------------------- #
# --------- Example Wheel lock, pannel brightness/timeout -------- #
print("set wheel lock to locked")
if(klcSetKcubeMMILock(hdl, 1)<0):
print("klcSetKcubeMMILock failed")
lock=[0]
if(klcGetKcubeMMILock(hdl, im)<0):
print("klcGetKcubeMMILock failed")
else:
print("klcGetKcubeMMILock ", im)
print("set pannel brightness to 90, timeout to never")
if(klcSetKcubeMMIParams(hdl, 90, 0xFFFF)<0):
print("klcSetKcubeMMIParams failed")
dbrightness=[0]
dtimeout=[0]
if(klcGetKcubeMMIParams(hdl, dbrightness, dtimeout)<0):
print("klcGetKcubeMMIParams failed")
else:
print("klcGetKcubeMMIParams dbrightness: ", dbrightness ," dtimeout:", dtimeout)
# ---------------------------------------------------------------- #
# ------------ Example get output status ------------------------- #
active=[0]
v=[0]
f=[0]
err=[0]
ch=[0]
if(klcGetOutPutStatus(hdl, active, v, f, err)<0):
print("klcGetOutPutStatus failed")
else:
print("klcGetOutPutStatus active: ", active ," voltage: ", v ," frequency: " , f, " errFlag ",err)
if(klcGetStatus(hdl, ch, vol1, freq1, vol2, freq2, swf, dbrightness, dtimeout, im, trigger, lock, err)<0):
print("klcGetStatus failed")
else:
print("klcGetStatus channel: ", ch ," vol1: ", vol1 ," freq1: " , freq1," vol2: ", vol2 ," freq2: " , freq2," swf: ", swf ," dbrightness: " , dbrightness," dtimeout: ", dtimeout ," im: " , im," trigger: ", trigger ," lock: " , lock, " errFlag ",err)
# ---------------------------------------------------------------- #
# ------------ Example run LUT ---------------------------------- #
print("Test LUT Array")
#disbale trigger mode
klcSetTrigIOConfigure(hdl, 1)
#disable mode in mode
klcSetInputMode(hdl, 0)
klcSetChannelEnable(hdl, 1)
#init array 2,4,6,8,10
vols = [2,4,6,8,10]
volarr = (c_float * len(vols))(*vols)
print("set LUT array")
if(klcSetOutputLUT(hdl, volarr, 5)<0):
print("klcSetOutputLUT failed")
#update second 4 to 5
if(klcUpdateOutputLUT(hdl, 1, 5)<0):
print("klcUpdateOutputLUT failed")
#remove last one the arry will be 2,5,6,8
if(klcRemoveLastOutputLUT(hdl, 1)<0):
print("klcRemoveLastOutputLUT failed")
print("set LUT parameters")
if(klcSetOutputLUTParams(hdl, 2, 3, 1000, 0)<0):
print("klcSetOutputLUTParams failed")
lut_mode=[0]
lut_cyclenumber=[0]
lut_delay=[0]
lut_precycle_rest=[0]
if(klcGetOutputLUTParams(hdl, lut_mode, lut_cyclenumber, lut_delay, lut_precycle_rest)<0):
print("klcGetOutputLUTParams failed")
else:
print("klcGetOutputLUTParams mode: ", lut_mode ," lut_cyclenumber:", lut_cyclenumber," lut_delay:", lut_delay," lut_precycle_rest:", lut_precycle_rest)
print("start LUT")
if(klcStartLUTOutput(hdl)<0):
print("klcStartLUTOutput failed")
t=0
while(t<20):
klcGetOutPutStatus(hdl, active, v, f, err)
print("Get LUT output: ", active ," voltage: ", v ," frequency: " , f, " errFlag ", err)
time.sleep(1)
t+=1
print("stop LUT")
if(klcStopLUTOutput(hdl)<0):
print("klcStopLUTOutput failed")
# ---------------------------------------------------------------- #
klcClose(hdl)
except Exception as ex:
print("Warning:", ex)
print("*** End ***")
input()
main()