a
This commit is contained in:
133
SR-X300W/Modelos/FMTSET.LUA
Normal file
133
SR-X300W/Modelos/FMTSET.LUA
Normal file
@@ -0,0 +1,133 @@
|
||||
function readformatEvent()
|
||||
local b = readCount()
|
||||
local a = 0
|
||||
local results = {}
|
||||
local tableRes = {}
|
||||
local code
|
||||
local preset = ''
|
||||
local presetLowQty = ''
|
||||
local i = 0
|
||||
local j = 0
|
||||
local data = {}
|
||||
local middle = 0
|
||||
local k = 0
|
||||
local dato
|
||||
local centerCoords
|
||||
local posX, posY
|
||||
|
||||
-- Contar códigos válidos
|
||||
for i = 1, b do
|
||||
code = readResult(i):readData()
|
||||
if (code ~= 'ERROR') then
|
||||
a = a + 1
|
||||
presetLowQty = code
|
||||
end
|
||||
end
|
||||
|
||||
-- CASO 1: Un solo código
|
||||
if (a == 1) then
|
||||
dato = readResult():readData()
|
||||
centerCoords = readResult():centerCoordinate()
|
||||
table.insert(tableRes, dato .. ':001:' .. centerCoords)
|
||||
return table.concat(tableRes, ',')
|
||||
|
||||
-- CASO 2: Dos códigos
|
||||
elseif (a == 2) then
|
||||
for i = 1, a do
|
||||
data[i] = readResult(i):readData()
|
||||
end
|
||||
|
||||
if (data[1] == data[2]) then
|
||||
for i = 1, 2 do
|
||||
centerCoords = readResult(i):centerCoordinate()
|
||||
local pos = i
|
||||
if pos < 10 then
|
||||
pos = '00' .. pos
|
||||
elseif pos < 100 then
|
||||
pos = '0' .. pos
|
||||
else
|
||||
pos = tostring(pos)
|
||||
end
|
||||
table.insert(tableRes, data[i] .. ':' .. pos .. ':' .. centerCoords)
|
||||
end
|
||||
return table.concat(tableRes, ',')
|
||||
else
|
||||
return 'Mezclado'
|
||||
end
|
||||
|
||||
-- CASO 3: Caja vacía
|
||||
elseif (a == 0) then
|
||||
return 'Caja vacia'
|
||||
|
||||
-- CASO 4: Más de 2 códigos
|
||||
else
|
||||
middle = math.floor(a / 2)
|
||||
|
||||
-- Leer todos los códigos
|
||||
for i = 1, b do
|
||||
code = readResult(i):readData()
|
||||
if (code ~= 'ERROR') then
|
||||
table.insert(data, code)
|
||||
end
|
||||
end
|
||||
|
||||
-- Determinar el código preset (más repetido)
|
||||
preset = ''
|
||||
local maxCount = 0
|
||||
|
||||
for i = 1, #data do
|
||||
if (data[i] ~= 'ERROR') then
|
||||
k = 0
|
||||
for j = 1, #data do
|
||||
if (data[j] == data[i]) then
|
||||
k = k + 1
|
||||
end
|
||||
end
|
||||
|
||||
if (k > maxCount) then
|
||||
maxCount = k
|
||||
preset = data[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Si no hay preset, tomar el primero válido
|
||||
if (preset == '' or preset == nil) then
|
||||
for i = 1, #data do
|
||||
if (data[i] ~= 'ERROR' and data[i] ~= nil) then
|
||||
preset = data[i]
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Generar resultados
|
||||
for i = 1, b do
|
||||
code = readResult(i):readData()
|
||||
|
||||
if (code ~= 'ERROR' and code ~= nil) then
|
||||
centerCoords = readResult(i):centerCoordinate()
|
||||
|
||||
-- Formatear posición con 3 dígitos
|
||||
local pos = i
|
||||
if pos < 10 then
|
||||
pos = '00' .. pos
|
||||
elseif pos < 100 then
|
||||
pos = '0' .. pos
|
||||
else
|
||||
pos = tostring(pos)
|
||||
end
|
||||
|
||||
table.insert(results, code .. ':' .. pos .. ':' .. centerCoords)
|
||||
else
|
||||
table.insert(results, 'ERROR')
|
||||
end
|
||||
end
|
||||
|
||||
return table.concat(results, ',')
|
||||
end
|
||||
end
|
||||
|
||||
function nameformatEvent()
|
||||
return 'Captura_Scanner'
|
||||
end
|
||||
Reference in New Issue
Block a user