- aggiornata lettura/scrittura variabili

- correzioni per funzionamento supervisore con lettura/scrittura variabili corrette
This commit is contained in:
Emmanuele Sassi
2023-11-06 10:36:33 +01:00
parent 58acf21f52
commit 113ad8bcf6
3 changed files with 70 additions and 23 deletions
@@ -60,7 +60,7 @@ Public Class SIEMENSSharp7Comm
#Region "Read Variables"
Public Sub RefreshAllVars()
Dim TestBuffer() As Byte = {3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
' Dim TestBuffer() As Byte = {3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
m_DBVariableList.Clear()
For Each Var In m_ReadingVars
@@ -94,14 +94,14 @@ Public Class SIEMENSSharp7Comm
Dim nBytePositionIndex As Integer = 0
Integer.TryParse(PositionAddressSplit(1), nBytePositionIndex)
Dim nPower As Integer = Math.Pow(2, nBytePositionIndex)
Dim bValue As Boolean = (TestBuffer(nStartIndex) And nPower) = nPower
Var.SetValue((DBBuffer.DBValue(nStartIndex) And nPower) = nPower)
' Dim bValue As Boolean = (TestBuffer(nStartIndex) And nPower) = nPower
Var.SetValue(If((DBBuffer.DBValue(nStartIndex) And nPower) = nPower, 1, 0))
Case 2
Dim x = BitConverter.ToInt16(TestBuffer, nStartIndex)
'Dim x = BitConverter.ToInt16(TestBuffer, nStartIndex)
Dim nValue As Int16 = BitConverter.ToInt16(DBBuffer.DBValue, nStartIndex)
Var.SetValue(BinaryPrimitives.ReverseEndianness(nValue))
Case 3
Dim x = BitConverter.ToInt32(TestBuffer, nStartIndex)
' Dim x = BitConverter.ToInt32(TestBuffer, nStartIndex)
Dim nValue As Integer = BitConverter.ToInt32(DBBuffer.DBValue, nStartIndex)
Var.SetValue(BinaryPrimitives.ReverseEndianness(nValue))
End Select
@@ -119,10 +119,29 @@ Public Class SIEMENSSharp7Comm
Integer.TryParse(PositionAddressSplit(0), nStartIndex)
Select Case CompleteAddressSplit(2)
Case 1
Dim nValue As Integer = 0
If Not Integer.TryParse(Value, nValue) Then Return False
Dim bValue As Boolean = nValue > 0
Return WriteBool(nDBAddress, nStartIndex, bValue)
' rileggo int16
Dim Buffer(1) As Byte
Client.DBRead(nDBAddress, nStartIndex, 1, Buffer)
' Dim bValue As Boolean = nValue > 0
Dim nBytePositionIndex As Integer = 0
Integer.TryParse(PositionAddressSplit(1), nBytePositionIndex)
Dim nPower As Integer = Math.Pow(2, nBytePositionIndex)
Dim nNewValue As Integer = 0
If Not Integer.TryParse(Value, nNewValue) Then Return False
Dim nOldValue As Integer = If((Buffer(0) And nPower) = nPower, 1, 0)
If nOldValue = nNewValue Then
Return True
ElseIf nOldValue = 0 Then
Buffer(0) = Buffer(0) Or nPower
ElseIf nOldValue = 1 Then
Buffer(0) = Buffer(0) Xor nPower
Else
Return False
End If
' Buffer(0) = Buffer(0) And nPower
Return Client.DBWrite(nDBAddress, nStartIndex, 1, Buffer) ' DbNumber, Start, Amount, Buffer
' Return WriteBool(nDBAddress, nStartIndex, bValue)
Case 2
Dim nValue As Int16 = 0
If Not Int16.TryParse(Value, nValue) Then Return False
@@ -59,6 +59,8 @@ Module ConstCommVar
Public Const DATAREADED As String = "Data_Readed"
' variabile per confermare lettura stato reset
Public Const RESETREADED As String = "Reset_Readed"
' variabile per confermare lettura stato reset
Public Const DATATOREAD As String = "Data_ToRead"
Public Enum OPStates
Start = 1
@@ -7,6 +7,7 @@ Imports EgtWPFLib5
Imports System.IO
Imports EgtBEAMWALL.Core
Imports EgtBEAMWALL.Supervisor.CommVar
Imports System.Windows.Forms.VisualStyles
Public Class MachManaging
@@ -273,6 +274,7 @@ Public Class MachManaging
Dim MachIndexVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = MACHINDEX)
Dim DataReadedVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = DATAREADED)
Dim ResetReadedVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RESETREADED)
Dim DataToReadVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = DATATOREAD)
Select Case CurrentMachine.NCType
Case NCTypes.TPA
' leggo tutte le variabili
@@ -488,6 +490,14 @@ Public Class MachManaging
nDataWrite = -1
End If
End Select
' se SiemensSharp7 e reset a 0, verifico che conferma lettura reset sia a zero
If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 And ResetReadedVariable.sValue = "1" And ResetVariable.sValue = "0" Then
ResetReadedVariable.sValue = "0"
End If
' se SiemensSharp7 e dati letti a 1 e dati scritti a 0, verifico che dati letti sia a zero
If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 And DataReadedVariable.sValue = "1" And DataToReadVariable.sValue = "0" Then
DataReadedVariable.sValue = "0"
End If
' se NUM aggiorno stato della macchina
If CurrentMachine.NCType = NCTypes.NUM_FLEXIUM Then
Dim OpState As OPStates
@@ -539,10 +549,15 @@ Public Class MachManaging
' resetto tutti i programmi
If Not IsNothing(Map.refProjectVM.SupervisorMachGroupPanelVM) Then Map.refProjectVM.SupervisorMachGroupPanelVM.ResetAllMachGroups()
' resetto variabili P
ProdVariable.sValue = "0"
MachGroupVariable.sValue = "0"
PartVariable.sValue = "0"
StateVariable.sValue = "0"
If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then
'resetto programma corrente
ISONumVariable.sValue = "0"
Else
ProdVariable.sValue = "0"
MachGroupVariable.sValue = "0"
PartVariable.sValue = "0"
StateVariable.sValue = "0"
End If
'Tpa.RWVariableManager.WriteVar(P_PROD, 0)
'Tpa.RWVariableManager.WriteVar(P_MACHGROUP, 0)
'Tpa.RWVariableManager.WriteVar(P_PART, 0)
@@ -553,7 +568,7 @@ Public Class MachManaging
End If
' azzero variabile reset
If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then
ResetReadedVariable.sValue = "0"
ResetReadedVariable.sValue = "1"
Else
ResetVariable.sValue = "0"
End If
@@ -580,9 +595,15 @@ Public Class MachManaging
' attesa per essere sicuro che abbia scritto e riletto variabili
Threading.Thread.Sleep(300)
' verifico stati inizio e fine pezzi
ElseIf nP_Prod <> 0 AndAlso
nP_Machgroup <> 0 AndAlso
nP_Part <> 0 Then
ElseIf (CurrentMachine.NCType <> NCTypes.SIEMENS_SHARP7 AndAlso
nP_Prod <> 0 AndAlso
nP_Machgroup <> 0 AndAlso
nP_Part <> 0) OrElse
(CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 AndAlso
DataToReadVariable.sValue = "1" AndAlso
nP_Prod <> 0 AndAlso
nP_Machgroup <> 0 AndAlso
nP_Part <> 0) Then
If nP_State = PartState.START Then
Dim dtStart As DateTime = DateTime.Now()
' recupero gruppo di lavorazione del pezzo
@@ -626,7 +647,7 @@ Public Class MachManaging
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT
StateVariable.sValue = "0"
Case NCTypes.SIEMENS_SHARP7
DataReadedVariable.sValue = "0"
DataReadedVariable.sValue = "1"
End Select
' se nessun pezzo della barra diverso da quello corrente e' in start
If Not MachGroup.PartVMList.Any(Function(x) x.nPartId <> nP_Part AndAlso x.nProduction_State = 1) Then
@@ -707,10 +728,15 @@ Public Class MachManaging
' scrivo evento fine MachGroup su DB
DbControllers.m_LogMachineController.Create(LogEvent.CreateMachGroupStateLog(dtEnd, nP_Prod, nP_Machgroup, nP_State, DbControllers.SupervisorId))
' azzero tutte le variabilli per iniziare barra successiva
ProdVariable.sValue = "0"
MachGroupVariable.sValue = "0"
PartVariable.sValue = "0"
StateVariable.sValue = "0"
' azzero variabile per far ripartire macchina
If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then
DataReadedVariable.sValue = "1"
Else
ProdVariable.sValue = "0"
MachGroupVariable.sValue = "0"
PartVariable.sValue = "0"
StateVariable.sValue = "0"
End If
' se non impostata data start
If MachGroup.dtStartTime = DateTime.MinValue Then
@@ -1167,7 +1193,7 @@ Public Class MachManaging
If Integer.TryParse(ProgramId, nFileType) AndAlso nFileType > 0 Then
Dim sDestDir As String = ""
GetPrivateProfileString(S_GENERAL, K_ISOFILEDIR, "c:/Saomad/ISO", sDestDir, CurrentMachine.sMachIniFile)
File.Copy(ProgramPath, sDestDir & nFileType & ".mpf")
File.Copy(ProgramPath, sDestDir & "/" & nFileType & ".mpf", True)
Dim ISONumVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_NUM)
ISONumVariable.sValue = nFileType
End If