diff --git a/NcComm/CNCommunication.vb b/NcComm/CNCommunication.vb index ecab6a2..5afa7d4 100644 --- a/NcComm/CNCommunication.vb +++ b/NcComm/CNCommunication.vb @@ -418,8 +418,9 @@ Public Class CNCommunication EgtOutLog("Error starting NC communication : " & ex.Message) End Try - '' Per forzare la lettura delle variabili siemens di configurazione - 'm_nNCType = 3 + '' !!!!!!!!!!!!! Per forzare la lettura delle variabili siemens di configurazione !!!!!!!!!!!!! + 'm_nNCType = 3 + '' !!!!!!!!!!!!! Per forzare la lettura delle variabili siemens di configurazione !!!!!!!!!!!!! Select Case m_nNCType Case 0 'Debug @@ -445,12 +446,13 @@ Public Class CNCommunication Try m_MachineStatus.MachineStatusGrid.Background = Application.Current.FindResource("OmagCut_DarkGray") Dim sArg As String = "-start """ & m_sCNSiemensPath & """" -<<<<<<< HEAD + + ' !!!!!!!!!!!!!! FORZO LA SIMULAZIONE DELLA LETTURA DELLE VARIBILI E SIEMENS !!!!!!!!!!!!!! EgtOutLog("ProcessStart : " & """" & m_sCNSiemensHMIPath & """" & " " & sArg) KillSimensCom(m_sCNSiemensHMIPath) -======= ->>>>>>> develop Process.Start(m_sCNSiemensHMIPath, sArg) + ' !!!!!!!!!!!!!! FORZO LA SIMULAZIONE DELLA LETTURA DELLE VARIBILI E SIEMENS !!!!!!!!!!!!!! + EgtOutLog("ProcessStart : " & """" & m_sCNSiemensHMIPath & """" & " " & sArg) m_CN.m_IsSiemensOne = GetPrivateProfileInt(S_NCSIEMENS, K_ISSIEMENSONE, 0, m_MainWindow.GetMachIniFile()) > 0 m_CN.m_IsActiveModeSubscription = GetPrivateProfileInt(S_NCSIEMENS, K_ISACTIVEMODESUBSCR, 0, m_MainWindow.GetMachIniFile()) > 0 @@ -476,7 +478,9 @@ Public Class CNCommunication Dim nIndexArrayLong As Integer = 0 Dim nIndexArrayDoub As Integer = 0 Dim nIndexArrayStr As Integer = 0 - ' Creo un vettore che mi permetta di risalire a cose contiene ogni vettore FLAG (di tipo Enum) + ' lista che associa Indice del vettore al nome (per associazioni Bit a Bit) + Dim ListIndexToVar As New List(Of IndexArrayToBit) + ' Creo un vettore che mi permetta di risalire a cosa contiene ogni vettore FLAG (di tipo Enum) For ItemIndex As Integer = 0 To m_CN.m_szCnDataVar.Count - 1 ' escludo i Flag 'Comm' e 'Refresh' If ItemIndex = CnData.Comm Or ItemIndex = CnData.Refresh Then @@ -528,6 +532,35 @@ Public Class CNCommunication m_CN.DVariables_Read_Subscription(sItem(1), nVarType, nIndexArrayStr) ListReferenceIndex.Add(New RefereceFlagSimens(nIndexArrayStr, ItemIndex, nVarType)) nIndexArrayStr += 1 + Case 5 + If nIndexArrayInt > 14 Then + Continue For + End If + ' verifico se devo riempire un vettore con bit + Dim sSubItem As String() = sItem(1).Split("."c) + ' //My. name. Is Bond._James Bond! + Dim sVarName = String.Join(".", sSubItem.Take(sSubItem.Length - 1)) ' //My. name. Is Bond + Dim sIndexBit = sSubItem.Last() ' //_James Bond! + If sSubItem.Count > 1 And IsNumeric(sIndexBit) Then + Dim bFound As Boolean = False + Dim nIndexArrayInt_1 As Integer = nIndexArrayInt + For Each VarSiemens As IndexArrayToBit In ListIndexToVar + If VarSiemens.sNameVar.Trim = sVarName.Trim Then + nIndexArrayInt_1 = VarSiemens.nIndex + bFound = True + Exit For + End If + Next + nVarType = VarType.TInteger + m_CN.DVariables_Read_Subscription(sVarName, nVarType, nIndexArrayInt_1) + ListReferenceIndex.Add(New RefereceFlagSimens(nIndexArrayInt_1, ItemIndex, nVarType, sIndexBit)) + If Not bFound Then + nIndexArrayInt += 1 + ListIndexToVar.Add(New IndexArrayToBit(nIndexArrayInt_1, sVarName.Trim)) + End If + Else + EgtOutLog(" ATTENZIONE: in [NcData] '" & m_CN.m_szCnDataVar(ItemIndex) & "' non è inidicato il bit associato") + End If Case Else If nIndexArrayInt > 14 Then Continue For @@ -538,6 +571,8 @@ Public Class CNCommunication nIndexArrayInt += 1 End Select End If + Else + EgtOutLog(" ATTENZIONE: in [NcData] '" & m_CN.m_szCnDataVar(ItemIndex) & "' non è indicato il tipo (0→Bool,1→Int,2→Long,3→Double,4→String,5→Bit)") End If End If Next @@ -545,6 +580,7 @@ Public Class CNCommunication ' Recupero il perocorso delle variabili PLC GetPrivateProfileString(S_NCSIEMENS, K_DBVARPATH, "", m_CN.m_DbVarPath, m_MainWindow.GetMachIniFile) + ElseIf m_CN.m_IsActiveModeSubscription Then m_CN.DVariables_Read_Subscription(m_CN.m_szCnDataVar(CN_generico.CnData.BlowState), VarType.TInteger, 3) End If @@ -1072,6 +1108,65 @@ Public Class CNCommunication 'Laser = 16384 End Enum +#Region "MASCHERA per conttrollo Bit a Bit" + + Public Enum Mask As Integer + bit_Err = -1 + bit_0 = &H1 ' 1 + bit_1 = &H2 ' 2 + bit_2 = &H4 ' 4 + bit_3 = &H8 ' 8 + bit_4 = &H10 ' 16 + bit_5 = &H20 ' 32 + bit_6 = &H40 ' 64 + bit_7 = &H80 ' 128 + bit_8 = &H100 ' 256 + bit_9 = &H200 ' 512 + bit_10 = &H400 ' 1024 + bit_11 = &H800 ' 2048 + bit_12 = &H1000 ' 4096 + bit_13 = &H2000 ' 8192 + bit_14 = &H4000 ' 16384 + End Enum + + Public Function GetMaskByBit(IndexBit As Integer) As Mask + Dim Bit_ As Mask = Mask.bit_Err + Select Case IndexBit + Case 0 + Bit_ = Mask.bit_0 + Case 1 + Bit_ = Mask.bit_1 + Case 2 + Bit_ = Mask.bit_2 + Case 3 + Bit_ = Mask.bit_3 + Case 4 + Bit_ = Mask.bit_4 + Case 5 + Bit_ = Mask.bit_5 + Case 6 + Bit_ = Mask.bit_6 + Case 7 + Bit_ = Mask.bit_7 + Case 8 + Bit_ = Mask.bit_8 + Case 9 + Bit_ = Mask.bit_9 + Case 10 + Bit_ = Mask.bit_10 + Case 11 + Bit_ = Mask.bit_11 + Case 12 + Bit_ = Mask.bit_12 + Case 13 + Bit_ = Mask.bit_13 + Case 14 + Bit_ = Mask.bit_14 + End Select + Return Bit_ + End Function +#End Region ' Maschera per controllo Bit a Bit + Public Function IsSetAll(value As Integer, flag As Integer) As Boolean ' somma Bit a Bit Return ((value And flag) = flag) @@ -1138,7 +1233,7 @@ Public Class CNCommunication ' m_CN.bLimitZState = IsSetAll(nVarValue, ControlStates.LimitZ) ' m_CN.b5AxesState = IsSetAll(nVarValue, ControlStates.Axis5) - 'nVarValue = m_CN.n_data(1) + ' nVarValue = m_CN.n_data(1) ''EgtOutLog("Variabile PLC vacuum addr: " & m_CN.m_szCnDataVar(CN_generico.CnData.LaserTrac) & " value: " & nVarValue) 'm_CN.bVacuumUp = IsSetAll(nVarValue, VacuumStates.VacuumUp) 'm_CN.bVacuumDown = IsSetAll(nVarValue, VacuumStates.VacuumDown) @@ -1178,8 +1273,9 @@ Public Class CNCommunication Dim nType As Integer = ListReferenceIndex(IndxLst).TypeArray Dim nFlag As Integer = ListReferenceIndex(IndxLst).FlagIndex Dim nIndex As Integer = ListReferenceIndex(IndxLst).SiemnesArrayIndex + Dim nIndexBit As Integer = ListReferenceIndex(IndxLst).IndexBit Dim b_temp As Boolean = False - Dim n_temp As Boolean = 0 + Dim n_temp As Integer = 0 Dim l_temp As Long = 0.0 Dim d_temp As Double = 0.0 ' leggo il valore caricato @@ -1188,6 +1284,8 @@ Public Class CNCommunication b_temp = m_CN.b_data(nIndex) Case VarType.TInteger n_temp = m_CN.n_data(nIndex) + ' VENTOSE: lettura dato da intero Bit a Bit (ver_2.6g2), ritorno un Boolean + b_temp = ReadBit(nIndexBit, n_temp) Case VarType.TLong l_temp = m_CN.l_data(nIndex) Case VarType.TDouble @@ -1399,6 +1497,14 @@ Public Class CNCommunication End Sub + Private Function ReadBit(IndexBit As Integer, Val As Integer) As Boolean + If IndexBit < 0 Then Return False + Dim _mask = GetMaskByBit(IndexBit) + If _mask = Mask.bit_Err Then Return False + If (Val And _mask) = 0 Then Return False + Return True + End Function + Friend Function SetProgramMainOrSub(bMain As Boolean) As Boolean Return m_CN.SetProgramMainOrSub(bMain) End Function @@ -1616,6 +1722,8 @@ Public Class RefereceFlagSimens Private m_SiemnesArrayIndex As Integer Private m_FlagIndex As Integer Private m_TypeArray As Integer + ' Opzionale + Private m_IndexBit As Integer = -1 Public Property SiemnesArrayIndex As Integer Get @@ -1644,10 +1752,49 @@ Public Class RefereceFlagSimens End Set End Property + Public Property IndexBit As String + Get + Return m_IndexBit + End Get + Set(value As String) + m_IndexBit = value + End Set + End Property + Sub New(IndArray As Integer, Flag As Integer, nType As Integer) m_SiemnesArrayIndex = IndArray m_FlagIndex = Flag m_TypeArray = nType End Sub + Sub New(IndArray As Integer, Flag As Integer, nType As Integer, nIndBit As Integer) + m_SiemnesArrayIndex = IndArray + m_FlagIndex = Flag + m_TypeArray = nType + m_IndexBit = nIndBit + End Sub + +End Class + +Public Class IndexArrayToBit + + Private m_nIndex As Integer = 0 + Public ReadOnly Property nIndex As Integer + Get + Return m_nIndex + End Get + End Property + + Private m_sNameVar As String = "" + Public ReadOnly Property sNameVar As String + Get + Return m_sNameVar + End Get + End Property + + Sub New(Index As Integer, NameVar As String) + m_nIndex = Index + m_sNameVar = NameVar + End Sub + End Class \ No newline at end of file diff --git a/NcComm/CN_Siemens.vb b/NcComm/CN_Siemens.vb index 8ec6793..df1dd1a 100644 --- a/NcComm/CN_Siemens.vb +++ b/NcComm/CN_Siemens.vb @@ -228,7 +228,7 @@ Public Class CN_Siemens Public Overrides Sub DVariables_Read_Subscription(VarAddr As String, ParType As Short, Index As Integer) ' Ricevo il percorso della varibile, il tipo Dim n_ret As Short = Read_subscription(VarAddr, ParType, Index) - 'EgtOutLog("CN SIEMENS Dopo lettura abbonamento") + EgtOutLog(" ABBONAMENTO (Esito: " & n_ret.ToString & ") -> Address: " & VarAddr & ", Type: " & ParType.ToString & ", Index: " & Index.ToString) End Sub '