376 lines
9.0 KiB
VB.net
376 lines
9.0 KiB
VB.net
Imports System.IO
|
|
|
|
Module M_state_machine
|
|
|
|
|
|
#Region "Global Constants"
|
|
|
|
Public Const ODD As Integer = 1
|
|
Public Const EVEN As Integer = 0 ' was 2 , changed to 0 for zero based arrays
|
|
|
|
Public Const ERR_RET As Short = 0
|
|
Public Const OK_RET As Short = 1
|
|
|
|
#End Region
|
|
|
|
#Region "ENUM States"
|
|
|
|
Public Enum mach_state_Type
|
|
T_RESET = 0
|
|
T_READY = 1
|
|
T_MACHINING_1 = 2
|
|
T_END_MACHINING_1 = 3
|
|
T_MACHINING_2 = 4
|
|
T_END_MACHINING_2 = 5
|
|
T_BAD_PART = 8
|
|
End Enum
|
|
|
|
#End Region
|
|
|
|
#Region "Global Vars"
|
|
|
|
Public machine_state As mach_state_Type
|
|
Public sim_machine_state As mach_state_Type
|
|
|
|
Public b_restarting As Boolean
|
|
Public sz_start_datetime(2) As String
|
|
|
|
Public b_running As Boolean
|
|
Public sz_next_program As String
|
|
|
|
#End Region
|
|
|
|
#Region "local variables "
|
|
|
|
Private prev_machine_state As mach_state_Type
|
|
Private entry_state As Boolean
|
|
Private b_check_new_program As Boolean
|
|
|
|
|
|
|
|
Private b_machining_odd_prog As Boolean
|
|
|
|
Private sz_dest As String
|
|
Private sz_source As String
|
|
Private sz_source_s(10) As String
|
|
|
|
|
|
#End Region
|
|
|
|
Sub init()
|
|
|
|
b_running = True
|
|
|
|
machine_state = mach_state_Type.T_RESET
|
|
prev_machine_state = mach_state_Type.T_RESET
|
|
|
|
b_restarting = False
|
|
|
|
entry_state = True
|
|
|
|
b_check_new_program = False
|
|
|
|
' set the fist machining to be ODD
|
|
Call set_b_machining_odd_prog(True)
|
|
|
|
|
|
|
|
End Sub
|
|
'
|
|
' the real main state machine
|
|
'
|
|
Sub go()
|
|
|
|
'If Not b_running Then Exit Sub
|
|
|
|
'' Call Display_machine_data()
|
|
|
|
'Call M_machine.get_machine_state()
|
|
|
|
'If entry_state Then FrmMain.LblMachState.Text = Message.msg(45) ' waiting machine to get ready......
|
|
|
|
|
|
Dim ncInfo As CndexLinkDotNet.Cndex.GETINFO1DATA
|
|
ncInfo = Nothing
|
|
|
|
|
|
Dim machineStatus As Byte
|
|
Dim modeSelected As Byte
|
|
|
|
' modi/stati vedere CncOSAI riga 85
|
|
|
|
machineStatus = CnOsai.GetMachineStatus()
|
|
modeSelected = CnOsai.GetModeSelected()
|
|
|
|
|
|
' valore bitmap dello statup IOB
|
|
Dim status As Short = 0
|
|
|
|
' power on
|
|
If CnOsai.Connected Then
|
|
status += 1
|
|
End If
|
|
|
|
' RUN mode
|
|
If (machineStatus = ComCNOsai.CYCLE_ And modeSelected = ComCNOsai.AUTO) Then
|
|
status += 2
|
|
End If
|
|
|
|
' Allarme
|
|
If (machineStatus = ComCNOsai.ERRO_) Then
|
|
status += 8
|
|
End If
|
|
|
|
' Manuale
|
|
If (modeSelected <> ComCNOsai.AUTO) Then
|
|
status += 16
|
|
End If
|
|
|
|
' Allarme
|
|
If (machineStatus = ComCNOsai.EMERG_) Then
|
|
status += 32
|
|
End If
|
|
|
|
|
|
' compongo i bit di status...
|
|
Dim IobBitmap As String
|
|
IobBitmap = "--------------" + vbCrLf
|
|
IobBitmap += "Bitmap IOB:" + vbCrLf
|
|
IobBitmap += status.ToString() + vbCrLf
|
|
IobBitmap += "--------------" + vbCrLf + vbCrLf
|
|
|
|
' per leggere variabili dichiaro la struttura
|
|
Dim temp As ComCNOsai.stVAR
|
|
temp.nAddress = nVar_NC_state ' da conf che vale 352 da
|
|
temp.nBit = 0
|
|
temp.nNumCn = 1
|
|
temp.szVarName = ""
|
|
|
|
Dim risultato As Short
|
|
risultato = CnOsai.ReadShortVar(temp)
|
|
|
|
IobBitmap += vbCrLf
|
|
IobBitmap += "Variabile " + nVar_NC_state.ToString() + ": " + risultato.ToString()
|
|
|
|
|
|
FrmMain.LblMapoIOB.Text = IobBitmap
|
|
|
|
|
|
|
|
'CnOsai.NcInfo1(ncInfo)
|
|
|
|
FrmMain.LblMachState.Text = "Status:" + machineStatus.ToString() + " / Mode: " + modeSelected.ToString()
|
|
|
|
'' wait for state 0 or 1 at beginning
|
|
|
|
'If entry_state And (machine_state = mach_state_Type.T_MACHINING_1) Then Exit Sub
|
|
'If entry_state And (machine_state = mach_state_Type.T_MACHINING_2) Then Exit Sub
|
|
'If entry_state And (machine_state = mach_state_Type.T_END_MACHINING_1) Then Exit Sub
|
|
'If entry_state And (machine_state = mach_state_Type.T_END_MACHINING_2) Then Exit Sub
|
|
|
|
'entry_state = False
|
|
|
|
'Select Case machine_state
|
|
|
|
' ' _______________________ T_RESET STATE ____________________
|
|
|
|
' Case mach_state_Type.T_RESET
|
|
' FrmMain.LblMachState.Text = Message.msg(46) ' Not Ready
|
|
|
|
' '_______________________ T_READY STATE ____________________
|
|
|
|
' Case mach_state_Type.T_READY
|
|
' FrmMain.LblMachState.Text = Message.msg(47) ' Ready
|
|
' FrmMain.LblProgramName.Text = "------"
|
|
|
|
' If prev_machine_state <> mach_state_Type.T_READY Then ' state change ??
|
|
' b_check_new_program = True ' enable 1 run only after state change
|
|
' End If ' cambio di stato
|
|
|
|
' If b_check_new_program Then '
|
|
' If get_next_item_no_qty() Then
|
|
' Call start_machining()
|
|
' b_check_new_program = False
|
|
' End If
|
|
' End If ' controllo programmi disponibili abilitato
|
|
|
|
' '_______________________ T_MACHINING_1 STATE ____________________
|
|
|
|
' Case mach_state_Type.T_MACHINING_1
|
|
|
|
' FrmMain.LblMachState.Text = Message.msg(49) ' machining
|
|
|
|
' If prev_machine_state <> mach_state_Type.T_MACHINING_1 Then ' state change ??
|
|
|
|
' If prev_machine_state = mach_state_Type.T_MACHINING_2 Then ' skipped end machining 2 ??
|
|
|
|
|
|
' End If ' skipped end machining 2
|
|
|
|
' b_check_new_program = True ' enable 1 run only after state change
|
|
|
|
' ' save start time
|
|
|
|
' sz_start_datetime(ODD) = Now.ToString
|
|
' Debug.Print(" Start time " & sz_start_datetime(ODD) & " odd/even " & Str(ODD))
|
|
' Call Log.write("Start time" & sz_start_datetime(ODD) & " odd/even " & Str(ODD))
|
|
|
|
' ' here change in queue display drawing if any
|
|
' ' here change in drawing if any
|
|
' ' Call M_wmf.picture_send(True)
|
|
|
|
|
|
|
|
' End If ' state change
|
|
|
|
' Call check_and_start()
|
|
|
|
' '_______________________ T_END_MACHINING_1 STATE ____________________
|
|
|
|
' Case mach_state_Type.T_END_MACHINING_1
|
|
|
|
' FrmMain.LblMachState.Text = Message.msg(48) ' end machining
|
|
' FrmMain.LblProgramName.Text = "------"
|
|
|
|
' If prev_machine_state <> mach_state_Type.T_END_MACHINING_1 Then ' state change ??
|
|
|
|
' ' here change in drawing if any
|
|
|
|
' End If ' state change
|
|
|
|
' Call check_and_start()
|
|
|
|
' '_______________________ T_MACHINING_2 STATE ____________________
|
|
|
|
' Case mach_state_Type.T_MACHINING_2
|
|
|
|
' FrmMain.LblMachState.Text = Message.msg(49) ' machining
|
|
|
|
' If prev_machine_state <> mach_state_Type.T_MACHINING_2 Then ' state change ??
|
|
|
|
' If prev_machine_state = mach_state_Type.T_MACHINING_1 Then ' skipped end machining 1 ??
|
|
|
|
|
|
' End If ' skipped end machining 1
|
|
|
|
' b_check_new_program = True ' enable 1 run only after state change
|
|
|
|
' ' save start time
|
|
|
|
' sz_start_datetime(EVEN) = Now.ToString
|
|
' Debug.Print(" Start time " & sz_start_datetime(EVEN) & " odd/even " & Str(EVEN))
|
|
' Call Log.write("Start time" & sz_start_datetime(EVEN) & " odd/even " & Str(EVEN))
|
|
|
|
' ' here change in queue display drawing if any
|
|
' ' here change in drawing if any
|
|
' ' Call M_wmf.picture_send(False)
|
|
|
|
|
|
' End If ' state change
|
|
|
|
' Call check_and_start()
|
|
|
|
' '_______________________ T_END_MACHINING_2 STATE ____________________
|
|
|
|
' Case mach_state_Type.T_END_MACHINING_2
|
|
|
|
' FrmMain.LblMachState.Text = Message.msg(48) ' end machining
|
|
' FrmMain.LblProgramName.Text = "------"
|
|
|
|
' If prev_machine_state <> mach_state_Type.T_END_MACHINING_2 Then ' state change ??
|
|
|
|
' ' here change in drawing if any
|
|
|
|
' End If ' state change
|
|
|
|
' Call check_and_start()
|
|
|
|
' '__________________________________________
|
|
|
|
'End Select
|
|
|
|
'prev_machine_state = machine_state
|
|
|
|
End Sub
|
|
|
|
' returns the next item from the queue ( if any )
|
|
|
|
Private Function get_next_item_no_qty() As Boolean
|
|
|
|
Dim b_ret As Boolean = False
|
|
|
|
|
|
|
|
Return b_ret
|
|
|
|
End Function
|
|
|
|
Private Sub check_and_start()
|
|
|
|
If b_check_new_program Then ' available programs check enabled ??
|
|
If get_next_item_no_qty() Then
|
|
Call start_machining()
|
|
b_check_new_program = False
|
|
End If
|
|
End If ' available programs check enabled
|
|
|
|
End Sub
|
|
|
|
' some serious processing here ....
|
|
|
|
Private Sub start_machining()
|
|
|
|
End Sub
|
|
|
|
Private Sub crea_programma()
|
|
|
|
|
|
End Sub
|
|
|
|
Private Sub set_dest_program_name()
|
|
|
|
|
|
|
|
End Sub
|
|
|
|
Private Sub set_b_machining_odd_prog(ByVal b As Boolean)
|
|
|
|
|
|
End Sub
|
|
|
|
'-------------------------------------------------------------
|
|
'-------------------------------------------------------------
|
|
|
|
#Region "my funny valentine"
|
|
'
|
|
' ritorna 1 ( OK_RET ) se ok ; 0 ( ERR_RET ) se in errore
|
|
'
|
|
Function my_f_____copy_file_to_nc(ByVal sz_Pc_file_name As String, ByVal sz_Nc_file_name As String) As Short
|
|
|
|
|
|
|
|
End Function
|
|
|
|
Sub my_f_____File_Delete(ByVal sz_to_delete As String)
|
|
|
|
End Sub
|
|
|
|
'
|
|
' ritorna 1 ( OK_RET ) se ok ; 0 ( ERR_RET ) se in errore
|
|
'
|
|
Function my_f_____copy_file_from_nc(ByVal sz_Nc_file_name As String, ByVal sz_Pc_file_name As String) As Short
|
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
Private Sub Display_machine_data()
|
|
|
|
|
|
End Sub
|
|
|
|
End Module
|