Compare commits

...

21 Commits

Author SHA1 Message Date
Nicola Pievani 92196b99e6 Gestione ventosa asse W e gestione foto per tutte le tavole 2025-07-28 17:13:20 +02:00
Nicola Pievani a3d40c5bc1 Gestione CameraHq (1 tavola e 2 camere) 2025-07-23 12:15:39 +02:00
Nicola Pievani e25bbc9216 Gestione BackImage da Process 2025-07-18 15:49:27 +02:00
Nicola Pievani a2b561e944 Inizio gestione BackImage 2025-07-15 11:03:05 +02:00
Demetrio Cassarino 5bc49d30b9 -aggiornato messaggi di errore su camera 2025-07-14 14:49:12 +02:00
Demetrio Cassarino c30ecc0574 -aggiunto messaggi di errore su fotocamera 2025-07-14 14:38:23 +02:00
Demetrio Cassarino f7e9401e15 Merge branch 'Features/Manage_Process_Camera' of https://gitlab.steamware.net/egalware-cadcam/interfacce/OmagCUT into Features/Manage_Process_Camera 2025-07-14 14:28:56 +02:00
Demetrio Cassarino 9a48c3beb3 -aggiunto controllo su processo vuoto 2025-07-14 14:28:52 +02:00
Nicola Pievani 5032ba4b0b Correzione posizionamento scena nel programma 2025-07-14 09:51:12 +02:00
Demetrio Cassarino 8724afe392 -sistemato currentprojectpage 2025-07-14 09:13:33 +02:00
Nicola Pievani 4fc97ddf4f Merge commit '8443739a70a1b015e2c506e936f56210ae0eb51d' into Features/Manage_Process_Camera 2025-07-14 09:02:41 +02:00
Demetrio Cassarino fb4cb7d26b -riportato m_nCameraCount al numero di tavole corrente 2025-07-02 16:44:37 +02:00
Demetrio Cassarino d0672157a8 -rinumerati processo a partire da 1 2025-06-30 15:56:27 +02:00
Demetrio Cassarino 0195d19884 -aggiunto text su progressbar 2025-06-24 10:26:25 +02:00
Demetrio Cassarino c24bb386fc -gestione al momento 1 solo processo 2025-06-20 13:04:44 +02:00
Nicola Pievani ba0987ba3e -gestione progressbar e caricamento foto 2025-06-18 18:40:05 +02:00
Demetrio Cassarino ac809502ed -migliorata gestione camera 2025-06-18 16:57:20 +02:00
Demetrio Cassarino 69b3db94f5 Merge branch 'Features/Manage_Process_Camera' of https://gitlab.steamware.net/egalware-cadcam/interfacce/OmagCUT into Features/Manage_Process_Camera 2025-06-17 10:52:39 +02:00
Demetrio Cassarino 67da8aa6ed -gestito apertura più processi cameramanager 2025-06-17 10:52:34 +02:00
Nicola Pievani 451dbed3b3 Gestione seleziona 3 tavole 2025-06-16 12:18:19 +02:00
Demetrio Cassarino 5ab9204cda -inserito avvio nuovo processo non funzionante 2025-06-10 09:31:50 +02:00
9 changed files with 700 additions and 352 deletions
+5
View File
@@ -1,4 +1,9 @@
Imports EgtUILib
Imports EgtWPFLib
Imports System.Reflection
Imports System.Globalization
Imports EgtWPFLib5
Imports System.Windows.Forms
Public Class CadCutPageUC
+3
View File
@@ -563,6 +563,9 @@ Module VacuumCups
' assegnate le posizioni del centro delle ventose e l'angolo di posizionamento orizzontale verifica che la posizione sia raggiungibile
Public Function VerifyOutOfStrokes(ptRef As Point3d, dRotAngDeg As Double) As Integer
' Se macchina con ventosa dietro (VacType=1) non eseguo nessun controllo
If GetVacuumType() = 1 Then Return 0
' Verifico se usare l'asse W per la gestione delle ventose
Dim sAxisName As String = "C"
' verifico che il nome dell'asse impostato sia corretto
If EgtGetAxisId(sAxisName) = GDB_ID.NULL Then
+6
View File
@@ -127,6 +127,7 @@
Public Const K_VACUUMOFF As String = "VacuumOff"
Public Const K_BYPASSTATE As String = "BypassState"
Public Const K_FEEDHOLD As String = "FeedHold"
Public Const K_SPOTLIGHT As String = "SpotLight"
Public Const K_SPOTLIGHT1 As String = "SpotLight1"
Public Const K_SPOTLIGHT2 As String = "SpotLight2"
Public Const K_NAXES As String = "nAxes"
@@ -178,10 +179,15 @@
Public Const K_CHANGETABWD As String = "ChangeTabWD"
Public Const S_PHOTO As String = "Photo"
Public Const K_PHOTO_CAMERACOUNTER As String = "CameraCounter"
Public Const K_PHOTO_OFFSETX As String = "OffsetX"
Public Const K_PHOTO_OFFSETY As String = "OffsetY"
Public Const K_PHOTO_TAB2_OFFSETX As String = "Tab2OffsetX"
Public Const K_PHOTO_TAB2_OFFSETY As String = "Tab2OffsetY"
Public Const K_PHOTO_TAB3_OFFSETX As String = "Tab3OffsetX"
Public Const K_PHOTO_TAB3_OFFSETY As String = "Tab3OffsetY"
Public Const K_PHOTO_TAB4_OFFSETX As String = "Tab4OffsetX"
Public Const K_PHOTO_TAB4_OFFSETY As String = "Tab4OffsetY"
Public Const K_PHOTO_HQ_OFFSETX As String = "HQOffsetX"
Public Const K_PHOTO_HQ_OFFSETY As String = "HQOffsetY"
Public Const K_CAMERA_DIRECT_CMD As String = "CameraDirectCmd"
+30 -2
View File
@@ -142,8 +142,14 @@ Public Class CurrentMachine
Private m_dPhotoOffsetY As Double = 0
Private m_dTab2PhotoOffsetX As Double = 0
Private m_dTab2PhotoOffsetY As Double = 0
Private m_dTab3PhotoOffsetX As Double = 0
Private m_dTab3PhotoOffsetY As Double = 0
Private m_dTab4PhotoOffsetX As Double = 0
Private m_dTab4PhotoOffsetY As Double = 0
Private m_dHQPhotoOffsetX As Double = 0
Private m_dHQPhotoOffsetY As Double = 0
' Numero di camere attive in macchina
Private m_nCamCounter As Integer = 0
' Abilitazione scelta restart
Private m_bEnableRestart As Boolean = False
@@ -917,18 +923,30 @@ Public Class CurrentMachine
Friend ReadOnly Property PhotoOffset As Vector3d
Get
Select Case GetCurrentTable()
Case 4
Return New Vector3d(m_dTab4PhotoOffsetX, m_dTab4PhotoOffsetY, 0)
Case 3
Return New Vector3d(m_dTab3PhotoOffsetX, m_dTab3PhotoOffsetY, 0)
Case 2
Return New Vector3d(m_dTab2PhotoOffsetX, m_dTab2PhotoOffsetY, 0)
Case Else
Case 1
' verifico quale delle due fotocamere è attualmente attiva
If GetPrivateProfileInt(S_CAMERAHQ, K_CAMERAHQ_ACTIVATE, 0, m_MainWindow.GetMachIniFile()) = 1 Then
Return New Vector3d(m_dHQPhotoOffsetX, m_dHQPhotoOffsetY, 0)
End If
Return New Vector3d(m_dPhotoOffsetX, m_dPhotoOffsetY, 0)
Case Else
Return New Vector3d(m_dPhotoOffsetX, m_dPhotoOffsetY, 0)
End Select
End Get
End Property
Friend ReadOnly Property CameraCounter As Integer
Get
Return m_nCamCounter
End Get
End Property
Friend ReadOnly Property bEnableRestart As Boolean
Get
Return m_bEnableRestart
@@ -1428,11 +1446,21 @@ Public Class CurrentMachine
' Leggo centratura del pezzo in X sulla tavola (per macchine con nastro)
m_bCenterRawOnX = (GetPrivateProfileInt(S_TABLE, K_CENTER_RAW_ONX, 0, sMachIniFile) <> 0)
' Leggo offset aggiuntivo a fotografia
' Leggo il numero di camere installate a bordo macchina
m_nCamCounter = GetPrivateProfileInt(S_PHOTO, K_PHOTO_CAMERACOUNTER, -1, sMachIniFile)
' Leggo offset aggiuntivo a fotografia (Tab1 oppure Tab di carico)
m_dPhotoOffsetX = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_OFFSETX, 0, sMachIniFile)
m_dPhotoOffsetY = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_OFFSETY, 0, sMachIniFile)
' Tab2
m_dTab2PhotoOffsetX = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_TAB2_OFFSETX, 0, sMachIniFile)
m_dTab2PhotoOffsetY = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_TAB2_OFFSETY, 0, sMachIniFile)
' Tab3
m_dTab3PhotoOffsetX = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_TAB3_OFFSETX, 0, sMachIniFile)
m_dTab3PhotoOffsetY = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_TAB3_OFFSETY, 0, sMachIniFile)
' Tab4
m_dTab4PhotoOffsetX = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_TAB4_OFFSETX, 0, sMachIniFile)
m_dTab4PhotoOffsetY = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_TAB4_OFFSETY, 0, sMachIniFile)
' Tab1 Hq
m_dHQPhotoOffsetX = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_HQ_OFFSETX, 0, sMachIniFile)
m_dHQPhotoOffsetY = GetPrivateProfileDouble(S_PHOTO, K_PHOTO_HQ_OFFSETY, 0, sMachIniFile)
+5 -1
View File
@@ -274,6 +274,10 @@ Class MainWindow
Return m_bIsSiemensPc
End Function
Public Function GetDebug() As Integer
Return m_nDebug
End Function
Private Sub MainWindow_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
' Verifico sia l'unica istanza
ManageSingleIstance()
@@ -704,7 +708,7 @@ Class MainWindow
MyLicWn.Show()
End If
' inizilizzo
' inizializzo
End Sub
#Region "Selezione dei bottoni IN LAVORO, TAGLII DIRETTI, TAGLI CAD, CORNICI, MACCHINA, OPZIONI"
+2 -2
View File
@@ -62,5 +62,5 @@ Imports System.Windows
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("2.7.7.1")>
<Assembly: AssemblyFileVersion("2.7.7.1")>
<Assembly: AssemblyVersion("2.7.7.2")>
<Assembly: AssemblyFileVersion("2.7.7.2")>
+84 -74
View File
@@ -8,86 +8,96 @@
d:DesignHeight="853.3" d:DesignWidth="1280"
Initialized="CurrentProjectPage_Initialized" Loaded="CurrentProjectPage_Loaded">
<!-- Definizione della CurrentProjectPage -->
<Grid Name="CurrentProjectPageGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="12*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="8*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<!-- Definizione della Grid superiore -->
<Grid Name="UpperButtonGrid" Grid.Column="1" Grid.Row="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="7*"/>
</Grid.ColumnDefinitions>
</Grid>
<!-- Definizione della Grid laterale -->
<Grid Grid.RowSpan="3">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="7*"/>
<!-- Definizione della CurrentProjectPage -->
<Grid Name="CurrentProjectPageGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="12*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<RowDefinition Height="8*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<!-- Definizione della Grid con le caratteristiche del progetto -->
<Border Name="CurrProjGrid" Style="{DynamicResource OmagCut_MachiningBorder}" Grid.Row="0" >
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.5*"/>
<RowDefinition Height="0.5*"/>
<RowDefinition Height="0.5*"/>
<RowDefinition Height="0.5*"/>
</Grid.RowDefinitions>
<!-- Definizione della Grid superiore -->
<Grid Name="UpperButtonGrid" Grid.Column="1" Grid.Row="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="7*"/>
</Grid.ColumnDefinitions>
</Grid>
<Image Name="MaterialTxBl"
Source="{DynamicResource RawPartImg}" Style="{DynamicResource OmagCut_TextIcon}"/>
<EgtWPFLib:EgtTextBox Name="MaterialTxBx" Grid.Column="1" Grid.Row="0" Margin="0,0,10,0"
TextAlignment="Right" Style="{DynamicResource OmagCut_FixedTextBox}"/>
<Image Name="HeightTxBl" Grid.Row="1"
Source="{DynamicResource RawHeightImg}" Style="{DynamicResource OmagCut_TextIcon}"/>
<EgtWPFLib:EgtTextBox Name="HeightTxBx" Grid.Column="1" Grid.Row="1" Margin="0,0,10,0"
Style="{DynamicResource OmagCut_FixedTextBox}" TextAlignment="Right"/>
<Image Name="ToolTxBl" Grid.Row="2"
Source="{DynamicResource DB-utensiliImg}" Style="{DynamicResource OmagCut_TextIcon}"/>
<EgtWPFLib:EgtTextBox Name="ToolTxBx" Grid.Column="1" Grid.Row="2" Margin="0,0,10,0"
Style="{DynamicResource OmagCut_FixedTextBox}" TextAlignment="Right"/>
<Image Name="MachiningTxBl" Grid.Row="3"
Source="{DynamicResource DB-lavorazioniImg}" Style="{DynamicResource OmagCut_TextIcon}"/>
<EgtWPFLib:EgtTextBox Name="MachiningTxBx" Grid.Column="1" Grid.Row="3" Margin="0,0,10,0"
Style="{DynamicResource OmagCut_FixedTextBox}" TextAlignment="Right"/>
<!-- Definizione della Grid laterale -->
<Grid Grid.RowSpan="3">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="7*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<!-- Definizione della Grid laterale -->
<Grid Grid.RowSpan="3">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="7*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<!-- Definizione della Grid con le caratteristiche del progetto -->
<Border Name="CurrProjGrid" Style="{DynamicResource OmagCut_MachiningBorder}" Grid.Row="0" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.5*"/>
<RowDefinition Height="0.5*"/>
<RowDefinition Height="0.5*"/>
<RowDefinition Height="0.5*"/>
</Grid.RowDefinitions>
<Image Name="MaterialTxBl"
Source="{DynamicResource RawPartImg}" Style="{StaticResource OmagCut_TextIcon}"/>
<EgtWPFLib:EgtTextBox Name="MaterialTxBx" Grid.Column="1" Grid.Row="0" Margin="0,0,10,0"
TextAlignment="Right" Style="{DynamicResource OmagCut_FixedTextBox}"/>
<Image Name="HeightTxBl" Grid.Row="1"
Source="{DynamicResource RawHeightImg}" Style="{StaticResource OmagCut_TextIcon}"/>
<EgtWPFLib:EgtTextBox Name="HeightTxBx" Grid.Column="1" Grid.Row="1" Margin="0,0,10,0"
Style="{DynamicResource OmagCut_FixedTextBox}" TextAlignment="Right"/>
<Image Name="ToolTxBl" Grid.Row="2"
Source="{DynamicResource DB-utensiliImg}" Style="{StaticResource OmagCut_TextIcon}"/>
<EgtWPFLib:EgtTextBox Name="ToolTxBx" Grid.Column="1" Grid.Row="2" Margin="0,0,10,0"
Style="{DynamicResource OmagCut_FixedTextBox}" TextAlignment="Right"/>
<Image Name="MachiningTxBl" Grid.Row="3"
Source="{DynamicResource DB-lavorazioniImg}" Style="{StaticResource OmagCut_TextIcon}"/>
<EgtWPFLib:EgtTextBox Name="MachiningTxBx" Grid.Column="1" Grid.Row="3" Margin="0,0,10,0"
Style="{DynamicResource OmagCut_FixedTextBox}" TextAlignment="Right"/>
</Grid>
</Border>
<StackPanel Grid.Row="2" Orientation="Vertical" Name="PhotoProgressStackPanel">
<ProgressBar Name="PhotoProgress" Height="50" Margin="10,0,10,0" Minimum="0" Maximum="100"/>
<Label Name="PhotoProgressText" Foreground="WhiteSmoke" HorizontalAlignment="Center"/>
</StackPanel>
<Border Name="OutMessageBrd" Grid.Row="2" >
<TextBlock Name="OutMessageTxBl" TextAlignment="Center"
Style="{StaticResource OmagCut_LowerCaseCharacterTextBlock}"/>
</Border>
</Grid>
</Border>
</Grid>
<ProgressBar Name="PhotoProgress" Grid.Row="2" Height="50" Margin="10,0,10,0" Minimum="0" Maximum="100"/>
<Border Name="OutMessageBrd" Grid.Row="2" >
<TextBlock Name="OutMessageTxBl" TextAlignment="Center"
Style="{DynamicResource OmagCut_LowerCaseCharacterTextBlock}"/>
</Border>
</Grid>
<Grid Name="SceneHostGrid" Grid.Row="1" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="1.2*"/>
</Grid.ColumnDefinitions>
</Grid>
</Grid>
<Grid Name="SceneHostGrid" Grid.Row="1" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="1.2*"/>
</Grid.ColumnDefinitions>
</Grid>
</Grid>
</UserControl>
+2 -2
View File
@@ -202,8 +202,8 @@ Public Class CurrentProjectPageUC
m_nCurrProj = GetPrivateProfileInt(S_GENERAL, K_LASTPROJ, 0, m_MainWindow.GetIniFile())
'NewProject()
' Nascondo progress per fotografia
PhotoProgress.Visibility = Windows.Visibility.Hidden
' Nascondo progress e testo per fotografia
PhotoProgressStackPanel.Visibility = Windows.Visibility.Hidden
Else
EgtSetCurrentContext(CurrentProjectScene.GetCtx())
+563 -271
View File
@@ -14,6 +14,7 @@
Imports System.Threading
Imports System.IO
Imports EgtUILib
Imports System.Reflection
Public Class Camera
@@ -25,40 +26,67 @@ Public Class Camera
Private m_bCalcContour As Boolean = False
Private m_nCameraCount As Integer = 0
Private m_sCameraPath As String = String.Empty
Private m_sCameraPath2 As String = String.Empty
'Private m_sCameraPath2 As String = String.Empty
Private m_sCameraProcName As String = String.Empty
Private m_sCameraProcName2 As String = String.Empty
'Private m_sCameraProcName2 As String = String.Empty
Private m_sImage As String = String.Empty
Private m_sImage2 As String = String.Empty
'Private m_sImage2 As String = String.Empty
Private m_sInfo As String = String.Empty
Private m_sInfo2 As String = String.Empty
'Private m_sInfo2 As String = String.Empty
Private m_sResult As String = String.Empty
Private m_sResult2 As String = String.Empty
'Private m_sResult2 As String = String.Empty
Private m_sContour As String = String.Empty
Private m_sContour2 As String = String.Empty
'Private m_sContour2 As String = String.Empty
Private m_nThreshold As Integer = 60
Private m_dTolerance As Double = 5
Private m_nTimeout As Integer = 30
Private m_sImageDir As String = String.Empty
Private Const CAMERAMNG As String = "CameraMng"
Private Const N_LOOP As Integer = 20
'Public m_ProcessCmg As New Process()
' Lista dei processi Cmg associati ad igni tavola
Public m_ProcessCmgList As New List(Of Process)
' restituisce lo stato che il processo associato alla tavola corrente (PrepareCamera)
Private m_bIsRunnigProc As Boolean = False
' restituisce l'esito dello scatto di una foto
Private m_bClickOk As Boolean = False
Private m_dClickOk As Double = 10
' restituisce l'esito dello scatto di una foto
Private m_bCorrectedImgOk As Boolean = False
Private m_dCorrectedImgOk As Double = 10
' restituisce l'esito di salvataggio BackImage
Private m_bSavedBackImage As Boolean = False
Private m_dSavedBackImage As Double = 90
'
Private m_bDowloadedPicFromCamera As Boolean = False
Private m_dDowloadedPicFromCamera As Double = 10
'
Private m_bReadOCV As Boolean = False
Private m_dReadOCV As Double = 10
'
Private m_bStartDistCorrect As Boolean = False
Private m_dStartDistCorrect As Double = 30
'
Private m_bStartProspCorrect As Boolean = False
Private m_dStartProspCorrect As Double = 20
Private DeltaCameraTab As Integer = 0
' Flag per foto in esecuzione
Friend m_bBusy As Boolean = False
Public Function Init() As Boolean
' Lettura dati di configurazione da file Ini
m_bCameraLink = (GetPrivateProfileInt(S_GENERAL, K_CAMERALINK, 0, m_MainWindow.GetIniFile()) <> 0) And
Not m_MainWindow.GetKeyOption( MainWindow.KEY_OPT.OFFICE_TYPE)
m_nCameraCount = GetPrivateProfileInt(S_CAMERA, K_CAM_COUNT, 1, m_MainWindow.GetIniFile())
Not m_MainWindow.GetKeyOption(MainWindow.KEY_OPT.OFFICE_TYPE)
GetPrivateProfileString(S_CAMERA, K_CAM_EXEPATH, "", m_sCameraPath, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_IMAGE, "", m_sImage, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_INFO, "", m_sInfo, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_RESULT, "", m_sResult, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_CONTOUR, "", m_sContour, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_EXEPATH2, "", m_sCameraPath2, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_IMAGE2, "", m_sImage2, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_INFO2, "", m_sInfo2, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_RESULT2, "", m_sResult2, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_CONTOUR2, "", m_sContour2, m_MainWindow.GetIniFile())
m_nThreshold = GetPrivateProfileInt(S_CAMERA, K_CAM_THRESHOLD, 60, m_MainWindow.GetIniFile())
m_dTolerance = GetPrivateProfileDouble(S_CAMERA, K_CAM_TOLERANCE, 5, m_MainWindow.GetIniFile())
m_nTimeout = GetPrivateProfileInt(S_CAMERA, K_CAM_TIMEOUT, 30, m_MainWindow.GetIniFile())
@@ -68,42 +96,15 @@ Public Class Camera
(GetPrivateProfileInt(S_GENERAL, K_CONTOURFROMCAMERA, 1, m_MainWindow.GetIniFile()) <> 0)
' Ricavo il nome del processo associato
m_sCameraProcName = Path.GetFileNameWithoutExtension(m_sCameraPath)
m_sCameraProcName2 = Path.GetFileNameWithoutExtension(m_sCameraPath2)
' Se camera abilitata, lancio l'esecuzione in cieco
If m_bCameraLink Then
If m_nCameraCount <> 2 Then
Dim bOk As Boolean = True
If Not CameraHide(1) Then
bOk = False
EgtOutLog("CameraMng not starting")
End If
Return bOk
Else
Dim bOk As Boolean = True
If Not CameraHide(1) Then
bOk = False
EgtOutLog("CameraMng 1 not starting")
End If
If Not CameraHide(2) Then
bOk = False
EgtOutLog("CameraMng 2 not starting")
End If
Return bOk
End If
Else
Return True
End If
' Avvio processi del camera manager per ogni tavola
CamerasHide()
Return True
End Function
Public Function Close() As Boolean
If m_bBusy Then Return False
If m_bCameraLink Then
If m_nCameraCount <> 2 Then
KillProcess(1)
Else
KillProcess(1)
KillProcess(2)
End If
KillProcess()
End If
Return True
End Function
@@ -154,191 +155,194 @@ Public Class Camera
End Set
End Property
Public Function CameraHide(nInd As Integer) As Boolean
' Lancio il programma in cieco, se già attivo lo nascondo
Try
Process.Start(If(nInd <> 2, m_sCameraPath, m_sCameraPath2), "0")
Return True
Catch ex As Exception
Return False
End Try
' OK: Restituisce la tavola a cui è associato il processo
Private Function GetCurrentTableFromCameraProcess(nIndProc As Integer) As Integer
Dim nIndTab As Integer = 1
Select Case DeltaCameraTab
Case 0
nIndTab = nIndProc
Case 1
' La cameraHq è sempre associata all'ultimo processo e sempre alla prima tavola
nIndTab = 1
Case -1
nIndTab = GetCurrentTable()
End Select
Return nIndTab
End Function
Public Function CameraShow(nInd As Integer) As Boolean
' Lancio il programma in modo visibile, se già attivo lo rendo visibile
Try
Process.Start(If(nInd <> 2, m_sCameraPath, m_sCameraPath2), "1")
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Function CameraTest(nInd As Integer) As Boolean
' Cancello il risultato
If My.Computer.FileSystem.FileExists(If(nInd <> 2, m_sResult, m_sResult2)) Then
My.Computer.FileSystem.DeleteFile(If(nInd <> 2, m_sResult, m_sResult2))
End If
' Lancio il programma per sapere se macchina fotografica collegata
Try
' Interrogo
Process.Start(If(nInd <> 2, m_sCameraPath, m_sCameraPath2), "3")
' Ciclo di attesa risultato
Dim nMaxThick = 10 * 4
For nThick As Integer = 0 To nMaxThick
' Se esiste il file di risultato
Dim nErr = 999
If VerifyResult(nInd, nErr) Then
Return (nErr = 0)
End If
' Aspetto 100 ms
Thread.Sleep(100)
Next
Catch ex As Exception
'
End Try
Return False
End Function
Private Function PrepareCamera() As Integer
' Determino la camera da utilizzare, se più di una (max 2)
Dim nInd As Integer = 1
If m_nCameraCount = 2 Then
nInd = GetCurrentTable()
' verifico se la macchina è configurata per fotocamera sulla tavola di lavoro
If (GetPrivateProfileInt(S_CAMERAHQ, K_CAMERAHQ_ENABLE, 0, m_MainWindow.GetMachIniFile()) <> 0) AndAlso
(GetPrivateProfileInt(S_CAMERAHQ, K_CAMERAHQ_ACTIVATE, 0, m_MainWindow.GetMachIniFile()) <> 0) Then
' forzo l'utilizzo della seconda camera (sopra alla tavola di lavoro)
nInd = 2
End If
If nInd <> 1 And nInd <> 2 Then Return 0
End If
' Se gestore macchina non attivo, lo lancio in modo cieco
If Not ProcessIsRunning(nInd) Then
If Not CameraHide(nInd) Then
Return 0
End If
' Aspetto 5000 ms
Thread.Sleep(5000)
' Altrimenti richiedo verifica di camera connessa
Else
If Not CameraTest(nInd) Then
Return 0
End If
' Aspetto 100 ms
Thread.Sleep(100)
End If
Return nInd
End Function
Public Function CameraBackImage() As Boolean
' Verifiche preliminari
Dim nInd As Integer = PrepareCamera()
If nInd = 0 Then Return False
' Visualizzo progressbar
m_bBusy = True
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Visibility = Visibility.Visible
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = 1
' Cancellazione eventuali vecchi file rimasti
Try
If My.Computer.FileSystem.FileExists(If(nInd <> 2, m_sResult, m_sResult2)) Then
My.Computer.FileSystem.DeleteFile(If(nInd <> 2, m_sResult, m_sResult2))
End If
Catch ex As Exception
End Try
' Scatto una foto come sfondo (il programma deve essere già attivo)
Dim bOk As Boolean = False
Try
Process.Start(If(nInd <> 2, m_sCameraPath, m_sCameraPath2), "4")
bOk = WaitBackImage(nInd)
Catch ex As Exception
bOk = False
End Try
' Nascondo progressbar
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Visibility = Visibility.Hidden
m_bBusy = False
Return bOk
End Function
Private Function WaitBackImage(nInd As Integer) As Boolean
' Ciclo di ricerca foto scattata
Dim nMaxThick = 10 * m_nTimeout
For nThick As Integer = 0 To nMaxThick
' Se esiste il file di risultato
Dim nErr = 999
If VerifyResult(nInd, nErr) Then
If nErr = 0 Then
Return True
' OK: Restituisce il processo a cui è associata la tavola
Private Function GetProcessFromCurrentTable(nIndTab As Integer) As Integer
Dim nIndProc As Integer = 1
Select Case DeltaCameraTab
Case 0
' Indice di processo uguale all'indice della tavola
nIndProc = nIndTab
Case 1
' Alla tavola 1 possono essre associati 2 processi (solo se camera Hq abilitata e attiva)
If nIndTab = 1 And
(GetPrivateProfileInt(S_CAMERAHQ, K_CAMERAHQ_ENABLE, 0, m_MainWindow.GetMachIniFile()) <> 0) AndAlso
(GetPrivateProfileInt(S_CAMERAHQ, K_CAMERAHQ_ACTIVATE, 0, m_MainWindow.GetMachIniFile()) <> 0) Then
' forzo l'utilizzo della seconda Hq (sopra alla tavola 1 di lavoro)
nIndProc = nIndTab + 1
Else
nIndProc = 1
End If
Case -1
nIndProc = 1
End Select
Return nIndProc
End Function
' OK: Avvio un processo per ogni tavola presente in macchina
Public Function CamerasHide() As Boolean
' Lancio il programma in cieco, se già attivo lo nascondo
m_nCameraCount = GetTableCount()
' Se esiste una configurazione, ne verifico la sua valità
If m_MainWindow.m_CurrentMachine.CameraCounter > -1 Then
DeltaCameraTab = m_MainWindow.m_CurrentMachine.CameraCounter - GetTableCount()
Select Case DeltaCameraTab
Case 0
' ad ogni tavola associo una camera/configurazione
Case 1
' Gestisco correttamente solo il caso: 1 tavola e 2 camere
If GetPrivateProfileInt(S_CAMERAHQ, K_CAMERAHQ_ENABLE, 0, m_MainWindow.GetMachIniFile()) = 1 Then
m_nCameraCount = m_nCameraCount + 1
End If
Case -1
' Gestisco correttamente solo il caso: 2 tavole e 1 camera
m_nCameraCount = m_nCameraCount - 1
Case Else
EgtOutLog(" 🚨 CAUTION : Differenza tra numero di camere e numero di tavole: " & DeltaCameraTab.ToString &
", sarà attivata solo la prima camera.")
DeltaCameraTab = 0
End Select
Else
EgtOutLog(" 🚨 CAUTION : In file *.ini machine '[Photo]' there is not param 'CameraCounter'.")
' Aggiungo un altro processo se camera Hq abilitata (non esite una vera tavola associata)
If GetPrivateProfileInt(S_CAMERAHQ, K_CAMERAHQ_ENABLE, 0, m_MainWindow.GetMachIniFile()) = 1 Then
m_nCameraCount = m_nCameraCount + 1
DeltaCameraTab = 1
End If
End If
Try
For Index As Integer = 1 To m_nCameraCount
Dim m_ProcessCmg As New Process()
m_ProcessCmg.StartInfo.FileName = m_sCameraPath
m_ProcessCmg.StartInfo.RedirectStandardInput = True
m_ProcessCmg.StartInfo.RedirectStandardOutput = True
' Assegno argomento 0 per avvio in cieco, index per specificare il numero di processo
m_ProcessCmg.StartInfo.Arguments = "0" & " " & Index.ToString()
m_ProcessCmg.StartInfo.UseShellExecute = False
m_ProcessCmg.StartInfo.CreateNoWindow = True
AddHandler m_ProcessCmg.OutputDataReceived, AddressOf Thread_OutputDataReceived
If m_ProcessCmg.Start() Then
m_ProcessCmg.BeginOutputReadLine()
' Richiesta lettura configurazione corrente
m_ProcessCmg.StandardInput.WriteLine("0")
m_ProcessCmgList.Add(m_ProcessCmg)
Else
EgtOutLog("Camera err=" & nErr.ToString())
Return False
End If
' Altrimenti aspetto
Else
' Imposto ProgressBar
Dim nProgress As Integer = CInt(nThick * 100 / nMaxThick)
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = nProgress
' Costringo ad aggiornare UI
UpdateUI()
' Aspetto 100 ms
Thread.Sleep(100)
End If
Next
EgtOutLog("Camera generic error")
' Chiudo il gestore della macchina per resettarlo
KillProcess(nInd)
Next
Return True
Catch ex As Exception
EgtOutLog(ex.Message)
Return False
End Try
End Function
' OK: Creo un nuovo processo associato alla tavola indicata
Public Function ReloadCameraHide(nInd As Integer) As Boolean
Dim m_ProcessCmg As New Process()
m_ProcessCmg.StartInfo.FileName = m_sCameraPath
m_ProcessCmg.StartInfo.RedirectStandardInput = True
m_ProcessCmg.StartInfo.RedirectStandardOutput = True
' Assegno argomento 0 per avvio in cieco, index per specificare il numero di processo
m_ProcessCmg.StartInfo.Arguments = "0" & " " & nInd.ToString()
m_ProcessCmg.StartInfo.UseShellExecute = False
m_ProcessCmg.StartInfo.CreateNoWindow = True
AddHandler m_ProcessCmg.OutputDataReceived, AddressOf Thread_OutputDataReceived
If m_ProcessCmg.Start() Then
m_ProcessCmg.BeginOutputReadLine()
m_ProcessCmgList(nInd) = m_ProcessCmg
Return True
End If
Return False
End Function
Public Function CameraClick() As Boolean
' Verifiche preliminari
Dim nInd As Integer = PrepareCamera()
' Visualizzo progressbar
m_bBusy = True
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Visibility = Visibility.Visible
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = 1
' Cancellazione eventuali vecchi file rimasti
Try
If My.Computer.FileSystem.FileExists(If(nInd <> 2, m_sResult, m_sResult2)) Then
My.Computer.FileSystem.DeleteFile(If(nInd <> 2, m_sResult, m_sResult2))
' OK: Ogni processo cameramanager che restituisce un messaggio passa di qua
Private Sub Thread_OutputDataReceived(sender As Object, e As DataReceivedEventArgs)
' Il formato del messaggio è 'esempio messaggio: #IndProc'
If Not IsNothing(e.Data) Then
Dim sMsg As String() = e.Data.Split(":"c)
' reinserisco eventuali ":" che sono stati rimossi
If sMsg.Length > 2 Then
For Index As Integer = 2 To sMsg.Length - 1
sMsg(1) &= ":" & sMsg(Index)
Next
End If
If My.Computer.FileSystem.FileExists(If(nInd <> 2, m_sImage, m_sImage2)) Then
My.Computer.FileSystem.DeleteFile(If(nInd <> 2, m_sImage, m_sImage2))
If sMsg.Length > 1 Then
Select Case sMsg(0)
' Metodo WaitingForInstruction
' Se richiesto comando 7 stampo questo messaggio
Case "PROCESSO ATTIVO"
m_bIsRunnigProc = True
' Metodo TakeFoto
Case "SCATTO FOTO AVVENUTO"
m_bClickOk = True
' Metodo Camera_DownloadedCompleted
Case "DOWNLOAD DA CAMERA COMPLETATO"
m_bDowloadedPicFromCamera = True
' Metodo LeggiFileCalibrazioneLenteOCV
Case "LETTURA OCV"
m_bReadOCV = True
' Metodo CorrezioneCompleta
Case "RICHIESTA CORREZIONE DISTORSIONE"
m_bStartDistCorrect = True
Case "RICHIESTA CORREZIONE PROSPETTICA"
m_bStartProspCorrect = True
' Metodo CorreggiProspettivaDaMatriceOCV
Case "FINE CREAZIONE IMMAGINE CON CORREZIONE OCV"
m_bCorrectedImgOk = True
' Metodo SalvaNuovoBackGround
Case "BACKIMAGE PRONTA"
m_bSavedBackImage = True
End Select
If m_MainWindow.GetDebug > 3 Then
EgtOutLog(" § " & sMsg(0) & " Process_" & sMsg(1))
End If
End If
If My.Computer.FileSystem.FileExists(If(nInd <> 2, m_sContour, m_sContour2)) Then
My.Computer.FileSystem.DeleteFile(If(nInd <> 2, m_sContour, m_sContour2))
End If
If My.Computer.FileSystem.FileExists(If(nInd <> 2, m_sInfo, m_sInfo2)) Then
My.Computer.FileSystem.DeleteFile(If(nInd <> 2, m_sInfo, m_sInfo2))
End If
Catch ex As Exception
End Try
End If
End Sub
' OK : Accendo fari e vado in Home
Private Sub PrepareMachine(nInd As Integer)
' ------------------------------------ accensione riflettori ------------------------------------
Dim sPLCVarSpotLight1 As String = String.Empty
GetPrivateProfileString(S_NCDATA, K_SPOTLIGHT1, "", sPLCVarSpotLight1, m_MainWindow.GetMachIniFile())
Dim sPLCVarSpotLight2 As String = String.Empty
GetPrivateProfileString(S_NCDATA, K_SPOTLIGHT2, "", sPLCVarSpotLight2, m_MainWindow.GetMachIniFile())
Dim sPLCVarSpotLightList As New List(Of String)
For IndexSpot As Integer = 1 To GetTableCount()
Dim sPLCVarSpotLight As String = String.Empty
GetPrivateProfileString(S_NCDATA, K_SPOTLIGHT & IndexSpot.ToString(), "", sPLCVarSpotLight, m_MainWindow.GetMachIniFile())
' eventualmente rimuovo inizio stringa: "PLC, ___"
Dim sItemString() As String = Split(sPLCVarSpotLight, ","c)
If sItemString.Count > 1 Then
sPLCVarSpotLight = sItemString(1).Trim
End If
sPLCVarSpotLightList.Add(sPLCVarSpotLight)
Next
Dim nPhotoDeley As Integer = GetPrivateProfileInt(S_NCNUM, K_PHOTODELEY, "100", m_MainWindow.GetMachIniFile())
' eventualmente rimuovo inizio stringa: "PLC, ___"
Dim sItemString1() As String = Split(sPLCVarSpotLight1, ","c)
If sItemString1.Count > 1 Then
sPLCVarSpotLight1 = sItemString1(1).Trim
End If
Dim sItemString2() As String = Split(sPLCVarSpotLight2, ","c)
If sItemString2.Count > 1 Then
sPLCVarSpotLight2 = sItemString2(1).Trim
End If
Select Case m_MainWindow.m_CNCommunication.m_nNCType
Case 1, 2
If m_MainWindow.m_CNCommunication.m_nNCType = 2 Then
' solo per Flexium
m_MainWindow.m_CNCommunication.m_CN.DPlcVariables_WriteVariables(If(nInd <> 2, sPLCVarSpotLight1, sPLCVarSpotLight2), "1")
m_MainWindow.m_CNCommunication.m_CN.DPlcVariables_WriteVariables(sPLCVarSpotLightList(nInd - 1), "1")
' altrimenti scrittura delle variabili E
Else
m_MainWindow.m_CNCommunication.m_CN.DVariables_WriteVariables2(If(nInd <> 2, sPLCVarSpotLight1, sPLCVarSpotLight2), "1")
m_MainWindow.m_CNCommunication.m_CN.DVariables_WriteVariables2(sPLCVarSpotLightList(nInd - 1), "1")
End If
System.Threading.Thread.Sleep(nPhotoDeley)
Case 3
@@ -351,25 +355,8 @@ Public Class Camera
If Not GoHomeForPhoto() Then
EgtOutLog("Error in positioning")
End If
' ------------------------------------ mando la testa in home ------------------------------------
' Scatto una foto con eventuale riconoscimento del contorno (il programma deve essere già attivo)
Dim bOk As Boolean = False
Dim sArgs As String = "2 0"
If m_bCalcContour Then sArgs = " 5 0 " & m_nThreshold.ToString() & " 0"
Try
Process.Start(If(nInd <> 2, m_sCameraPath, m_sCameraPath2), sArgs)
bOk = WaitPhoto(nInd)
Catch ex As Exception
EgtOutLog(ex.Message())
bOk = False
End Try
' Nascondo progressbar
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Visibility = Visibility.Hidden
m_bBusy = False
Return bOk
End Function
End Sub
Private Function GoHomeForPhoto() As Boolean
Dim bGoHome As Boolean = GetPrivateProfileInt(S_PHOTO, K_ENABELE_GOHOME_FOR_PHOTO, 0, m_MainWindow.GetMachIniFile()) <> 0
@@ -431,55 +418,359 @@ Public Class Camera
Return bPositionOk
End Function
Private Function WaitPhoto(nInd As Integer) As Boolean
' Ciclo di ricerca foto scattata
Dim nMaxThick = 10 * m_nTimeout
For nThick As Integer = 0 To nMaxThick
' Se esiste il file di risultato
Dim nErr = 999
If VerifyResult(nInd, nErr) Then
If nErr = 0 Then
' Copio i file
Dim sImageDest As String = m_sImageDir & "\" & Path.GetFileName(If(nInd <> 2, m_sImage, m_sImage2))
Dim sInfoDest As String = Path.ChangeExtension(sImageDest, "txt")
File.Copy(If(nInd <> 2, m_sImage, m_sImage2), sImageDest, True)
File.Copy(If(nInd <> 2, m_sInfo, m_sInfo2), sInfoDest, True)
' Se richiesto il riconoscimento del contorno
Dim sContourDest As String = String.Empty
If m_bCalcContour Then
sContourDest = Path.ChangeExtension(sImageDest, "dxf")
File.Copy(If(nInd <> 2, m_sContour, m_sContour2), sContourDest, True)
' altrimenti cancello eventuale contorno presente
Else
m_MainWindow.m_CurrentProjectPageUC.RemoveContour()
End If
' Lancio caricamento della foto e del contorno
m_MainWindow.m_CadCutPageUC.PostPhoto(sImageDest, sContourDest)
Return True
Else
EgtOutLog("Camera err=" & nErr.ToString())
Return False
End If
' Altrimenti aspetto
' OK: Ottengo l'indice del processo associato alla tavola e la configurazione del processo
Private Function PrepareCamera() As Integer
' Stati del processo
m_bIsRunnigProc = False
m_bClickOk = False
m_bCorrectedImgOk = False
m_bSavedBackImage = False
' Argomento utilizzato per verificare lo stato della comunicazione
Dim sArgs As String = "7"
Dim nIndTab As Integer = GetCurrentTable()
Dim nIndProc As Integer = GetProcessFromCurrentTable(nIndTab)
' Invio richiesta al processo per vedere se la comunicazione è aperta
Try
If Not m_ProcessCmgList(nIndProc - 1).HasExited Then
m_ProcessCmgList(nIndProc - 1).StandardInput.WriteLine(sArgs)
Else
' Imposto ProgressBar
Dim nProgress As Integer = CInt(nThick * 100 / nMaxThick)
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = nProgress
Return -2
End If
Catch ex As Exception
EgtOutLog(ex.Message())
End Try
' Attendo massimo N_LOOP secondi per avere una risposta dal programma (la risposta arriva al metodo Thread_OutputDataReceived)
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bIsRunnigProc Then Exit For
Next
' Se processo non attivo allora provo a rilanciarlo
If Not m_bIsRunnigProc Then
EgtOutLog(" ~ PROCESSO NON RISPONDE: Process_" & (nIndProc).ToString())
ReloadCameraHide(nIndProc - 1)
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
' Invio richiesta al processo per vedere se la comunicazione è aperta
m_ProcessCmgList(nIndProc - 1).StandardInput.WriteLine(sArgs)
If m_bIsRunnigProc Then Exit For
Next
End If
' -----------------------------------------------------------------
' ----- PREPARAZIONE PERCORSO FILE -----
' -----------------------------------------------------------------
GetPrivateProfileString(S_CAMERA, K_CAM_IMAGE, "", m_sImage, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_INFO, "", m_sInfo, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_RESULT, "", m_sResult, m_MainWindow.GetIniFile())
GetPrivateProfileString(S_CAMERA, K_CAM_CONTOUR, "", m_sContour, m_MainWindow.GetIniFile())
m_sImage = m_sImage.Replace(CAMERAMNG, CAMERAMNG & (nIndProc).ToString())
m_sInfo = m_sInfo.Replace(CAMERAMNG, CAMERAMNG & (nIndProc).ToString())
m_sResult = m_sResult.Replace(CAMERAMNG, CAMERAMNG & (nIndProc).ToString())
m_sContour = m_sContour.Replace(CAMERAMNG, CAMERAMNG & (nIndProc).ToString())
Return If(m_bIsRunnigProc, nIndProc, -1)
End Function
' OK: Scatto foto e aspetto WaitBackImage
Public Function CameraBackImage() As Boolean
' Verifiche preliminari
Dim nIndProc As Integer = PrepareCamera()
' Se non è stato trovato il processo associato alla tavola allora esco
Select Case nIndProc
Case -2
EgtOutLog("Direttorio di configurazione 'CamerMng" & GetCurrentTable().ToString() & "' non è stato trovato")
Case -1
EgtOutLog("Camera " & GetCurrentTable().ToString() & " spenta")
End Select
If nIndProc < 0 Then Return False
' Visualizzo progressbar
m_bBusy = True
m_MainWindow.m_CurrentProjectPageUC.ClearMessage()
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressStackPanel.Visibility = Visibility.Visible
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = 0
' Cancellazione eventuali vecchi file rimasti
Try
If My.Computer.FileSystem.FileExists(m_sResult) Then
My.Computer.FileSystem.DeleteFile(m_sResult)
End If
Catch ex As Exception
End Try
' Se richiesto: accendo fari ed eventualmente mando la testa in Home
Dim nIndTab As Integer = GetCurrentTableFromCameraProcess(nIndProc)
PrepareMachine(nIndTab)
' Scatto una foto come sfondo (il programma deve essere già attivo)
Dim bOk As Boolean = False
Dim sArgs As String = "4"
Try
m_ProcessCmgList(nIndProc - 1).StandardInput.WriteLine(sArgs)
bOk = WaitBackImage(nIndProc)
Catch ex As Exception
bOk = False
End Try
' Nascondo progressbar
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressStackPanel.Visibility = Visibility.Hidden
m_bBusy = False
Return bOk
End Function
' OK: cerco l'immagine nella confidurazione di indica nInd
Private Function WaitBackImage(nInd As Integer) As Boolean
Dim dProgVal As Double = 0
' verifico che abbia scattato la foto (dalla lettura degli eventi restituiti dal processo)
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "CLICK"
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bClickOk Then
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = m_dClickOk
' Costringo ad aggiornare UI
UpdateUI()
' Aspetto 100 ms
Thread.Sleep(100)
Exit For
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = m_dClickOk / N_LOOP * (i + 1)
' Costringo ad aggiornare UI
UpdateUI()
Next
dProgVal = m_dClickOk
If Not m_bClickOk Then Return False
' verifico che sia stata scaricata l'immagine
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "DOWNLOAD PIC"
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bDowloadedPicFromCamera Then
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dDowloadedPicFromCamera
' Costringo ad aggiornare UI
UpdateUI()
Exit For
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dDowloadedPicFromCamera / N_LOOP * (i + 1)
' Costringo ad aggiornare UI
UpdateUI()
Next
dProgVal = dProgVal + m_dDowloadedPicFromCamera
If Not m_bDowloadedPicFromCamera Then Return False
' verifico che sia stata scaricata l'immagine
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "SAVE BACKIMG"
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bSavedBackImage Then
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dSavedBackImage
' Costringo ad aggiornare UI
UpdateUI()
Exit For
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dSavedBackImage / N_LOOP * (i + 1)
' Costringo ad aggiornare UI
UpdateUI()
Next
dProgVal = dProgVal + m_dSavedBackImage
If Not m_bSavedBackImage Then Return False
' Se esiste il file di risultato (NON ho modo di vedere se il risultato è andato a buon fine)
Dim nErr = 999
If VerifyResult(nInd, nErr) Then
If nErr = 0 Then
Return True
Else
EgtOutLog("Camera err=" & nErr.ToString())
Return False
End If
' Altrimenti aspetto
End If
EgtOutLog("Camera generic error")
' Chiudo il gestore della macchina per resettarlo
KillProcess(nInd)
Return False
End Function
' OK: Scatto foto e aspetto WaitPhoto
Public Function CameraClick() As Boolean
' Verifiche preliminari
Dim nIndProc As Integer = PrepareCamera()
' Se non è stato trovato il processo associato alla tavola allora esco
Select Case nIndProc
Case -2
EgtOutLog("Direttorio di configurazione 'CamerMng" & GetCurrentTable().ToString() & "' non è stato trovato")
Case -1
EgtOutLog("Camera " & GetCurrentTable().ToString() & " spenta")
End Select
If nIndProc < 0 Then Return False
' Visualizzo progressbar
m_bBusy = True
m_MainWindow.m_CurrentProjectPageUC.ClearMessage()
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressStackPanel.Visibility = Visibility.Visible
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = 0
' Costringo ad aggiornare UI
UpdateUI()
' Cancellazione eventuali vecchi file rimasti
Try
If My.Computer.FileSystem.FileExists(m_sResult) Then
My.Computer.FileSystem.DeleteFile(m_sResult)
End If
If My.Computer.FileSystem.FileExists(m_sImage) Then
My.Computer.FileSystem.DeleteFile(m_sImage)
End If
If My.Computer.FileSystem.FileExists(m_sContour) Then
My.Computer.FileSystem.DeleteFile(m_sContour)
End If
If My.Computer.FileSystem.FileExists(m_sInfo) Then
My.Computer.FileSystem.DeleteFile(m_sInfo)
End If
Catch ex As Exception
End Try
' Se richiesto: accendo fari ed eventualmente mando la testa in Home
Dim nIndTab As Integer = GetCurrentTableFromCameraProcess(nIndProc)
PrepareMachine(nIndTab)
' Scatto una foto con eventuale riconoscimento del contorno (il programma deve essere già attivo)
Dim bOk As Boolean = False
Dim sArgs As String = "2"
' Per ricavare il contorno bisogna passare i segunti valori: 5,Valore_Soglia
If m_bCalcContour Then sArgs = "5" & "," & m_nThreshold.ToString()
Try
' invio la richiesta di scattare una foto
m_ProcessCmgList(nIndProc - 1).StandardInput.WriteLine(sArgs)
bOk = WaitPhoto()
Catch ex As Exception
EgtOutLog(ex.Message())
bOk = False
End Try
' Nascondo progressbar
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressStackPanel.Visibility = Visibility.Hidden
m_bBusy = False
Return bOk
End Function
' OK: attendo che sia pronta l'immagine
Private Function WaitPhoto() As Boolean
Dim dProgVal As Double = 0
' verifico che abbia scattato la foto (dalla lettura degli eventi restituiti dal processo)
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "CLICK"
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bClickOk Then
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = m_dClickOk
' Costringo ad aggiornare UI
UpdateUI()
Exit For
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = m_dClickOk / N_LOOP * (i + 1)
' Costringo ad aggiornare UI
UpdateUI()
Next
dProgVal = m_dClickOk
If Not m_bClickOk Then Return False
'
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "DOWNLOAD PIC"
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bDowloadedPicFromCamera Then
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dDowloadedPicFromCamera
' Costringo ad aggiornare UI
UpdateUI()
Exit For
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dDowloadedPicFromCamera / N_LOOP * (i + 1)
' Costringo ad aggiornare UI
UpdateUI()
Next
dProgVal = dProgVal + m_dDowloadedPicFromCamera
If Not m_bDowloadedPicFromCamera Then Return False
'
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "READ OCV"
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bReadOCV Then
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dReadOCV
' Costringo ad aggiornare UI
UpdateUI()
Exit For
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dReadOCV / N_LOOP * (i + 1)
' Costringo ad aggiornare UI
UpdateUI()
Next
dProgVal = dProgVal + m_dReadOCV
If Not m_bReadOCV Then Return False
'
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "START DIST"
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bStartDistCorrect Then
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dStartDistCorrect
' Costringo ad aggiornare UI
UpdateUI()
Exit For
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dStartDistCorrect / N_LOOP * (i + 1)
' Costringo ad aggiornare UI
UpdateUI()
Next
dProgVal = dProgVal + m_dStartDistCorrect
If Not m_bStartDistCorrect Then Return False
'
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "START PROSP"
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bStartProspCorrect Then
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dStartProspCorrect
' Costringo ad aggiornare UI
UpdateUI()
Exit For
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dStartProspCorrect / N_LOOP * (i + 1)
' Costringo ad aggiornare UI
UpdateUI()
Next
dProgVal = dProgVal + m_dStartProspCorrect
If Not m_bStartProspCorrect Then Return False
' verifico che il processo di correzione della foto sia terminato correttamente
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "CORRECT IMG"
For i As Integer = 0 To N_LOOP
Thread.Sleep(1000)
If m_bCorrectedImgOk Then
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dCorrectedImgOk
' Costringo ad aggiornare UI
UpdateUI()
Exit For
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = dProgVal + m_dCorrectedImgOk / N_LOOP * (i + 1)
' Costringo ad aggiornare UI
UpdateUI()
Next
dProgVal = dProgVal + m_dCorrectedImgOk
m_MainWindow.m_CurrentProjectPageUC.PhotoProgressText.Content = "IMPORT IMG"
' Copio i file
Dim sImageDest As String = m_sImageDir & "\" & Path.GetFileName(m_sImage)
Dim sInfoDest As String = Path.ChangeExtension(sImageDest, "txt")
File.Copy(m_sImage, sImageDest, True)
File.Copy(m_sInfo, sInfoDest, True)
' Se richiesto il riconoscimento del contorno
Dim sContourDest As String = String.Empty
If m_bCalcContour Then
sContourDest = Path.ChangeExtension(sImageDest, "dxf")
File.Copy(m_sContour, sContourDest, True)
' altrimenti cancello eventuale contorno presente
Else
m_MainWindow.m_CurrentProjectPageUC.RemoveContour()
End If
m_MainWindow.m_CurrentProjectPageUC.PhotoProgress.Value = 95
' Costringo ad aggiornare UI
UpdateUI()
' Lancio caricamento della foto e del contorno
m_MainWindow.m_CadCutPageUC.PostPhoto(sImageDest, sContourDest)
Return True
End Function
' OK: verifica che la backimage sia stata scaricata correttamente nel direttorio CameraMng#n
Private Function VerifyResult(nInd As Integer, ByRef nErr As Integer) As Boolean
' Se non esiste il file con il risultato
If Not My.Computer.FileSystem.FileExists(If(nInd <> 2, m_sResult, m_sResult2)) Then
If Not My.Computer.FileSystem.FileExists(m_sResult) Then
Return False
End If
' Leggo il file
@@ -487,7 +778,7 @@ Public Class Camera
Try
' Controllo errori nel file di info
Dim sLine As String = String.Empty
Dim sr As StreamReader = New StreamReader(If(nInd <> 2, m_sResult, m_sResult2))
Dim sr As StreamReader = New StreamReader(m_sResult)
Do While sr.Peek() > -1
sLine = sr.ReadLine()
sLine = sLine.Replace(" ", "")
@@ -505,19 +796,20 @@ Public Class Camera
Return bOk
End Function
Private Function ProcessIsRunning(nInd As Integer) As Boolean
Private Function ProcessIsRunning() As Boolean
Dim Procs() As Process
Procs = Process.GetProcessesByName(If(nInd <> 2, m_sCameraProcName, m_sCameraProcName2))
Procs = Process.GetProcessesByName(m_sCameraProcName)
Return (Procs.Length() > 0)
End Function
Private Sub KillProcess(nInd As Integer)
' OK: chiudo tutti i processi che hanno il nome CameraMng.exe
Private Sub KillProcess()
Dim Procs() As Process
Procs = Process.GetProcessesByName(If(nInd <> 2, m_sCameraProcName, m_sCameraProcName2))
Procs = Process.GetProcessesByName(m_sCameraProcName)
For i As Integer = 0 To Procs.Length() - 1
Procs(i).Kill()
Procs(i).WaitForExit(2000)
Next i
End Sub
End Sub
End Class