Merge branch 'feature/CommSharp7' into feature/NewWarehouseSiemens

This commit is contained in:
Emmanuele Sassi
2024-07-02 17:23:25 +02:00
13 changed files with 869 additions and 61 deletions
@@ -0,0 +1,456 @@
Imports System.Buffers.Binary
Imports EgtUILib
Imports EgtWPFLib5
Imports Sharp7
Public Class SIEMENSSharp7Comm
Private m_DBVariableList As New List(Of DBBuffer) ' Buffer list
Private IntBuffer() As Byte = {0, 0}
Private BoolBuffer() As Byte = {0}
Private DIntBuffer() As Byte = {0, 0, 0, 0}
Private RealBuffer() As Byte = {0, 0, 0, 0}
Private StringBuffer(65536) As Byte ' Buffer
Private Client As New S7Client ' Client Object
' lista variabili in lettura
Private Shared m_ReadingVars(100) As CommVar
' lista dei messaggi di errore attivi
Private m_ActiveMessages As New List(Of SiemensReadMessages)
Private m_MachManaging As MachManaging
Friend ReadOnly Property MachManaging As MachManaging
Get
Return m_MachManaging
End Get
End Property
Public Sub New(MachManaging As MachManaging)
m_MachManaging = MachManaging
End Sub
Public Shared Function InitVar(Variable As CommVar) As CommVar
Dim Index As Integer = Array.IndexOf(m_ReadingVars, Nothing)
m_ReadingVars(Index) = Variable
Return m_ReadingVars(Index)
End Function
' Avvio la connessione Hardware-Client
Friend Function InitConnection() As Boolean
' Ip del PLC
Dim sIp As String = ""
GetPrivateProfileString(S_GENERAL, K_IP, "", sIp, CurrentMachine.sMachIniFile)
' unità usate dal PLC (Rack e Slot)
Dim nRack As Integer = GetPrivateProfileInt(S_GENERAL, K_RACK, 0, CurrentMachine.sMachIniFile)
Dim nSlot As Integer = GetPrivateProfileInt(S_GENERAL, K_SLOT, 0, CurrentMachine.sMachIniFile)
Map.refMachManaging.DebugMessage(1, "Tentativo di connessione a CN Siemens con Sharp7")
Map.refMachManaging.DebugMessage(1, "IP: " & sIp)
Map.refMachManaging.DebugMessage(1, "Rack: " & nRack)
Map.refMachManaging.DebugMessage(1, "Slot: " & nSlot)
Dim nResult As Integer = Client.ConnectTo(sIp, nRack, nSlot)
If nResult = 0 Then
Map.refMachManaging.DebugMessage(1, "Connessione effettuata")
Else
Map.refMachManaging.DebugMessage(1, "Connessione fallita con codice di errore: " & nResult)
End If
' se la connessione è restituisce 0
Return nResult = 0
End Function
' chiudo la connessione
Friend Sub CloseConnection()
Dim nResult As Integer = Client.Disconnect()
If Map.refMachManaging.Debug > 0 Then
If nResult = 0 Then
EgtOutLog("Disconnessione effettuata")
Else
EgtOutLog("Disconnessione fallita con codice di errore: " & nResult)
End If
End If
End Sub
#Region "Read Variables"
Public Sub RefreshAllVars()
m_DBVariableList.Clear()
For Each Var In m_ReadingVars
' rileggo solo variabili continue
If Not IsNothing(Var) AndAlso Var.nReadType = CommVar.ReadTypes.CONTINUOUS Then
Dim CompleteAddressSplit() As String = Var.sAddress.Split(":"c)
Dim nDBAddress As Integer = 0
Integer.TryParse(CompleteAddressSplit(0), nDBAddress)
If nDBAddress = 0 Then Return
Dim DBBuffer As DBBuffer = m_DBVariableList.FirstOrDefault(Function(x) x.DBAddress = nDBAddress)
If IsNothing(DBBuffer) Then
Dim Buffer(65536) As Byte
Dim nAddressByte As Integer = 0
Select Case nDBAddress
Case 301
nAddressByte = 8
Case 302
nAddressByte = 34
End Select
Map.refMachManaging.DebugMessage(1, "Lettura di " & nAddressByte & " byte dalla variabile " & nDBAddress)
Dim nResult As Integer = 1234567890
Try
nResult = Client.DBRead(nDBAddress, 0, nAddressByte, Buffer)
Catch ex As Exception
nResult = 1234567890
Map.refMachManaging.DebugMessage(1, "Lettura di " & nDBAddress & " ha generato un'eccezione")
Map.refMachManaging.DebugMessage(1, ex.ToString())
End Try
If nResult = 0 Then
Map.refMachManaging.DebugMessage(1, "Lettura di " & nDBAddress & " effettuata")
If Map.refMachManaging.Debug > 1 Then
For Index = 0 To Buffer.Count - 1
Map.refMachManaging.DebugMessage(2, Index & ": " & Buffer(Index))
Next
End If
Else
Map.refMachManaging.DebugMessage(2, "Lettura fallita con codice di errore: " & nResult)
End If
If nResult = 0 Then
DBBuffer = New DBBuffer(nDBAddress, Buffer)
m_DBVariableList.Add(DBBuffer)
End If
End If
If Not IsNothing(DBBuffer) Then
Dim PositionAddressSplit() As String = CompleteAddressSplit(1).Split("."c)
Dim nStartIndex As Integer = 0
Integer.TryParse(PositionAddressSplit(0), nStartIndex)
Select Case CompleteAddressSplit(2)
Case 1
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
Map.refMachManaging.DebugMessage(2, "Lettura variabile " & nDBAddress & ":" & nStartIndex & "." & nBytePositionIndex)
Var.SetValue(If((DBBuffer.DBValue(nStartIndex) And nPower) = nPower, 1, 0))
Map.refMachManaging.DebugMessage(2, "Variabile " & nDBAddress & ":" & nStartIndex & "." & nBytePositionIndex & " (Tipo 1) = " & Var.sValue)
Case 2
'Dim x = BitConverter.ToInt16(TestBuffer, nStartIndex)
Dim nValue As Int16 = BitConverter.ToInt16(DBBuffer.DBValue, nStartIndex)
Map.refMachManaging.DebugMessage(2, "Lettura variabile " & nDBAddress & ":" & nStartIndex)
Var.SetValue(BinaryPrimitives.ReverseEndianness(nValue))
Map.refMachManaging.DebugMessage(2, "Variabile " & nDBAddress & ":" & nStartIndex & " (Tipo 2) = " & Var.sValue)
Case 3
' Dim x = BitConverter.ToInt32(TestBuffer, nStartIndex)
Dim nValue As Integer = BitConverter.ToInt32(DBBuffer.DBValue, nStartIndex)
Map.refMachManaging.DebugMessage(2, "Lettura variabile " & nDBAddress & ":" & nStartIndex)
Var.SetValue(BinaryPrimitives.ReverseEndianness(nValue))
Map.refMachManaging.DebugMessage(2, "Variabile " & nDBAddress & ":" & nStartIndex & " (Tipo 3) = " & Var.sValue)
End Select
End If
End If
Next
End Sub
Friend Function WriteVariable(Address As String, Value As String) As Boolean
Dim CompleteAddressSplit() As String = Address.Split(":"c)
Dim nDBAddress As Integer = 0
Integer.TryParse(CompleteAddressSplit(0), nDBAddress)
If nDBAddress = 0 Then Return False
Dim PositionAddressSplit() As String = CompleteAddressSplit(1).Split("."c)
Dim nStartIndex As Integer = 0
Integer.TryParse(PositionAddressSplit(0), nStartIndex)
Select Case CompleteAddressSplit(2)
Case 1
' rileggo int16
Dim Buffer(1) As Byte
Client.DBRead(nDBAddress, nStartIndex, 1, Buffer)
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
If Map.refMachManaging.Debug > 1 Then
EgtOutLog("Scrittura variabile " & Address & " (Tipo 1) con valore " & Value)
For Index = 0 To Buffer.Count - 1
EgtOutLog(Index & ": " & Buffer(Index))
Next
End If
Dim nResult As Integer = Client.DBWrite(nDBAddress, nStartIndex, 1, Buffer) ' DbNumber, Start, Amount, Buffer
' Return WriteBool(nDBAddress, nStartIndex, bValue)
If Map.refMachManaging.Debug > 1 Then
If nResult <> 0 Then
EgtOutLog("Scrittura variabile " & nDBAddress & ":" & nStartIndex & " con valore " & Value & " effettuata")
Else
EgtOutLog("Scrittura variabile " & nDBAddress & ":" & nStartIndex & " con valore " & Value & " fallita")
End If
End If
Return nResult = 0
Case 2
Dim nValue As Int16 = 0
If Not Int16.TryParse(Value, nValue) Then Return False
If Map.refMachManaging.Debug > 1 Then
EgtOutLog("Scrittura variabile " & Address & " (Tipo 2) con valore " & Value)
End If
Dim bResult As Boolean = WriteInt(nDBAddress, nStartIndex, nValue)
If Map.refMachManaging.Debug > 1 Then
If bResult Then
EgtOutLog("Scrittura variabile " & nDBAddress & ":" & nStartIndex & " con valore " & Value & " effettuata")
Else
EgtOutLog("Scrittura variabile " & nDBAddress & ":" & nStartIndex & " con valore " & Value & " fallita")
End If
End If
Return bResult
Case 3
Dim nValue As Integer = 0
If Not Integer.TryParse(Value, nValue) Then Return False
If Map.refMachManaging.Debug > 1 Then
EgtOutLog("Scrittura variabile " & Address & " (Tipo 3) con valore " & Value)
End If
Dim bResult As Boolean = WriteDInt(nDBAddress, nStartIndex, nValue)
If Map.refMachManaging.Debug > 1 Then
If bResult Then
EgtOutLog("Scrittura variabile " & nDBAddress & ":" & nStartIndex & " con valore " & Value & " effettuata")
Else
EgtOutLog("Scrittura variabile " & nDBAddress & ":" & nStartIndex & " con valore " & Value & " fallita")
End If
End If
Return bResult
End Select
End Function
#End Region ' Read Variables
Friend Function ReadInt(DBNumber As Integer, Start As Integer, ByRef Value As Integer) As Boolean
' Read 2 bytes from the DBNumber starting from Start and puts them into ReadBuffer.
Dim Result As Integer = Client.DBRead(DBNumber, Start, 2, IntBuffer) ' DbNumber, Start, Amount, Buffer
If Result = 0 Then
Value = S7.GetIntAt(IntBuffer, 0)
Return True
End If
Return False
End Function
Friend Function WriteInt(DBNumber As Integer, Start As Integer, Value As Int16) As Boolean
S7.SetIntAt(IntBuffer, 0, Value)
' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer.
Dim Result As Integer = Client.DBWrite(DBNumber, Start, 2, IntBuffer) ' DbNumber, Start, Amount, Buffer
Return Result = 0
End Function
Friend Function ReadBool(DBNumber As Integer, Start As Integer, ByRef Value As Boolean) As Boolean
' Read 2 bytes from the DBNumber starting from Start and puts them into ReadBuffer.
Dim Result As Integer = Client.DBRead(DBNumber, Start, 1, BoolBuffer) ' DbNumber, Start, Amount, Buffer
If Result = 0 Then
Value = BitConverter.ToBoolean(BoolBuffer, 0)
Return True
End If
Return False
End Function
Friend Function WriteBool(DBNumber As Integer, Start As Integer, Value As Boolean) As Boolean
If Value Then
BoolBuffer(0) = &H1
Else
BoolBuffer(0) = &H0
End If
' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer.
Dim Result As Integer = Client.DBWrite(DBNumber, Start, 1, BoolBuffer) ' DbNumber, Start, Amount, Buffer
Return Result = 0
End Function
Friend Function ReadDInt(DBNumber As Integer, Start As Integer, ByRef Value As Integer) As Boolean
' Read 2 bytes from the DBNumber starting from Start and puts them into ReadBuffer.
Dim Result As Integer = Client.DBRead(DBNumber, Start, 4, DIntBuffer) ' DbNumber, Start, Amount, Buffer
If Result = 0 Then
Value = S7.GetDIntAt(DIntBuffer, 0)
Return True
End If
Return False
End Function
Friend Function WriteDInt(DBNumber As Integer, Start As Integer, Value As Integer) As Boolean
S7.SetDIntAt(DIntBuffer, 0, Value)
' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer.
Dim Result As Integer = Client.DBWrite(DBNumber, Start, 4, DIntBuffer) ' DbNumber, Start, Amount, Buffer
Return Result = 0
End Function
Friend Function ReadReal(DBNumber As Integer, Start As Integer, ByRef Value As Double) As Boolean
' Read 4 bytes from the DBNumber starting from Start and puts them into ReadBuffer.
Dim Result As Integer = Client.DBRead(DBNumber, Start, 4, RealBuffer) ' DbNumber, Start, Amount, Buffer
If Result = 0 Then
Value = S7.GetRealAt(RealBuffer, 0)
Return True
End If
Return False
End Function
Friend Function WriteReal(DBNumber As Integer, Start As Integer, Value As Single) As Boolean
S7.SetRealAt(RealBuffer, 0, Value)
' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer.
Dim Result As Integer = Client.DBWrite(DBNumber, Start, 4, RealBuffer) ' DbNumber, Start, Amount, Buffer
Return Result = 0
End Function
Friend Function ReadString(DBNumber As Integer, Start As Integer, Length As Integer, ByRef Value As String) As Boolean
' Read 2 bytes from the DBNumber starting from Start and puts them into ReadBuffer.
Dim Result As Integer = Client.DBRead(DBNumber, Start, Length, StringBuffer) ' DbNumber, Start, Amount, Buffer
If Result = 0 Then
Value = S7.GetStringAt(StringBuffer, 0)
Return True
End If
Return False
End Function
Friend Function WriteString(DBNumber As Integer, Start As Integer, Value As String) As Boolean
If Value.Length > 65535 Then
Return False
End If
S7.SetStringAt(StringBuffer, 0, 65535, Value)
' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer.
Dim Result As Integer = Client.DBWrite(DBNumber, Start, Value.Length + 2, StringBuffer) ' DbNumber, Start, Amount, Buffer
Return Result = 0
End Function
Friend Sub ResetStep(bReset As Boolean)
Dim ResetStep As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList(19) ' Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RESET_STEP)
If bReset Then
Map.refMachManaging.DebugMessage(1, "Imposto variabile ResetStep a 1")
ResetStep.sValue = 1
Threading.Thread.Sleep(100)
Dim nResetStepOk As Integer = 0
Dim ResetStepOk As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RESET_STEP_OK)
While nResetStepOk <> 1
Map.refMachManaging.DebugMessage(1, "Rileggo variabili")
RefreshAllVars()
Map.refMachManaging.DebugMessage(1, "Leggo valore ResetStepOk")
Integer.TryParse(ResetStepOk.sValue, nResetStepOk)
Threading.Thread.Sleep(1000)
End While
End If
ResetStep.sValue = 0
Map.refMachManaging.DebugMessage(1, "Imposto variabile ResetStep a 0")
End Sub
Friend Sub ReadPLCMessages()
Dim nPlc_Msg As New List(Of Byte)
For Index As Integer = 1 To 6
Dim nIndex As Integer = Index
Dim PLCMessagesVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = PLC_MESSAGES & nIndex)
If IsNothing(PLCMessagesVariable) OrElse IsNothing(PLCMessagesVariable.sValue) Then Return
Dim nTemp As Int16 = 0
Int16.TryParse(PLCMessagesVariable.sValue, nTemp)
nTemp = BinaryPrimitives.ReverseEndianness(nTemp)
Dim Bytes As Byte() = BitConverter.GetBytes(nTemp)
nPlc_Msg.AddRange(Bytes)
Next
Dim BitArray As New BitArray(nPlc_Msg.ToArray())
Dim ErrorList As New List(Of Integer)
For BitIndex = 0 To BitArray.Count - 1
If BitIndex <= 169 AndAlso BitArray(BitIndex) Then
ErrorList.Add(BitIndex)
End If
Next
ShowPLCError(ErrorList)
End Sub
Friend Sub ShowPLCError(ErrorNumber As List(Of Integer))
' resetto stati bFound
For Each Message In m_ActiveMessages
Message.bFound = False
Next
For index As Integer = 0 To ErrorNumber.Count - 1
Dim nIndex As Integer = index
Dim NewMessageInList As SiemensReadMessages = m_ActiveMessages.FirstOrDefault(Function(x) x.nIndex = 0.ToString())
' se il messaggio e' gia' in lista
If Not IsNothing(NewMessageInList) Then
' lo segno come trovato
NewMessageInList.bFound = True
Else
' lo aggiungo
Dim NewMessage As SiemensReadMessages = New SiemensReadMessages(0.ToString())
NewMessage.bFound = True
m_ActiveMessages.Add(NewMessage)
m_SiemensAlarmCallbackDlg(0, 0)
End If
Next
' cancello messaggi non trovati
For Index = m_ActiveMessages.Count - 1 To 0 Step -1
Dim Message As SiemensReadMessages = m_ActiveMessages(Index)
If Not Message.bFound Then
m_SiemensAlarmCallbackDlg(Message.nIndex, 1)
m_ActiveMessages.RemoveAt(Index)
End If
Next
End Sub
End Class
Friend Class DBBuffer
Private m_DBAddress As Integer
Public ReadOnly Property DBAddress As Integer
Get
Return m_DBAddress
End Get
End Property
Private m_DBValue(65536) As Byte
Public ReadOnly Property DBValue As Byte()
Get
Return m_DBValue
End Get
End Property
Sub New(DBAddress As Integer, DBValue As Byte())
m_DBAddress = DBAddress
m_DBValue = DBValue
End Sub
End Class
Public Class SiemensReadMessages
Private m_nIndex As Integer
Public ReadOnly Property nIndex As Integer
Get
Return m_nIndex
End Get
End Property
Private m_sMessage As String
Public ReadOnly Property sMessage As String
Get
Return m_sMessage
End Get
End Property
Friend Sub SetMessage(sValue As String)
m_sMessage = sValue
End Sub
Private m_bFound As Boolean = False
Friend Property bFound As Boolean
Get
Return m_bFound
End Get
Set(value As Boolean)
m_bFound = value
End Set
End Property
Public Sub New(nIndex As Integer)
m_nIndex = nIndex
m_sMessage = sMessage
End Sub
End Class
@@ -19,6 +19,7 @@ Module ConstCommVar
NUM_FLEXIUM = 2
NUM_AXIUM_APSERVER = 3
NUM_AXIUM_PCTOOLKIT = 4
SIEMENS_SHARP7 = 5
End Enum
' Assi
@@ -54,6 +55,22 @@ Module ConstCommVar
Public Const PLC_MESSAGES As String = "PLC_Messages"
' variabile per leggere e scrivere permesso invio cn a macchina
Public Const SENDPERMISSION As String = "SendPermission"
' variabile per confermare lettura dati di stato pezzo
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"
' variabile per confermare lettura stato reset
Public Const RESET_STEP As String = "Reset_Step"
' variabile per confermare lettura stato reset
Public Const RESET_STEP_OK As String = "Reset_Step_Ok"
' variabile per stato CN
Public Const NC_STATUS As String = "NC_Status"
' variabile per modo CN
Public Const NC_MODE As String = "NC_Mode"
' variabile per apertura pinze manuale
Public Const OPEN_CLAMP As String = "Open_Clamp"
Public Enum OPStates
Start = 1
@@ -72,4 +89,11 @@ Module ConstCommVar
Home = 8
End Enum
' Variabili Siemens
Public Const K_IP As String = "Ip"
Public Const K_RACK As String = "Rack"
Public Const K_SLOT As String = "Slot"
Public Const K_TIMERINTERVAL As String = "TimerInterval"
Public Const K_ISOFILEDIR As String = "IsoFileDir"
End Module
@@ -163,6 +163,9 @@
<Reference Include="SdkApi.Desktop.Usb, Version=2.15.2634.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Zebra.Printer.SDK.2.15.2634\lib\net471\SdkApi.Desktop.Usb.dll</HintPath>
</Reference>
<Reference Include="Sharp7.net">
<HintPath>..\..\..\EgtProg\EgtBEAMWALL\Sharp7.net.dll</HintPath>
</Reference>
<Reference Include="SharpSnmpLib, Version=12.1.0.0, Culture=neutral, PublicKeyToken=4c00852d3788e005, processorArchitecture=MSIL">
<HintPath>..\packages\Lextm.SharpSnmpLib.12.1.0\lib\net471\SharpSnmpLib.dll</HintPath>
</Reference>
@@ -283,6 +286,7 @@
<Compile Include="Comms\NUMAxiumComm.vb" />
<Compile Include="Comms\NUMAxiumPcToolkitComm.vb" />
<Compile Include="Comms\NUMFlexiumComm.vb" />
<Compile Include="Comms\SIEMENSSharp7Comm.vb" />
<Compile Include="Comms\TPAComm.vb" />
<Compile Include="Constants\ConstMachMsg.vb" />
<Compile Include="MachineLogPage\MachineLogPageV.xaml.vb">
@@ -49,7 +49,8 @@
Visibility="{Binding E80002_Visibility}"/>
</UniformGrid>
<Expander Grid.Row="4"
Header="Axis">
Header="Axis"
Visibility="{Binding Axis_Visibility}">
<EgtBEAMWALL:AxesPanelV DataContext="{StaticResource AxesPanelVM}"/>
</Expander>
@@ -148,6 +148,17 @@ Public Class LeftPanelVM
End Get
End Property
Public Property m_Axis_Visibility As Visibility
Public ReadOnly Property Axis_Visibility As Visibility
Get
Return m_Axis_Visibility
End Get
End Property
Friend Sub SetAxisVisibility()
m_Axis_Visibility = If(CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7, Visibility.Collapsed, Visibility.Visible)
NotifyPropertyChanged(NameOf(Axis_Visibility))
End Sub
Private m_bRestart As Boolean = False
Public Property bRestart As Boolean
Get
@@ -269,7 +280,7 @@ Public Class LeftPanelVM
Public ReadOnly Property OPMode_Visibility As Visibility
Get
Return If(CurrentMachine.NCType = NCTypes.NUM_FLEXIUM Or CurrentMachine.NCType = NCTypes.NUM_AXIUM_APSERVER Or CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT, Visibility.Visible, Visibility.Collapsed)
Return If(CurrentMachine.NCType = NCTypes.NUM_FLEXIUM Or CurrentMachine.NCType = NCTypes.NUM_AXIUM_APSERVER Or CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT Or CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7, Visibility.Visible, Visibility.Collapsed)
End Get
End Property
@@ -430,7 +441,7 @@ Public Class LeftPanelVM
New OPState("Pending", OPStates.Pending),
New OPState("Unspecified", OPStates.Unspecified)
}
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT, NCTypes.SIEMENS_SHARP7
m_OPStateList = New List(Of OPState) From {
New OPState("Start", OPStates.Start),
New OPState("Stop", OPStates.Stop),
@@ -462,12 +473,19 @@ Public Class LeftPanelVM
New OPState("Manual", OPModes.Manual),
New OPState("Home", OPModes.Home)
}
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT, NCTypes.SIEMENS_SHARP7
m_OPModeList = New List(Of OPState) From {
New OPState("Auto", OPModes.Auto),
New OPState("Mdi", OPModes.Mdi),
New OPState("Manual", OPModes.Manual),
New OPState("Reference Point", OPModes.Home)
}
End Select
End Sub
Friend Sub SetE80000Visibility()
' imposto visibilità variabili E80000 e seconda del tipo di controllo
If CurrentMachine.NCType = NCTypes.TPA Then
If CurrentMachine.NCType = NCTypes.TPA OrElse CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then
m_E80000_Visibility = Visibility.Collapsed
m_E80002_Visibility = Visibility.Collapsed
Else
@@ -324,7 +324,7 @@ Public Class MachCommandMessagePanelVM
m_MachManagingThread = New Thread(Sub()
MachineCommThread.MachManagingThreadFunction(AddressOf ResultCallbackDlg, AddressOf CloseCallbackDlg,
AddressOf UpdateCallbackDlg, AddressOf TPAAlarmCallbackDlg, AddressOf NUMAlarmCallbackDlg,
AddressOf AxisCoordinatesCallbackDlg, AddressOf OpStateCallbackDlg,
AddressOf SiemensAlarmCallbackDlg, AddressOf AxisCoordinatesCallbackDlg, AddressOf OpStateCallbackDlg,
AddressOf OpModeCallbackDlg, AddressOf ChannelCallbackDlg, AddressOf ReadVarCallbackDlg)
End Sub)
' avvio thread di gestione della macchina che avvia la connessione
@@ -804,6 +804,42 @@ Public Class MachCommandMessagePanelVM
DbControllers.m_LogMachineController.Create(LogEvent.CreateAlarmLog(DateTime.Now(), AlarmOperation & LogEvent.cSeparator & ErrorTyp & LogEvent.cSeparator & AlarmMessage & LogEvent.cSeparator & AlarmCode & LogEvent.cSeparator, DbControllers.m_SupervisorId))
End Sub
Friend Sub SiemensAlarmCallbackDlg(nIndex As Integer, AlarmOperation As AlarmOperation)
' se aggiungo allarme e non ce ne erano
If AlarmOperation = CInt(ISOCNC.Remoting.AlarmOperation.Addition) AndAlso m_ErrCycle.Count = 0 AndAlso m_Iso.Count = 0 AndAlso m_Message.Count = 0 AndAlso m_ErrSystem.Count = 0 Then
' avvio il timer degli allarmi
m_AlarmTimer.Start()
End If
Dim AlarmMessage As String = nIndex
' costruisco messaggio errore in base al tipo
Dim sErrorMessage As String = AlarmMessage
If bMsgTranslationActive Then
Dim sTranslatedMsg = MachMsg(MsgParagraphs.PLC, nIndex)
If Not String.IsNullOrWhiteSpace(sTranslatedMsg) Then
sErrorMessage = sTranslatedMsg
End If
End If
AlarmMessage = If(Not String.IsNullOrWhiteSpace(sErrorMessage), sErrorMessage, "")
If AlarmOperation = CInt(ISOCNC.Remoting.AlarmOperation.Addition) Then
m_ErrCycle.Add(Alarm.CreateAlarm(nIndex, AlarmMessage))
Else
m_ErrCycle.RemoveAll(Function(x) x.sCode = nIndex)
End If
' forzo aggiornamento allarmi
AlarmTimer_Tick()
' se non ci sono errori
If m_ErrCycle.Count = 0 AndAlso m_Iso.Count = 0 AndAlso m_Message.Count = 0 AndAlso m_ErrSystem.Count = 0 Then
' fermo timer degli allarmi
m_AlarmTimer.Stop()
End If
'DbControllers.m_LogMachineController.Create(MachLog.CreateAlarmLog(AlarmOperation, ErrorTyp, AlarmMessage, AlarmCode, DateTime.Now))
DbControllers.m_LogMachineController.Create(LogEvent.CreateAlarmLog(DateTime.Now(), AlarmOperation & LogEvent.cSeparator & nIndex & LogEvent.cSeparator & sErrorMessage, DbControllers.m_SupervisorId))
End Sub
Friend Sub AxisCoordinatesCallbackDlg(AxisValue As Double, AxisIndex As Integer)
Map.refAxesPanelVM.AxisCoordinatesCallbackDlg(AxisValue, AxisIndex)
End Sub
@@ -821,7 +857,7 @@ Public Class MachCommandMessagePanelVM
Next
End If
End If
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT, NCTypes.SIEMENS_SHARP7
Map.refLeftPanelVM.SetOPState(NewState)
End Select
'DbControllers.m_LogMachineController.Create(MachLog.CreateOPStateLog(newOpState))
@@ -835,7 +871,7 @@ Public Class MachCommandMessagePanelVM
Return
End If
Select Case CurrentMachine.NCType
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT, NCTypes.SIEMENS_SHARP7
Map.refLeftPanelVM.SetOPMode(NewState)
End Select
'DbControllers.m_LogMachineController.Create(MachLog.CreateOPStateLog(newOpState))
@@ -22,13 +22,14 @@ Public Class MyMachGroupVM
ElseIf m_bToBeProduced OrElse m_bSentToMachine Then
Return False
' se la macchina e' ferma
ElseIf IsNothing(Map.refLeftPanelVM.SelOPState) OrElse
(Map.refLeftPanelVM.SelOPState.Id = 0 OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.End OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.Stop OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.Unspecified) Then
ElseIf CurrentMachine.NCType <> NCTypes.SIEMENS_SHARP7 AndAlso
(IsNothing(Map.refLeftPanelVM.SelOPState) OrElse
(Map.refLeftPanelVM.SelOPState.Id = 0 OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.End OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.Stop OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.Unspecified)) Then
' verifico se c'e' un pezzo non finito
Dim ToBeRestartedPart As MyMachGroupVM = Map.refSupervisorMachGroupPanelVM.MachGroupVMList.FirstOrDefault(Function(x As MyMachGroupVM) x.nProduction_State = Global.EgtBEAMWALL.Core.ItemState.WIP And Not m_bToBeProduced)
Dim ToBeRestartedPart As MyMachGroupVM = Map.refSupervisorMachGroupPanelVM.MachGroupVMList.FirstOrDefault(Function(x As MyMachGroupVM) x.nProduction_State = Global.EgtBEAMWALL.Core.ItemState.WIP And Not x.m_bToBeProduced)
' se c'e', attivo solo il pezzo non finito
Return Not (Not IsNothing(ToBeRestartedPart) AndAlso Not ToBeRestartedPart Is Me)
Else
@@ -48,11 +49,12 @@ Public Class MyMachGroupVM
Case ItemState.WIP
If Not m_bToBeProduced AndAlso Not m_bSentToMachine Then
Return True
ElseIf IsNothing(Map.refLeftPanelVM.SelOPState) OrElse
(Map.refLeftPanelVM.SelOPState.Id = 0 OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.End OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.Stop OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.Unspecified) Then
ElseIf CurrentMachine.NCType <> NCTypes.SIEMENS_SHARP7 AndAlso
(IsNothing(Map.refLeftPanelVM.SelOPState) OrElse
(Map.refLeftPanelVM.SelOPState.Id = 0 OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.End OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.Stop OrElse
Map.refLeftPanelVM.SelOPState.Id = OPStates.Unspecified)) Then
Return True
Else
Return False
@@ -231,27 +233,45 @@ Public Class MyMachGroupVM
End If
' se progetto travi e lavorazione interrotta da reset
If Map.refSupervisorManagerVM.CurrProd.nType = BWType.BEAM AndAlso (bResetWhileCutting OrElse dtStartTime <> DateTime.MinValue) And Not Map.refLeftPanelVM.bRestart Then
' chiedo se riprendere o rifare la barra da zero
Dim bRedo As MessageBoxResult = MessageBox.Show(EgtMsg(62509), "", MessageBoxButton.YesNo, MessageBoxImage.Information)
Dim bRedo As MessageBoxResult = MessageBoxResult.No
If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 AndAlso Not IsNothing(Map.refMachManaging) Then
' leggo pinze aperte
Dim Open_ClampVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = OPEN_CLAMP)
Map.refMachManaging.Siemens_Sharp7.RefreshAllVars()
Map.refMachManaging.DebugMessage(1, "Leggo variabile pinze aperte " & Open_ClampVariable.sValue)
If Open_ClampVariable.sValue = 1 Then
Map.refMachManaging.DebugMessage(1, "Pinze aperte, ripartenza impossibile")
bRedo = MessageBoxResult.No
MessageBox.Show("Pinze aperte, ripartenza impossibile!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
Else
' chiedo se riprendere o rifare la barra da zero
bRedo = MessageBox.Show(EgtMsg(62509), "", MessageBoxButton.YesNo, MessageBoxImage.Information)
End If
Else
' chiedo se riprendere o rifare la barra da zero
bRedo = MessageBox.Show(EgtMsg(62509), "", MessageBoxButton.YesNo, MessageBoxImage.Information)
End If
Select Case bRedo
Case MessageBoxResult.Yes
' segno da rifare pezzi non completamente lavorati
For Each Part As PartVM In PartVMList
If Part.dtEndTime <> DateTime.MinValue Then
Part.bDO = False
Else
Part.SetDo(True)
End If
'Part.bDO = (Part.dtEndTime = DateTime.MinValue)
'Part.NotifyPropertyChanged(NameOf(Part.bRedo))
Next
' se ripresa, mostro lista feature e colonne Redo
Map.refLeftPanelVM.bRestart = True
' blocco produzione di tutti gli altri
MyMachGroupVM.UpdateProduceIsEnabledForAll()
' riabilito bottoni di comunicazione a fine invio programma
Map.refMachCommandMessagePanelVM.SetCommBtnIsEnabled(True)
Return
If CurrentMachine.NCType <> NCTypes.SIEMENS_SHARP7 Then
' segno da rifare pezzi non completamente lavorati
For Each Part As PartVM In PartVMList
If Part.dtEndTime <> DateTime.MinValue Then
Part.bDO = False
Else
Part.SetDo(True)
End If
'Part.bDO = (Part.dtEndTime = DateTime.MinValue)
'Part.NotifyPropertyChanged(NameOf(Part.bRedo))
Next
' se ripresa, mostro lista feature e colonne Redo
Map.refLeftPanelVM.bRestart = True
' blocco produzione di tutti gli altri
MyMachGroupVM.UpdateProduceIsEnabledForAll()
' riabilito bottoni di comunicazione a fine invio programma
Map.refMachCommandMessagePanelVM.SetCommBtnIsEnabled(True)
Return
End If
Case MessageBoxResult.No
' annullo stati dei pezzi gia' fatti
For Each Part In PartVMList
@@ -21,6 +21,7 @@ Module MachCommConst
Public Delegate Sub UpdateCallbackDlg(Param As String, Params As String)
Public Delegate Sub TPAAlarmCallbackDlg(ByVal AlarmOperation As Integer, ByVal AlarmType As Integer, ByVal AlarmMessage As String, ByVal AlarmCode As String, ByVal AlarmDateTime As String)
Public Delegate Sub NUMAlarmCallbackDlg(ByVal CncNumber As Integer, ByVal numberOfError As Integer, ByVal ErrorTyp As String, ByVal ErrorIndex As String, ByVal ErrorNumber As String, ByVal ErrorLine As String, ByVal ErrorMessage As String, ByVal ErrorAdditional As String)
Public Delegate Sub SiemensAlarmCallbackDlg(nIndex As Integer, AlarmOperation As AlarmOperation)
Public Delegate Sub AxisCoordinatesCallbackDlg(ByVal AxisValue As Double, ByVal AxisIndex As Integer)
Public Delegate Sub OpStateCallbackDlg(ByVal newOpState As Integer)
Public Delegate Sub OpModeCallbackDlg(ByVal newOpState As Integer)
@@ -32,6 +33,7 @@ Module MachCommConst
Friend m_UpdateCallbackDlg As UpdateCallbackDlg
Friend m_TPAAlarmCallbackDlg As TPAAlarmCallbackDlg
Friend m_NUMAlarmCallbackDlg As NUMAlarmCallbackDlg
Friend m_SiemensAlarmCallbackDlg As SiemensAlarmCallbackDlg
Friend m_AxisCoordinatesCallbackDlg As AxisCoordinatesCallbackDlg
Friend m_OpStateCallbackDlg As OpStateCallbackDlg
Friend m_OpModeCallbackDlg As OpModeCallbackDlg
@@ -7,6 +7,7 @@ Imports EgtWPFLib5
Imports System.IO
Imports EgtBEAMWALL.Core
Imports EgtBEAMWALL.Supervisor.CommVar
Imports System.Windows.Forms.VisualStyles
Public Class MachManaging
@@ -49,6 +50,11 @@ Public Class MachManaging
Return m_CN
End Get
End Property
Public ReadOnly Property Siemens_Sharp7 As SIEMENSSharp7Comm
Get
Return m_CN
End Get
End Property
Private Shared WithEvents m_CommandList As New ObservableCollection(Of ThreadCommand)
Public Shared ReadOnly Property CommandList As ObservableCollection(Of ThreadCommand)
@@ -97,7 +103,20 @@ Public Class MachManaging
End Get
End Property
' variabile che indica prima barra dopo start (Siemens)
Private m_bFirstRaw As Boolean = False
' variabile che indica se emettere ii messaggi di debug
Private m_Debug As Integer = 0
Public ReadOnly Property Debug As Integer
Get
Return m_Debug
End Get
End Property
Sub New()
' leggo variabile debug da ini
m_Debug = GetPrivateProfileInt(S_GENERAL, K_DEBUG, 0, CurrentMachine.sMachIniFile)
' imposto in Map
Map.SetRefMachManaging(Me)
AddHandler m_CommandList.CollectionChanged, AddressOf CommandList_CollectionChanged
@@ -241,7 +260,7 @@ Public Class MachManaging
' Threading.Thread.Sleep(300)
' End If
' End If
Case NCTypes.NUM_FLEXIUM, NCTypes.TPA, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT
Case NCTypes.NUM_FLEXIUM, NCTypes.TPA, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT, NCTypes.SIEMENS_SHARP7
' eseguo ciclo principale
Dim nReset_State As Integer
Dim nStart_State As Boolean
@@ -254,6 +273,9 @@ Public Class MachManaging
Dim nISO_Sent As Integer
Dim nRunning As Integer
Dim nCurrMachIndex As Integer
Dim nDataWrite As Integer
Dim nNCStatus As Integer
Dim nNCMode As Integer
Dim ResetVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RESET_STATE)
Dim StartVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = START_STATE)
Dim StopVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = STOP_STATE)
@@ -265,6 +287,11 @@ Public Class MachManaging
Dim ISOSentVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_SENT)
Dim RunningVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RUNNING)
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)
Dim NCStatusVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NC_STATUS)
Dim NCModeVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NC_MODE)
Select Case CurrentMachine.NCType
Case NCTypes.TPA
' leggo tutte le variabili
@@ -441,7 +468,73 @@ Public Class MachManaging
'EgtOutLog("Pre lettura posizioni")
Num_Axium_PCToolkit.ReadPosition()
'EgtOutLog("Post lettura messaggi")
Case NCTypes.SIEMENS_SHARP7
' leggo tutte le variabili
Map.refMachManaging.DebugMessage(1, "Leggo tutte le variabili")
Siemens_Sharp7.RefreshAllVars()
If Not IsNothing(ResetVariable.sValue) Then
Integer.TryParse(ResetVariable.sValue, nReset_State)
Else
nReset_State = 1
End If
If Not IsNothing(ProdVariable.sValue) Then
Integer.TryParse(ProdVariable.sValue, nP_Prod)
Else
nP_Prod = -1
End If
If Not IsNothing(MachGroupVariable.sValue) Then
Integer.TryParse(MachGroupVariable.sValue, nP_Machgroup)
Else
nP_Machgroup = -1
End If
If Not IsNothing(PartVariable.sValue) Then
Integer.TryParse(PartVariable.sValue, nP_Part)
Else
nP_Part = -1
End If
If Not IsNothing(StateVariable.sValue) Then
Integer.TryParse(StateVariable.sValue, nP_State)
Else
nP_State = -1
End If
If Not IsNothing(ISONumVariable.sValue) Then
Integer.TryParse(ISONumVariable.sValue, nISO_Num)
Else
nISO_Num = -1
End If
If Not IsNothing(RunningVariable.sValue) Then
Integer.TryParse(RunningVariable.sValue, nRunning)
Else
nRunning = -1
End If
If Not IsNothing(DataReadedVariable.sValue) Then
Integer.TryParse(DataReadedVariable.sValue, nDataWrite)
Else
nDataWrite = -1
End If
If Not IsNothing(NCStatusVariable.sValue) Then
Integer.TryParse(NCStatusVariable.sValue, nNCStatus)
Else
nNCStatus = -1
End If
If Not IsNothing(NCModeVariable.sValue) Then
Integer.TryParse(NCModeVariable.sValue, nNCMode)
Else
nNCMode = -1
End If
' leggo messaggi plc
Siemens_Sharp7.ReadPLCMessages()
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
Map.refMachManaging.DebugMessage(1, "Azzero lettura reset")
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
Map.refMachManaging.DebugMessage(1, "Azzero lettura dati")
DataReadedVariable.sValue = "0"
End If
' se NUM aggiorno stato della macchina
If CurrentMachine.NCType = NCTypes.NUM_FLEXIUM Then
Dim OpState As OPStates
@@ -469,6 +562,41 @@ Public Class MachManaging
If IsNothing(Map.refLeftPanelVM.SelOPState) OrElse OpState <> Map.refLeftPanelVM.SelOPState.Id Then
m_OpStateCallbackDlg(OpState)
End If
ElseIf CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then
Dim OpState As OPStates
If nNCStatus > 0 Then
Select Case nNCStatus
Case 1
OpState = OPStates.End
Case 2
OpState = OPStates.Stop
Case 3
OpState = OPStates.Start
Case Else
OpState = OPStates.Unspecified
End Select
End If
If IsNothing(Map.refLeftPanelVM.SelOPState) OrElse OpState <> Map.refLeftPanelVM.SelOPState.Id Then
Map.refMachManaging.DebugMessage(1, "Imposto stato CN: " & OpState)
m_OpStateCallbackDlg(OpState)
End If
Dim OpMode As OPModes
If nNCMode > 0 Then
Select Case nNCMode
Case 1
OpMode = OPModes.Manual
Case 2
OpMode = OPModes.Auto
Case 3
OpMode = OPModes.Mdi
Case 4 ' Reference Point
OpMode = OPModes.Home
End Select
End If
If IsNothing(Map.refLeftPanelVM.SelOPMode) OrElse OpMode <> Map.refLeftPanelVM.SelOPMode.Id Then
Map.refMachManaging.DebugMessage(1, "Imposto modo CN: " & OpMode)
m_OpModeCallbackDlg(OpMode)
End If
End If
' se TPA e non ancora fatto, preparo variabili barra successiva
If CurrentMachine.NCType = NCTypes.TPA AndAlso CurrentMachine.Flow = FlowTypes.CONTINUOUS AndAlso m_NextBarId = 0 Then
@@ -482,19 +610,31 @@ Public Class MachManaging
nISO_Sent = 1) OrElse
(CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT AndAlso
Not Num_Axium_PCToolkit.bIsTransferActive AndAlso
nISO_Sent = 1) Then
nISO_Sent = 1) OrElse
(CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 AndAlso
(nISO_Num = 0 OrElse
nISO_Num = nRunning)) Then
' verifico se c'e' un programma da lanciare
Map.refMachManaging.DebugMessage(1, "Entro in SendNextProgram")
SendNextProgram()
End If
' verifico se scattato stato reset
If nReset_State <> 0 Then
Map.refMachManaging.DebugMessage(1, "Scattato Reset")
' 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
Map.refMachManaging.DebugMessage(1, "Resetto programma corrente")
ISONumVariable.sValue = "0"
m_bFirstRaw = True
Else
' resetto variabili P
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)
@@ -504,7 +644,12 @@ Public Class MachManaging
RemoveAllProgram() ' rimuovo programma default per pending
End If
' azzero variabile reset
ResetVariable.sValue = "0"
If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then
Map.refMachManaging.DebugMessage(1, "Confermo lettura reset")
ResetReadedVariable.sValue = "1"
Else
ResetVariable.sValue = "0"
End If
'Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.WriteVar),
' RWVariableManager.GetReadVarFromName(RESET_STATE).sAddress, "0")
' resetto prossima barra e variabili V
@@ -528,10 +673,17 @@ 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
Map.refMachManaging.DebugMessage(1, "Leggo dati start")
Dim dtStart As DateTime = DateTime.Now()
' recupero gruppo di lavorazione del pezzo
Dim MachGroup As MyMachGroupVM = Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.FirstOrDefault(Function(x) x.Id = nP_Machgroup)
@@ -573,6 +725,9 @@ Public Class MachManaging
Tpa.RWVariableManager.WriteVarByName(P_STATE, 0)
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT
StateVariable.sValue = "0"
Case NCTypes.SIEMENS_SHARP7
Map.refMachManaging.DebugMessage(1, "Confermo lettura dati start")
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
@@ -590,9 +745,11 @@ Public Class MachManaging
End If
' flag di aggiornamento log macchina
Map.refMachineLogPageVM.UpdateMachineLogList(False)
DebugMessage(1, "Fine lettura dati start")
' attesa per essere sicuro che abbia scritto e riletto variabili
Threading.Thread.Sleep(300)
ElseIf nP_State = PartState.END_ Then
DebugMessage(1, "Leggo dati end")
Dim dtEnd As DateTime = DateTime.Now()
' recupero gruppo di lavorazione del pezzo
Dim MachGroup As MyMachGroupVM = Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.FirstOrDefault(Function(x) x.Id = nP_Machgroup)
@@ -652,10 +809,16 @@ 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
DebugMessage(1, "Confermo lettura dati end")
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
@@ -683,7 +846,11 @@ Public Class MachManaging
End If
Else
' azzero variabile per far ripartire macchina
StateVariable.sValue = "0"
If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then
DataReadedVariable.sValue = "1"
Else
StateVariable.sValue = "0"
End If
End If
' aggiorno utilizzo barra da magazzino
If GetMainPrivateProfileInt(S_WAREHOUSE, K_NETWAREHOUSE, 0) = 1 AndAlso MachGroup.PartVMList(0).nPartId = nP_Part AndAlso MachGroup.nProduction_State <> ItemState.Scrapped Then
@@ -717,6 +884,7 @@ Public Class MachManaging
End If
' flag di aggiornamento log macchina
Map.refMachineLogPageVM.UpdateMachineLogList(False)
DebugMessage(1, "Fine lettura dati end")
' attesa per essere sicuro che abbia scritto e riletto variabili
Threading.Thread.Sleep(300)
End If
@@ -766,25 +934,28 @@ Public Class MachManaging
If (CurrentMachine.NCType = NCTypes.TPA AndAlso Not m_bStartPending AndAlso Tpa.opState = MachineOperatingState.Pending) OrElse
(CurrentMachine.NCType = NCTypes.NUM_FLEXIUM AndAlso Not Num_Flexium.bIsTransferActive) OrElse
(CurrentMachine.NCType = NCTypes.NUM_AXIUM_APSERVER AndAlso Not Num_Axium_APServer.bIsTransferActive) OrElse
(CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT AndAlso Not Num_Axium_PCToolkit.bIsTransferActive) Then ' Or Tpa.opState = MachineOperatingState.Start) Then
(CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT AndAlso Not Num_Axium_PCToolkit.bIsTransferActive) OrElse
CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then ' Or Tpa.opState = MachineOperatingState.Start) Then
' verifico se c'e' un programma da lanciare
If Not IsNothing(Map.refProjectVM.SupervisorMachGroupPanelVM) Then
' EgtOutLog("Start " & DateTime.Now())
Dim bMachGroupNotReady As Boolean = False
SyncLock m_Lock_SendProgram
For Each MyMachGroup As MyMachGroupVM In Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList
DebugMessage(1, "Ciclo alla ricerca di un programma da mandare")
' EgtOutLog("Ciclo su name: " & MyMachGroup.Name & " id: " & MyMachGroup.Id)
If Not MyMachGroup.bSentToMachine AndAlso (MyMachGroup.dtStartTime = DateTime.MinValue OrElse
If Not MyMachGroup.bSentToMachine AndAlso (If(CurrentMachine.NCType <> NCTypes.SIEMENS_SHARP7, MyMachGroup.dtStartTime = DateTime.MinValue, MyMachGroup.dtEndTime = DateTime.MinValue) OrElse
(Map.refSupervisorManagerVM.CurrProd.nType = BWType.WALL AndAlso MyMachGroup.bResetWhileCutting)) Then
' EgtOutLog(MyMachGroup.Name & " id: " & MyMachGroup.Id & " è da fare")
' verifico se ricalcolo finito
If MyMachGroup.bReadyForMachining AndAlso If(CurrentMachine.NCType = NCTypes.NUM_FLEXIUM Or CurrentMachine.NCType = NCTypes.NUM_AXIUM_APSERVER OrElse CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT, Not MyMachGroup.bSendingToMachine, True) Then
' EgtOutLog(MyMachGroup.Name & " id: " & MyMachGroup.Id & " pronto per essere lavorato")
' lo lancio
bSent = SendProgram(MyMachGroup.CnFilePath(), MyMachGroup.Name)
DebugMessage(1, "Eseguo SendProgram")
bSent = SendProgram(MyMachGroup.CnFilePath(), MyMachGroup.Name, MyMachGroup)
' EgtOutLog(MyMachGroup.Name & " id: " & MyMachGroup.Id & " mandato " & DateTime.Now() & " " & MyMachGroup.Name & " " & bSent.ToString())
Select Case CurrentMachine.NCType
Case NCTypes.TPA
Case NCTypes.TPA, NCTypes.SIEMENS_SHARP7
MyMachGroup.SetSentToMachine(bSent)
Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT
MyMachGroup.SetSendingToMachine(bSent)
@@ -801,6 +972,14 @@ Public Class MachManaging
End If
Next
End SyncLock
If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 AndAlso Not Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.Any(Function(x As MyMachGroupVM) x.nProduction_State < ItemState.WIP And x.bReadyForMachining) Then
Dim ISONumVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_NUM)
Dim nISONum As Integer = 0
If Not Integer.TryParse(ISONumVariable.sValue, nISONum) Or nISONum <> 0 Then
DebugMessage(1, "Resetto programma da inviare")
ISONumVariable.sValue = 0
End If
End If
If bMachGroupNotReady Then Return False
' EgtOutLog("End " & DateTime.Now())
End If
@@ -918,6 +1097,24 @@ Public Class MachManaging
m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!")
Return
End Try
Case NCTypes.SIEMENS_SHARP7
Try
m_CN = New SIEMENSSharp7Comm(Me)
If Siemens_Sharp7.InitConnection() Then
m_bConnected = True
' imposto stato manuale
Dim ManualMode As OPState = Map.refLeftPanelVM.OPModeList.FirstOrDefault(Function(x) x.Id = OPModes.Manual)
Map.refLeftPanelVM.SetOPMode(ManualMode)
m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.OK, ResultTypes.EXECUTED, "")
Else
m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!")
Return
End If
' creo classe di gestione variabili
Catch ex As Exception
m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!")
Return
End Try
End Select
End Sub
@@ -950,6 +1147,13 @@ Public Class MachManaging
' chiudo classe Num_Flexium
Me.OnDispose()
'Num_Flexium.OnDispose()
Case NCTypes.SIEMENS_SHARP7
m_bConnected = False
Siemens_Sharp7.CloseConnection()
m_ResultCallbackDlg(CommandTypes.DISCONNECT, CommandStates.OK, ResultTypes.EXECUTED, "")
' chiudo classe Num_Flexium
Me.OnDispose()
'Num_Flexium.OnDispose()
End Select
' termino thread di comunicazione
MachineCommThread.StopThread()
@@ -1065,7 +1269,7 @@ Public Class MachManaging
End Select
End Sub
Public Function SendProgram(ProgramPath As String, ProgramId As String) As Boolean
Public Function SendProgram(ProgramPath As String, ProgramId As String, Optional MyMachGroup As MyMachGroupVM = Nothing) As Boolean
Select Case CurrentMachine.NCType
Case NCTypes.TPA
If Tpa.opState = MachineOperatingState.Pending Then
@@ -1096,6 +1300,27 @@ Public Class MachManaging
Num_Axium_PCToolkit.FileDownload(nFileType * 10, ProgramPath)
End If
Return True
Case NCTypes.SIEMENS_SHARP7
' EgtOutLog("Pre Download")
Dim nFileType As Integer = 0
If Integer.TryParse(ProgramId, nFileType) AndAlso nFileType > 0 Then
Dim sDestDir As String = ""
GetPrivateProfileString(S_GENERAL, K_ISOFILEDIR, "c:/Saomad/ISO", sDestDir, CurrentMachine.sMachIniFile)
DebugMessage(1, "Copio programma")
File.Copy(ProgramPath, sDestDir & "/" & nFileType & ".mpf", True)
' imposto numero programma scritto
Dim ISONumVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_NUM)
DebugMessage(1, "Imposto programma inviato: " & nFileType)
ISONumVariable.sValue = nFileType
' se primo dopo start
If m_bFirstRaw Then
m_bFirstRaw = False
DebugMessage(1, "Primo grezzo")
' annullo step di ripartenza
Map.refMachManaging.Siemens_Sharp7.ResetStep(Not (MyMachGroup.dtStartTime <> DateTime.MinValue OrElse MyMachGroup.nProduction_State = ItemState.WIP))
End If
End If
Return True
End Select
Return False
End Function
@@ -1188,6 +1413,13 @@ Public Class MachManaging
Case CommVar.Types.CN
Num_Axium_PCToolkit.WriteNCVariables(Address, Value)
End Select
Case NCTypes.SIEMENS_SHARP7
Select Case Type
Case CommVar.Types.PLC
Siemens_Sharp7.WriteVariable(Address, Value)
'Case CommVar.Types.CN
' Num_Axium_PCToolkit.WriteNCVariables(Address, Value)
End Select
End Select
End Sub
@@ -1203,6 +1435,8 @@ Public Class MachManaging
Return NUMAxiumComm.InitVar(NewVar)
Case NCTypes.NUM_AXIUM_PCTOOLKIT
Return NUMAxiumPcToolkitComm.InitVar(NewVar)
Case NCTypes.SIEMENS_SHARP7
Return SIEMENSSharp7Comm.InitVar(NewVar)
End Select
Return Nothing
End Function
@@ -1295,4 +1529,14 @@ Public Class MachManaging
End Select
End Sub
#Region "Debug"
Friend Sub DebugMessage(nLevel As Integer, sMessage As String)
If m_Debug >= nLevel Then
EgtOutLog(sMessage)
End If
End Sub
#End Region ' Debug
End Class
@@ -21,7 +21,7 @@ Class MachineCommThread
Private Shared sResetVarName As String = "0.FUNM.E80048"
Public Shared Sub MachManagingThreadFunction(ResultCallbackDlg As ResultCallbackDlg, CloseCallbackDlg As CloseCallbackDlg, UpdateCallbackDlg As UpdateCallbackDlg,
TPAAlarmCallbackDlg As TPAAlarmCallbackDlg, NUMAlarmCallbackDlg As NUMAlarmCallbackDlg, AxisCoordinatesCallbackDlg As AxisCoordinatesCallbackDlg,
TPAAlarmCallbackDlg As TPAAlarmCallbackDlg, NUMAlarmCallbackDlg As NUMAlarmCallbackDlg, SiemensAlarmCallbackDlg As SiemensAlarmCallbackDlg, AxisCoordinatesCallbackDlg As AxisCoordinatesCallbackDlg,
OpStateCallbackDlg As OpStateCallbackDlg, OpModeCallbackDlg As OpModeCallbackDlg, ChannelCallbackDlg As ChannelCallbackDlg,
ReadVarCallbackDlg As ReadVarCallbackDlg)
' inizializzo callback
@@ -30,6 +30,7 @@ Class MachineCommThread
m_UpdateCallbackDlg = UpdateCallbackDlg
m_TPAAlarmCallbackDlg = TPAAlarmCallbackDlg
m_NUMAlarmCallbackDlg = NUMAlarmCallbackDlg
m_SiemensAlarmCallbackDlg = SiemensAlarmCallbackDlg
m_AxisCoordinatesCallbackDlg = AxisCoordinatesCallbackDlg
m_OpStateCallbackDlg = OpStateCallbackDlg
m_OpModeCallbackDlg = OpModeCallbackDlg
@@ -176,7 +176,7 @@ Public Class MainMenuVM
#Region "METHODS"
Friend Sub SetInputOutputVisibility()
If CurrentMachine.NCType = NCTypes.TPA Then
If CurrentMachine.NCType = NCTypes.TPA OrElse CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then
m_Inputs_Visibility = Visibility.Collapsed
m_Outputs_Visibility = Visibility.Collapsed
End If
@@ -240,7 +240,7 @@ Public Class MainWindowVM
Public Sub CloseApplication()
' se macchina sta funzionando
If Not IsNothing(Map.refMachManaging) AndAlso Map.refMachManaging.bConnected AndAlso
(Map.refLeftPanelVM.SelOPState.Id <> OPStates.End AndAlso Map.refLeftPanelVM.SelOPState.Id <> OPStates.Unspecified) Then
(If(Not IsNothing(Map.refLeftPanelVM.SelOPState), Map.refLeftPanelVM.SelOPState.Id <> OPStates.End AndAlso Map.refLeftPanelVM.SelOPState.Id <> OPStates.Unspecified, True)) Then
MessageBox.Show("Impossible closing software while machine is working. If you want to close, first press reset and stop the machine!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
@@ -268,6 +268,8 @@ Public Module CurrentMachine
Map.refLeftPanelVM.LoadOPModes()
' Imposto visibilità variabili E80000
Map.refLeftPanelVM.SetE80000Visibility()
' Imposto visibilita' assi
Map.refLeftPanelVM.SetAxisVisibility()
End Sub
#End Region 'Init