Running through this, I’m not successful acquiring data. (Trigger is good but no data) My hope it’s something simple.
Running in debug and i don’t see any data being placed within the destination(s) of the function block RecipeQueryGetData.
bool resultchar num[4] = “1”short clear[200], count = 0, kalike = 0, rqty = 0, bqty = 0char ctop[40] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}char cbottom[40] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}char b1[40] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}char b2[40] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}int recordIDs = 0int total_row=0int row_number=0bool result_querybool result_id
FILL(clear[0], 0, 200) // Initialize clear arraySetData(clear[0], “Local HMI”, LW, 2000, 200) // Clear current results
GetData(count, “Local HMI”, RECIPE, “Code_Que1.Count”) //Gets record count from recipe
short curr
for curr = 1 to count
bool trig
// Get PLC trigger, assume a bit trigger
GetData(trig, "Local HMI", LB, 50, 1)
// Waiting for trigger to be active
while not trig
DELAY(500)
GetData(trig, "Local HMI", LB, 50, 1)
wend
//Trigger active, sets statement to char
char sql[100] = "SELECT * FROM Code_Que1 WHERE No = "
if curr < 10 then
DEC2ASCII(curr, num[0], 1)
else if curr < 100 then
DEC2ASCII(curr, num[0], 2)
else if curr < 1000 then
DEC2ASCII(curr, num[0], 3)
else
DEC2ASCII(curr, num[0], 4)
end if
//Concats record number field into statememt for query
StringCat(num[0], sql[0])
short n_records
result = RecipeQuery(sql[0], n_records)
DELAY(1000)
if n_records > 0 then
short recordID = 0, i = 0
//Get record ID to acquire data
RecipeQueryGetRecordID(recordID, i)
RecipeQueryGetData(ctop[0], "Code_Que1.CodeTop",recordID)
RecipeQueryGetData(cbottom[0], "Code_Que1.CodeBottom", recordID)
RecipeQueryGetData(b1[0], "Code_Que1.Bitting1", recordID)
RecipeQueryGetData(b2[0], "Code_Que1.Bitting2", recordID)
RecipeQueryGetData(kalike, "Code_Que1.KeyAlike", recordID)
RecipeQueryGetData(rqty, "Code_Que1.RingQty", recordID)
RecipeQueryGetData(bqty, "Code_Que1.BinQty", recordID)
SetData(ctop[0], "Local HMI", LW, 2000, 40)
SetData(cbottom[0], "Local HMI", LW, 2020, 40)
SetData(b1[0], "Local HMI", LW, 2040, 40)
SetData(b2[0], "Local HMI", LW, 2060, 40)
SetData(kalike, "Local HMI", LW, 2080, 1)
SetData(rqty, "Local HMI", LW, 2081, 1)
SetData(bqty, "Local HMI", LW, 2082, 1)
SetData(ctop[0], "Rockwell EtherNet/IP (ControlLogix)", "KeyData[0].LockCode.DATA[0]", 40)
SetData(cbottom[0], "Rockwell EtherNet/IP (ControlLogix)", "KeyData[0].LockCode2.DATA[0]", 40)
SetData(b1[0], "Rockwell EtherNet/IP (ControlLogix)", "KeyData[0].KeyBitting.DATA[0]", 40)
SetData(b2[0], "Rockwell EtherNet/IP (ControlLogix)", "KeyData[0].KeyBitting2.DATA[0]", 40)
SetData(kalike, "Rockwell EtherNet/IP (ControlLogix)", "KeyData[0].KeyAlikeQty[0]", 1)
SetData(rqty, "Rockwell EtherNet/IP (ControlLogix)", "KeyData[0].RingQty[0]", 1)
SetData(bqty, "Rockwell EtherNet/IP (ControlLogix)", "KeyData[0].BinQty[0]", 1)
DELAY(1500)
end if
I’m also assuming i can Setdata back to the PLC during this macro, I kept the “LW” setdata(s) because i like to visually see (during testing) the data being queried on the HMI object(s).