PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 25 → Windev + CLP Panasonic + Hfsql - AUTOMACAO INDUSTRIAL
Windev + CLP Panasonic + Hfsql - AUTOMACAO INDUSTRIAL
Started by Boller, Jul., 02 2022 3:38 PM - No answer
Registered member
3,413 messages
Popularité : +175 (223 votes)
Posted on July, 02 2022 - 3:38 PM
//EXEMPLO Windev + CLP Panasonic + Hfsql - AUTOMACAO INDUSTRIAL













// Automatic procedure:
// The procedure is automatically run, after the window initialization code, with a delay set to 1 second
// It will be run in a thread (without having to call ThreadExecute), without using HFSQL
// It will be repeated in loop, with a timeout set to 30 hundredths of a second between each call
//

PROCEDURE lerCLP()
arrResponse is array of 5 int // MaquinaBloqueada 2049..
arrBitRasp is array of 5 int // Bitrasp 2161
arrParaLeitura is array of 5 int // ParaLeitura
arrMaquinaBloq is array of 5 int // 2193

arrReset is array of 5 int // = 2097 # 2097 - 2104
arrBypass is array of 5 int // = 2113 # 2113 - 2120
arrReset_Ret is array of 5 int // = 2145 # 2145 - 2152
arrAtiva_Ret is array of 5 int // = 2081 # 2081 - 2088

arrmaquinaSetup is array of 5 int // = 2368
arrandon is array of 5 int // = 2353

arrResponseQtde is array of 5 2-byte int
arrResponseQtde2 is array of 5 2-byte int
arrResponseQtde3 is array of 5 2-byte int
arrResponseQtde4 is array of 5 2-byte int
arrResponseQtde5 is array of 5 2-byte int
arrResponseQtde6 is array of 5 2-byte int
arrResponseQtde7 is array of 5 2-byte int
arrResponseQtde8 is array of 5 2-byte int


arrTempoParada01 is array of 5 4-byte int //
arrTempoParada02 is array of 5 4-byte int //
arrTempoParada03 is array of 5 4-byte int //
arrTempoParada04 is array of 5 4-byte int //
arrTempoParada05 is array of 5 4-byte int //
arrTempoParada06 is array of 5 4-byte int //
arrTempoParada07 is array of 5 4-byte int //
arrTempoParada08 is array of 5 4-byte int //

arrFiltroSensor01 is array of 5 4-byte int //
arrFiltroSensor02 is array of 5 4-byte int //
arrFiltroSensor03 is array of 5 4-byte int //
arrFiltroSensor04 is array of 5 4-byte int //
arrFiltroSensor05 is array of 5 4-byte int //
arrFiltroSensor06 is array of 5 4-byte int //
arrFiltroSensor07 is array of 5 4-byte int //
arrFiltroSensor08 is array of 5 4-byte int //



xErro is string
xErro = "N"

Session is modbusSession
Session = ModbusConnectTCP("120.0.0.120",560)
IF ExceptionInfo(errCode) THEN
Info(errCode)
xErro = "S"
END
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
ELSE

// Read a sequence of 5 bits in read-write mode starting at address 0x42
arrResponse = ModbusReadBit(Session, 2049, 10, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrBitRasp = ModbusReadBit(Session, 2161, 10, False) // Bitrasp 2161
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrParaLeitura = ModbusReadBit(Session, 2065, 10, False) // ParaLeitura
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrMaquinaBloq = ModbusReadBit(Session, 2193, 10, False) // 2193
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END

arrReset = ModbusReadBit(Session, 2097, 10, False) // = 2097 # 2097 - 2104
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrBypass = ModbusReadBit(Session, 2113, 10, False) // = 2113 # 2113 - 2120
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
// arrReset_Ret = ModbusReadBit(Session, 2145, 10, False) // = 2145 # 2145 - 2152
// arrAtiva_Ret = ModbusReadBit(Session, 2081, 10, False) // = 2081 # 2081 - 2088

arrmaquinaSetup = ModbusReadBit(Session, 2368, 10, False) // = 2368
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
// arrandon = ModbusReadBit(Session, 2353, 10, False) // = 2353


arrResponseQtde = ModbusReadRegister(Session,21180, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrResponseQtde2 = ModbusReadRegister(Session,21280, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrResponseQtde3 = ModbusReadRegister(Session,21380, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrResponseQtde4 = ModbusReadRegister(Session,21480, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrResponseQtde5 = ModbusReadRegister(Session, 21580, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrResponseQtde6 = ModbusReadRegister(Session, 21680, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrResponseQtde7 = ModbusReadRegister(Session, 21780, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrResponseQtde8 = ModbusReadRegister(Session, 21880, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
// Display the error, if any


arrTempoParada01 = ModbusReadRegister(Session, 21010, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrTempoParada02 = ModbusReadRegister(Session, 21020, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrTempoParada03 = ModbusReadRegister(Session, 21030, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrTempoParada04 = ModbusReadRegister(Session, 21040, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrTempoParada05 = ModbusReadRegister(Session, 21050, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrTempoParada06 = ModbusReadRegister(Session, 21060, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrTempoParada07 = ModbusReadRegister(Session, 21070, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
arrTempoParada08 = ModbusReadRegister(Session, 21080, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END

arrFiltroSensor01 = ModbusReadRegister(Session, 22001, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
IF arrFiltroSensor01[1] = 0 THEN
IF NOT ModbusWriteRegister(Session, 22001, [5]) THEN
Trace(ErrorInfo())
END
END
arrFiltroSensor02 = ModbusReadRegister(Session, 22002, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
IF arrFiltroSensor02[1] = 0 THEN
IF NOT ModbusWriteRegister(Session, 22002, [5]) THEN
Trace(ErrorInfo())
END

END

arrFiltroSensor03 = ModbusReadRegister(Session, 22003, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
IF arrFiltroSensor03[1] = 0 THEN
IF NOT ModbusWriteRegister(Session, 22003, [5]) THEN
Trace(ErrorInfo())
END

END
arrFiltroSensor04 = ModbusReadRegister(Session, 22004, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
IF arrFiltroSensor04[1] = 0 THEN
IF NOT ModbusWriteRegister(Session, 22004, [5]) THEN
Trace(ErrorInfo())
END

END
arrFiltroSensor05 = ModbusReadRegister(Session, 22005, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
IF arrFiltroSensor05[1] = 0 THEN
IF NOT ModbusWriteRegister(Session, 22005, [5]) THEN
Trace(ErrorInfo())
END

END
arrFiltroSensor06 = ModbusReadRegister(Session, 22006, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
IF arrFiltroSensor06[1] = 0 THEN
IF NOT ModbusWriteRegister(Session, 22006, [5]) THEN
Trace(ErrorInfo())
END

END
arrFiltroSensor07 = ModbusReadRegister(Session, 22007, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
IF arrFiltroSensor07[1] = 0 THEN
IF NOT ModbusWriteRegister(Session, 22007, [5]) THEN
Trace(ErrorInfo())
END

END
arrFiltroSensor08 = ModbusReadRegister(Session, 22008, 2, False)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
xErro = "S"
END
IF arrFiltroSensor08[1] = 0 THEN
IF NOT ModbusWriteRegister(Session, 22008, [5]) THEN
Trace(ErrorInfo())
END

END


END

Var1 is string = arrResponse[1]
Var2 is string = arrResponse[2]
Var3 is string = arrResponse[3]
Var4 is string = arrResponse[4]
Var5 is string = arrResponse[5]
Var6 is string = arrResponse[6]
Var7 is string = arrResponse[7]
Var8 is string = arrResponse[8]

vbit1 is string = arrBitRasp[1]
vbit2 is string = arrBitRasp[2]
vbit3 is string = arrBitRasp[3]
vbit4 is string = arrBitRasp[4]
vbit5 is string = arrBitRasp[5]
vbit6 is string = arrBitRasp[6]
vbit7 is string = arrBitRasp[7]
vbit8 is string = arrBitRasp[8]

vPar1 is string = arrParaLeitura[1]
vPar2 is string = arrParaLeitura[2]
vPar3 is string = arrParaLeitura[3]
vPar4 is string = arrParaLeitura[4]
vPar5 is string = arrParaLeitura[5]
vPar6 is string = arrParaLeitura[6]
vPar7 is string = arrParaLeitura[7]
vPar8 is string = arrParaLeitura[8]

vMqb1 is string = arrMaquinaBloq[1]
vMqb2 is string = arrMaquinaBloq[2]
vMqb3 is string = arrMaquinaBloq[3]
vMqb4 is string = arrMaquinaBloq[4]
vMqb5 is string = arrMaquinaBloq[5]
vMqb6 is string = arrMaquinaBloq[6]
vMqb7 is string = arrMaquinaBloq[7]
vMqb8 is string = arrMaquinaBloq[8]

vRes1 is string = arrReset[1]
vRes2 is string = arrReset[2]
vRes3 is string = arrReset[3]
vRes4 is string = arrReset[4]
vRes5 is string = arrReset[5]
vRes6 is string = arrReset[6]
vRes7 is string = arrReset[7]
vRes8 is string = arrReset[8]

vSet1 is string = arrmaquinaSetup[1]
vSet2 is string = arrmaquinaSetup[2]
vSet3 is string = arrmaquinaSetup[3]
vSet4 is string = arrmaquinaSetup[4]
vSet5 is string = arrmaquinaSetup[5]
vSet6 is string = arrmaquinaSetup[6]
vSet7 is string = arrmaquinaSetup[7]
vSet8 is string = arrmaquinaSetup[8]

vbyp1 is string = arrBypass[1]
vbyp2 is string = arrBypass[2]
vbyp3 is string = arrBypass[3]
vbyp4 is string = arrBypass[4]
vbyp5 is string = arrBypass[5]
vbyp6 is string = arrBypass[6]
vbyp7 is string = arrBypass[7]
vbyp8 is string = arrBypass[8]

Vqtde1 is real = arrResponseQtde[1]
Vqtde2 is real = arrResponseQtde2[1]
Vqtde3 is real = arrResponseQtde3[1]
Vqtde4 is real = arrResponseQtde4[1]
Vqtde5 is real = arrResponseQtde5[1]
Vqtde6 is real = arrResponseQtde6[1]
Vqtde7 is real = arrResponseQtde7[1]
Vqtde8 is real = arrResponseQtde8[1]

vtemp1 is real = arrTempoParada01[1]
vtemp2 is real = arrTempoParada02[1]
vtemp3 is real = arrTempoParada03[1]
vtemp4 is real = arrTempoParada04[1]
vtemp5 is real = arrTempoParada05[1]
vtemp6 is real = arrTempoParada06[1]
vtemp7 is real = arrTempoParada07[1]
vtemp8 is real = arrTempoParada08[1]


vfilt1 is real = arrFiltroSensor01[1]
vfilt2 is real = arrFiltroSensor02[1]
vfilt3 is real = arrFiltroSensor03[1]
vfilt4 is real = arrFiltroSensor04[1]
vfilt5 is real = arrFiltroSensor05[1]
vfilt6 is real = arrFiltroSensor06[1]
vfilt7 is real = arrFiltroSensor07[1]
vfilt8 is real = arrFiltroSensor08[1]


// Disconnect server
ModbusDisconnect(Session)

leitura.CLP01_parada[1] = Var1
leitura.CLP01_parada[2] = Var2
leitura.CLP01_parada[3] = Var3
leitura.CLP01_parada[4] = Var4
leitura.CLP01_parada[5] = Var5
leitura.CLP01_parada[6] = Var6
leitura.CLP01_parada[7] = Var7
leitura.CLP01_parada[8] = Var1

leitura.paraleitura[1] = vPar1
leitura.paraleitura[2] = vPar2
leitura.paraleitura[3] = vPar3
leitura.paraleitura[4] = vPar4
leitura.paraleitura[5] = vPar5
leitura.paraleitura[6] = vPar6
leitura.paraleitura[7] = vPar7
leitura.paraleitura[8] = vPar8

leitura.bitrasp[1] = vbit1
leitura.bitrasp[2] = vbit2
leitura.bitrasp[3] = vbit3
leitura.bitrasp[4] = vbit4
leitura.bitrasp[5] = vbit5
leitura.bitrasp[6] = vbit6
leitura.bitrasp[7] = vbit7
leitura.bitrasp[8] = vbit8

leitura.bypass[1] = vbyp1
leitura.bypass[2] = vbyp2
leitura.bypass[3] = vbyp3
leitura.bypass[4] = vbyp4
leitura.bypass[5] = vbyp5
leitura.bypass[6] = vbyp6
leitura.bypass[7] = vbyp7
leitura.bypass[8] = vbyp8


leitura.maquinabloq[1] = vMqb1
leitura.maquinabloq[2] = vMqb2
leitura.maquinabloq[3] = vMqb3
leitura.maquinabloq[4] = vMqb4
leitura.maquinabloq[5] = vMqb5
leitura.maquinabloq[6] = vMqb6
leitura.maquinabloq[7] = vMqb7
leitura.maquinabloq[8] = vMqb8

leitura.CLP01_reset[1] = vRes1
leitura.CLP01_reset[2] = vRes2
leitura.CLP01_reset[3] = vRes3
leitura.CLP01_reset[4] = vRes4
leitura.CLP01_reset[5] = vRes5
leitura.CLP01_reset[6] = vRes6
leitura.CLP01_reset[7] = vRes7
leitura.CLP01_reset[8] = vRes8

leitura.maquinasetup[1] = vSet1
leitura.maquinasetup[2] = vSet2
leitura.maquinasetup[3] = vSet3
leitura.maquinasetup[4] = vSet4
leitura.maquinasetup[5] = vSet5
leitura.maquinasetup[6] = vSet6
leitura.maquinasetup[7] = vSet7
leitura.maquinasetup[8] = vSet8

// MAQUINA 1
leitura.CLP01_qtde01 = Vqtde1
IF Vqtde1 = 0 THEN
gQtdePro01 = 0
END

IF gQtdeAnt01 = 0 OR gQtdeAnt01 > Vqtde1 THEN
gQtdeAnt01 = Vqtde1
END

IF gQtdeCav01 = 0 THEN
gQtdeCav01 = EDT_cav01.Value
END

IF gQtdePro01 = 0 THEN
gQtdePro01 = Vqtde1
END

gQtdeCav01 = EDT_cav01.Value
gQtdeCic01 = Vqtde1

vQtdeProd01 is int = 0
vQtdeProd01 = (Vqtde1 - gQtdeAnt01)

IF (Vqtde1 = 0) THEN
vQtdeProd01 = 0
END

gQtdePro01 += (vQtdeProd01 * gQtdeCav01)

leitura.qtdeAnt01 = gQtdeAnt01
leitura.qtdecav01 = gQtdeCav01
leitura.qtdeproduz01 = gQtdePro01

gQtdeAnt01 = Vqtde1

// MAQUINA 2
leitura.CLP01_qtde02 = Vqtde2
IF Vqtde2 = 0 THEN
gQtdePro02 = 0
END

IF gQtdeAnt02 = 0 OR gQtdeAnt02 > Vqtde2 THEN
gQtdeAnt02 = Vqtde2
END

IF gQtdeCav02 = 0 THEN
gQtdeCav02 = EDT_cav01.Value
END

IF gQtdePro02 = 0 THEN
gQtdePro02 = Vqtde2
END

gQtdeCav02 = EDT_cav01.Value
gQtdeCic02 = Vqtde2

vQtdeProd02 is int = 0
vQtdeProd02 = (Vqtde2 - gQtdeAnt02)

gQtdePro02 += (vQtdeProd02 * gQtdeCav02)
leitura.qtdeAnt02 = gQtdeAnt02
leitura.qtdecav02 = gQtdeCav02
leitura.qtdeproduz02 = gQtdePro02

gQtdeAnt02 = Vqtde2

// MAQUINA 3
leitura.CLP01_qtde03 = Vqtde3
IF Vqtde3 = 0 THEN
gQtdePro03 = 0
END

IF gQtdeAnt03 = 0 OR gQtdeAnt03 > Vqtde3 THEN
gQtdeAnt03 = Vqtde3
END

IF gQtdeCav03 = 0 THEN
gQtdeCav03 = EDT_cav01.Value
END

IF gQtdePro03 = 0 THEN
gQtdePro03 = Vqtde3
END

gQtdeCav03 = EDT_cav01.Value
gQtdeCic03 = Vqtde3

vQtdeProd03 is int = 0
vQtdeProd03 = (Vqtde3 - gQtdeAnt03)
gQtdePro03 += (vQtdeProd03 * gQtdeCav03)
leitura.qtdeAnt03 = gQtdeAnt03
leitura.qtdecav03 = gQtdeCav03
leitura.qtdeproduz03 = gQtdePro03
gQtdeAnt03 = Vqtde3

//-----------------------------------------------------------------------------------

leitura.CLP01_qtde04 = Vqtde4
IF Vqtde4 = 0 THEN
gQtdePro04 = 0
END
IF gQtdeAnt04 = 0 OR gQtdeAnt04 > Vqtde4 THEN
gQtdeAnt04 = Vqtde4
END
IF gQtdeCav04 = 0 THEN
gQtdeCav04 = EDT_cav01.Value
END
IF gQtdePro04 = 0 THEN
gQtdePro04 = Vqtde4
END

gQtdeCav04 = EDT_cav01.Value
gQtdeCic04 = Vqtde4

vQtdeProd04 is int = 0
vQtdeProd04 = (Vqtde4 - gQtdeAnt04)
gQtdePro04 += (vQtdeProd04 * gQtdeCav04)

leitura.qtdeAnt04 = gQtdeAnt04
leitura.qtdecav04 = gQtdeCav04
leitura.qtdeproduz04 = gQtdePro04

gQtdeAnt04 = Vqtde4

leitura.CLP01_qtde05 = Vqtde5
IF Vqtde5 = 0 THEN
gQtdePro05 = 0
END


IF gQtdeAnt05 = 0 OR gQtdeAnt05 > Vqtde5 THEN
gQtdeAnt05 = Vqtde5
END

IF gQtdeCav05 = 0 THEN
gQtdeCav05 = EDT_cav01.Value
END

IF gQtdePro05 = 0 THEN
gQtdePro05 = Vqtde5
END

gQtdeCav05 = EDT_cav01.Value
gQtdeCic05 = Vqtde5

vQtdeProd05 is int = 0
vQtdeProd05 = (Vqtde5 - gQtdeAnt05)
gQtdePro05 += (vQtdeProd05 * gQtdeCav05)

leitura.qtdeAnt05 = gQtdeAnt05
leitura.qtdecav05 = gQtdeCav05
leitura.qtdeproduz05 = gQtdePro05

gQtdeAnt05 = Vqtde5

leitura.CLP01_qtde06 = Vqtde6
IF Vqtde6 = 0 THEN
gQtdePro06 = 0
END
IF gQtdeAnt06 = 0 OR gQtdeAnt06 > Vqtde2 THEN
gQtdeAnt06 = Vqtde6
END

IF gQtdeCav06 = 0 THEN
gQtdeCav06 = EDT_cav01.Value
END

IF gQtdePro06 = 0 THEN
gQtdePro06 = Vqtde6
END

gQtdeCav06 = EDT_cav01.Value
gQtdeCic06 = Vqtde6

vQtdeProd06 is int = 0
vQtdeProd06 = (Vqtde6 - gQtdeAnt06)
gQtdePro06 += (vQtdeProd06 * gQtdeCav06)

IF (Vqtde6 = 0) THEN
vQtdeProd06 = 0
END

leitura.qtdeAnt06 = gQtdeAnt06
leitura.qtdecav06 = gQtdeCav06
leitura.qtdeproduz06 = gQtdePro06

gQtdeAnt06 = Vqtde6


leitura.CLP01_qtde07 = Vqtde7
IF Vqtde7 = 0 THEN
gQtdePro07 = 0
END

IF gQtdeAnt07 = 0 OR gQtdeAnt07 > Vqtde7 THEN
gQtdeAnt07 = Vqtde7
END

IF gQtdeCav07 = 0 THEN
gQtdeCav07 = EDT_cav01.Value
END

IF gQtdePro07 = 0 THEN
gQtdePro07 = Vqtde7
END

gQtdeCav07 = EDT_cav01.Value
gQtdeCic07 = Vqtde7

vQtdeProd07 is int = 0
vQtdeProd07 = (Vqtde7 - gQtdeAnt07)
gQtdePro07 += (vQtdeProd07 * gQtdeCav07)

leitura.qtdeAnt07 = gQtdeAnt07
leitura.qtdecav07 = gQtdeCav07
leitura.qtdeproduz07 = gQtdePro07
gQtdeAnt07 = Vqtde7


leitura.CLP01_qtde08 = Vqtde8
IF Vqtde8 = 0 THEN
gQtdePro08 = 0
END

IF gQtdeAnt08 = 0 OR gQtdeAnt08 > Vqtde8 THEN
gQtdeAnt08 = Vqtde8
END

IF gQtdeCav08 = 0 THEN
gQtdeCav08 = EDT_cav01.Value
END

IF gQtdePro08 = 0 THEN
gQtdePro08 = Vqtde8
END

gQtdeCav08 = EDT_cav01.Value
gQtdeCic08 = Vqtde1

vQtdeProd08 is int = 0
vQtdeProd08 = (Vqtde8 - gQtdeAnt08)
gQtdePro08 += (vQtdeProd08 * gQtdeCav08)
leitura.qtdeAnt08 = gQtdeAnt08
leitura.qtdecav08 = gQtdeCav08
leitura.qtdeproduz08 = gQtdePro08

gQtdeAnt08 = Vqtde8


leitura.FiltroSensor01 = vfilt1
leitura.FiltroSensor02 = vfilt2
leitura.FiltroSensor03 = vfilt3
leitura.FiltroSensor04 = vfilt4
leitura.FiltroSensor05 = vfilt5
leitura.FiltroSensor06 = vfilt6
leitura.FiltroSensor07 = vfilt7
leitura.FiltroSensor08 = vfilt8

leitura.TempoParada01 = vtemp1
leitura.TempoParada02 = vtemp2
leitura.TempoParada03 = vtemp3
leitura.TempoParada04 = vtemp4
leitura.TempoParada05 = vtemp5
leitura.TempoParada06 = vtemp6
leitura.TempoParada07 = vtemp7
leitura.TempoParada08 = vtemp8



leitura.ritmo01 = 0
leitura.ritmo02 = 0
leitura.ritmo03 = 0
leitura.ritmo04 = 0
leitura.ritmo05 = 0
leitura.ritmo06 = 0
leitura.ritmo07 = 0
leitura.ritmo08 = 0


DataAgora is DateTime = DateSys() + TimeSys()
DataMinuto is DateTime = DateSys() + TimeSys()
DataMinuto..Minute-=1

horaatual is Time = TimeSys()

leitura.CLP01_DataHora = DataAgora
leitura.CLP01_dthoraant = DataMinuto

xTurno is int = 3

IF HExecuteQuery(QRY_turno,hQueryDefault, horaatual) THEN
IF QRY_turno.F003_id > 0 THEN
xTurno = QRY_turno.F003_id

StartDateTime is DateTime = DateSys() + QRY_turno.F003_inicio
EndDateTime is DateTime = DataAgora
Diff is string
Diff = DateTimeDifference(StartDateTime, EndDateTime)

xtotalhoras is real = (StringToNum(Middle(Diff, 9, 2))) + (StringToNum(Middle(Diff, 11, 2)) / 60) + (StringToNum(Middle(Diff, 13, 2)) / 3600)


leitura.F003_inicio = DateSys() + QRY_turno.F003_inicio
leitura.F003_Termino = DateSys() + QRY_turno.F003_Termino
leitura.HorasTrabalhadas = xtotalhoras
// Trace(" ENTROU AQUI ", QRY_turno.F003_id)
ELSE
xTurno = 3
IF HExecuteQuery(QRY_turnoCod,hQueryDefault, xTurno) THEN
diaInicio is Date = DateSys()
proximoDia is Date = DateSys()

IF (TimeSys() = QRY_turnoCod.F003_inicio TO StringToTime("23:59:59")) THEN
diaInicio = DateSys()
proximoDia..Day += 1
END

IF (TimeSys() = StringToTime("00:00:00") TO QRY_turnoCod.F003_Termino) THEN
diaInicio..Day -= 1
proximoDia = DateSys()
END

StartDateTime is DateTime = diaInicio + QRY_turnoCod.F003_inicio
EndDateTime is DateTime = proximoDia + QRY_turnoCod.F003_Termino
Diff is string
Diff = DateTimeDifference(StartDateTime, EndDateTime)

xtotalhoras is real = (StringToNum(Middle(Diff, 9, 2))) + (StringToNum(Middle(Diff, 11, 2)) / 60) + (StringToNum(Middle(Diff, 13, 2)) / 3600)

leitura.F003_inicio = diaInicio + QRY_turnoCod.F003_inicio
leitura.F003_Termino = proximoDia + QRY_turnoCod.F003_Termino
leitura.HorasTrabalhadas = xtotalhoras
// Trace("ACHOU 3o TURNO ", QRY_turnoCod.F003_id)

ELSE
xTurno = 3
diaInicio is Date = DateSys()
proximoDia is Date = DateSys()

IF (TimeSys() = StringToTime("23:07:00") TO StringToTime("23:59:59")) THEN
diaInicio = DateSys()
proximoDia..Day += 1
END

IF (TimeSys() = StringToTime("00:00:00") TO StringToTime("05:49:59")) THEN
diaInicio..Day -= 1
proximoDia = DateSys()
END

StartDateTime is DateTime = diaInicio + StringToTime("23:07:00")
EndDateTime is DateTime = proximoDia + StringToTime("05:49:49")
Diff is string
Diff = DateTimeDifference(StartDateTime, EndDateTime)

xtotalhoras is real = (StringToNum(Middle(Diff, 9, 2))) + (StringToNum(Middle(Diff, 11, 2)) / 60) + (StringToNum(Middle(Diff, 13, 2)) / 3600)

leitura.F003_inicio = diaInicio + QRY_turnoCod.F003_inicio
leitura.F003_Termino = proximoDia + QRY_turnoCod.F003_Termino
leitura.HorasTrabalhadas = xtotalhoras

// Trace("NAO ACHOU 3o TURNO ")
END

END
ELSE
xTurno = 3
IF HExecuteQuery(QRY_turnoCod,hQueryDefault, xTurno) THEN
diaInicio is Date = DateSys()
proximoDia is Date = DateSys()

IF (TimeSys() = QRY_turnoCod.F003_inicio TO StringToTime("23:59:59")) THEN
diaInicio = DateSys()
proximoDia..Day += 1
END

IF (TimeSys() = StringToTime("00:00:00") TO QRY_turnoCod.F003_Termino) THEN
diaInicio..Day -= 1
proximoDia = DateSys()
END

StartDateTime is DateTime = diaInicio + QRY_turnoCod.F003_inicio
EndDateTime is DateTime = proximoDia + QRY_turnoCod.F003_Termino
Diff is string
Diff = DateTimeDifference(StartDateTime, EndDateTime)

xtotalhoras is real = (StringToNum(Middle(Diff, 9, 2))) + (StringToNum(Middle(Diff, 11, 2)) / 60) + (StringToNum(Middle(Diff, 13, 2)) / 3600)

leitura.F003_inicio = diaInicio + QRY_turnoCod.F003_inicio
leitura.F003_Termino = proximoDia + QRY_turnoCod.F003_Termino
leitura.HorasTrabalhadas = xtotalhoras
ELSE
xTurno = 3
diaInicio is Date = DateSys()
proximoDia is Date = DateSys()

IF (TimeSys() = StringToTime("23:07:00") TO StringToTime("23:59:59")) THEN
diaInicio = DateSys()
proximoDia..Day += 1
END

IF (TimeSys() = StringToTime("00:00:00") TO StringToTime("05:49:59")) THEN
diaInicio..Day -= 1
proximoDia = DateSys()
END

StartDateTime is DateTime = diaInicio + StringToTime("23:07:00")
EndDateTime is DateTime = proximoDia + StringToTime("05:49:49")
Diff is string
Diff = DateTimeDifference(StartDateTime, EndDateTime)

xtotalhoras is real = (StringToNum(Middle(Diff, 9, 2))) + (StringToNum(Middle(Diff, 11, 2)) / 60) + (StringToNum(Middle(Diff, 13, 2)) / 3600)

leitura.F003_inicio = diaInicio + QRY_turnoCod.F003_inicio
leitura.F003_Termino = proximoDia + QRY_turnoCod.F003_Termino
leitura.HorasTrabalhadas = xtotalhoras

// trace(" NÃO ENCONTROU TURNO 3 ")
END

END

leitura.F003_id = xTurno
leitura.datafabrica = leitura.F003_inicio..Date

IF NOT HExecuteQuery(QRY_RITMO, hQueryDefault, DataMinuto, DataAgora) THEN
Error("NAO CONSEGUI EXECUTAR", HErrorInfo())
ELSE
ritmo01 is int = (QRY_RITMO.CLP01_qtde01_max - QRY_RITMO.CLP01_qtde01_min)
ritmo02 is int = (QRY_RITMO.CLP01_qtde02_max - QRY_RITMO.CLP01_qtde02_min)
ritmo03 is int = (QRY_RITMO.CLP01_qtde03_max - QRY_RITMO.CLP01_qtde03_min)
ritmo04 is int = (QRY_RITMO.CLP01_qtde04_max - QRY_RITMO.CLP01_qtde04_min)
ritmo05 is int = (QRY_RITMO.CLP01_qtde05_max - QRY_RITMO.CLP01_qtde05_min)
ritmo06 is int = (QRY_RITMO.CLP01_qtde06_max - QRY_RITMO.CLP01_qtde06_min)
ritmo07 is int = (QRY_RITMO.CLP01_qtde07_max - QRY_RITMO.CLP01_qtde07_min)
ritmo08 is int = (QRY_RITMO.CLP01_qtde08_max - QRY_RITMO.CLP01_qtde08_min)
// Info("RITMO 01 ", ritmo01)
leitura.ritmo01 = ritmo01
leitura.ritmo02 = ritmo02
leitura.ritmo03 = ritmo03
leitura.ritmo04 = ritmo04
leitura.ritmo05 = ritmo05
leitura.ritmo06 = ritmo06
leitura.ritmo07 = ritmo07
leitura.ritmo08 = ritmo08

END

IF xErro = "N" THEN
IF HAdd(leitura) = True THEN
TABLE_Leitura.Display(taCurrentRecord)
END
END

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/