diff --git a/CNCommunication.vb b/CNCommunication.vb index 45f2d2d..cd1e27e 100644 --- a/CNCommunication.vb +++ b/CNCommunication.vb @@ -78,7 +78,7 @@ Public Class CNCommunication #End If EgtOutLog("NcLink=" & m_MainWindow.m_bNCLink.ToString & " type=" & m_nNCType) - ' Se CNSiemens leggo dati programma intermedio di comunicazione + ' Se CN Siemens leggo dati programma intermedio di comunicazione If m_nNCType = 3 Then Dim sExeName As String = String.Empty GetPrivateProfileString(S_NCSIEMENS, K_COMM_NAME, "", sExeName, m_MainWindow.m_CurrentMachine.sMachIniFile) diff --git a/M_MMFiles.vb b/M_MMFiles.vb index 79d2f08..7eb456a 100644 --- a/M_MMFiles.vb +++ b/M_MMFiles.vb @@ -213,9 +213,7 @@ Module M_MMFiles MapSize, _ FullMapName) - If (hMapFile.IsInvalid) Then - Throw New Win32Exception - End If + If hMapFile.IsInvalid Then Throw New Win32Exception ' Create the file mapping object2 . hMapFile2 = NativeMethod.CreateFileMapping( _ @@ -226,9 +224,7 @@ Module M_MMFiles MapSize, _ FullMapName2) - If (hMapFile2.IsInvalid) Then - Throw New Win32Exception - End If + If hMapFile2.IsInvalid Then Throw New Win32Exception ' Map a view of the file mapping into the address space of the current process. @@ -239,9 +235,7 @@ Module M_MMFiles ViewOffset, _ ViewSize) - If (pView = IntPtr.Zero) Then - Throw New Win32Exception - End If + If pView = IntPtr.Zero Then Throw New Win32Exception ' Map a view of the file mapping into the address space of the current process. @@ -252,9 +246,7 @@ Module M_MMFiles ViewOffset, _ ViewSize) - If (pView = IntPtr.Zero) Then - Throw New Win32Exception - End If + If pView2 = IntPtr.Zero Then Throw New Win32Exception Catch ex As Exception EgtOutLog("Errore nell'init dell'm_mmFiles") @@ -482,6 +474,7 @@ Module M_MMFiles Try ' Attesa eventuale busy iniziale + Dim nCount As Integer = 0 Dim bEnd As Boolean = False While Not bEnd If SiemensRet.b_busy Then @@ -489,6 +482,9 @@ Module M_MMFiles Else bEnd = True End If + ' controllo massimo numero di cicli + nCount += 1 + If nCount > 40 Then Throw New Win32Exception("Timeout") End While ' Alzo il comando @@ -498,6 +494,7 @@ Module M_MMFiles ' Ciclo di attesa della risposta Dim nState As State = State.Command_on + nCount = 0 bEnd = False While Not bEnd Select Case nState @@ -512,22 +509,25 @@ Module M_MMFiles ' scrivo !!!!! Marshal.StructureToPtr(SiemensSend, pView, False) nState = State.Command_off - Case State.Command_off - If Not SiemensRet.b_busy Then ' abbassato il comando attendo il busy basso - nState = State.Busy_Off - Else + Case State.Command_off ' abbassato il comando attendo il busy basso + If SiemensRet.b_busy Then System.Threading.Thread.Sleep(50) + Else + nState = State.Busy_Off End If Case State.Busy_Off bEnd = True End Select - + ' controllo massimo numero di cicli + nCount += 1 + If nCount > 400 Then Throw New Win32Exception("Timeout") End While 'EgtOutLog("Eseguito comando :" & SiemensSend.n_Command.ToString()) Catch ex As Exception - EgtOutLog("Errore nell'esecuzione di un comando :" & ex.ToString()) + SiemensRet.n_result = 99 + EgtOutLog("Errore nell'esecuzione di un comando : " & ex.Message) End Try End Sub diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb index 20dd8a6..88c404c 100644 --- a/My Project/AssemblyInfo.vb +++ b/My Project/AssemblyInfo.vb @@ -22,7 +22,7 @@ Imports System.Windows #End If - + @@ -49,7 +49,7 @@ Imports System.Windows 'The following GUID is for the ID of the typelib if this project is exposed to COM - + ' Version information for an assembly consists of the following four values: ' @@ -62,5 +62,5 @@ Imports System.Windows ' by using the '*' as shown below: ' - - + +