I’m new to Igniton and Python, so sorry in advance.
I am trying to “efficiently” move data in “chunks” from an array in a Controllogix PLC to SQL. I had the below code working, but then later learned about the overhead involved.
if newValue.value:
i = 0
while i < 240:
tStamp = system.tag.read("[default]Plt4_MchSig/Unit0Flip/Unit0Flip_"+str(i)+"_/tStamp").value
Temp = system.tag.read("[default]Plt4_MchSig/Unit0Flip/Unit0Flip_"+str(i)+"_/Temperature").value
Vibrtn = system.tag.read("[default]Plt4_MchSig/Unit0Flip/Unit0Flip_"+str(i)+"_/Vibration").value
VoltsL1 = system.tag.read("[default]Plt4_MchSig/Unit0Flip/Unit0Flip_"+str(i)+"_/L1Voltage").value
VoltsL2 = system.tag.read("[default]Plt4_MchSig/Unit0Flip/Unit0Flip_"+str(i)+"_/L2Voltage").value
VoltsL3 = system.tag.read("[default]Plt4_MchSig/Unit0Flip/Unit0Flip_"+str(i)+"_/L3Voltage").value
AmpsL1 = system.tag.read("[default]Plt4_MchSig/Unit0Flip/Unit0Flip_"+str(i)+"_/L1Amps").value
AmpsL2 = system.tag.read("[default]Plt4_MchSig/Unit0Flip/Unit0Flip_"+str(i)+"_/L2Amps").value
AmpsL3 = system.tag.read("[default]Plt4_MchSig/Unit0Flip/Unit0Flip_"+str(i)+"_/L3Amps").value
system.db.runPrepUpdate("INSERT INTO Unit0 (PLCtStamp, temp, vib, VoltsL1, VoltsL2, VoltsL3, AmpsL1, AmpsL2, AmpsL3) VALUES (?,?,?,?,?,?,?,?,?)", [tStamp, Temp, Vibrtn, VoltsL1, VoltsL2, VoltsL3, AmpsL1, AmpsL2, AmpsL3])
i += 1
I found this in a separate posting. It looks like what I would need to do, but I am struggling to convert it over.
def writeRollData(dsReducedData,recordNumber):
import system
pyData = system.dataset.toPyDataSet(dsReducedData)
block_id = system.tag.getTagValue("[PMIServer]GaugeBandTester/block_id")
valueString = “”
args = []
for row in pyData:
xVal = row[“distance”]
yVal = row[“height”]
valueString += “(?,?,?),”
args.append(block_id)
args.append(xVal)
args.append(yVal)
if valueString != “”:
valueString[:-1]
system.db.runPrepUpdate(“INSERT INTO GuageBand_RollData (block_id, xVal, yVal) VALUES %s” % valueString, args, “PMIServer”)
return
Any help in either converting things over, or suggestions on a better method would be greatly appreciated.
Thanks in advance.