Files
OmagCUT/M_Num_old.vb
T
Emmanuele Sassi 8f912cae70 OmagCUT :
- Miglioramento comunicazione per prove su macchina.
- Aggiunto componente checkbox nel dictionary.
- Usato checkbox per parametro di lavorazione inveti.
2015-11-20 09:03:31 +00:00

1379 lines
39 KiB
VB.net

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Namespace Num
Public Class NumNCOld
Inherits CN_generico
' Riferimento alla MainWindow
Private m_MainWindow As MainWindow = Application.Current.MainWindow
#Region " Classes"
#End Region
#Region " Enum"
Enum eStatetype As Int16
NOT_INIT = -999
READY = 0
BUSY = -998
End Enum
#End Region
#Region " Constants"
Const SLEEP_TIME = 100
Const A_AXIS As Short = 6
Const RET_OK As Int16 = 0
' modi NUM Axium
Const AUTO_M = 0, SINGLE_M = 1, MDI_M = 2, DRYRUN_M = 3, SEARCH_M = 4, EDIT_M = 5, TEST_M = 6
Const MANUAL_M = 7, MOS_M = 8, SHIFTS_M = 9, TLCOMP_M = 10, LOAD_M = 13, UPLOAD_M = 15
Const V0 = &HA000, V1 = &HA001, V2 = &HA002, V3 = &HA003, V4 = &HA004, V5 = &HA005, V6 = &HA006, V7 = &HA007
Const VBY = &HA040, VW = &HA041, VL = &HA042 'VB4 doesn't accepte VB (-->VBY )
Const M0 = &HA100, M1 = &HA101, M2 = &HA102, M3 = &HA103, M4 = &HA104, M5 = &HA105, M6 = &HA106, M7 = &HA107
Const MB = &HA140, MW = &HA141, ML = &HA142
'Global Const C0=*0xA200
'C1,C2,C3,C4,C5,C6,C7,
Const CB = &HA240, CW = &HA241, CL = &HA242
Const R0 = &HA400, R1 = &HA401, R2 = &HA402, R3 = &HA403, R4 = &HA404, R5 = &HA405, R6 = &HA406, R7 = &HA407
Const RB = &HA440, RW = &HA441, RL = &HA442
Const W0 = &HA500, W1 = &HA501, W2 = &HA502, W3 = &HA503, W4 = &HA504, W5 = &HA505, W6 = &HA506, W7 = &HA507
Const WB = &HA540, WW = &HA541, WL = &HA542
Const I0 = &HA800, I1 = &HA801, I2 = &HA802, I3 = &HA803, I4 = &HA804, I5 = &HA805, I6 = &HA806, I7 = &HA807
Const IB = &HA840, IW = &HA841, IL = &HA842
Const Q0 = &HA900, Q1 = &HA901, Q2 = &HA902, Q3 = &HA903, Q4 = &HA904, Q5 = &HA905, Q6 = &HA906, Q7 = &HA907
Const QB = &HA940, QW = &HA941, QL = &HA942
Const SYN = 0 ' /* synchrone */
Const ASS = 1 ' /* assynchrone send request */
Const ASR = 2 ' /* assynchrone read response */
Const CTRL_AXES = 143
Const SPINDLE_SPEED = 144
Const SPINDLE_POS = 145, H_VAR = 147, MOS_OK = 149
Const E80000 = 150, E81000 = 151, E82000 = 152, E30000 = 166, E40000 = 167, M_DECOD = 168, DATA_PROG = 226
Const Mode = 180, ACTIVE_PROG = 181
Const REF = 128, MES = 129, DAT1 = 130, DAT2 = 131, DAT3 = 132, MIN_LIM = 133, MAX_LIM = 134, VARH = 147
Const TILT = 135, MACH_ORIGIN = 136, P17_MIN = 137, P17_MAX = 138, REF_COR = 139, REF_POS = 140, MES_POS = 141
Const TMACRO1 = &H31, TMACRO2 = &H32, TMACRO3 = &H33
Const TUT6 = 6, TLAD = 7, TIHM = 8, TNC = 12, TPAR = 5, TCALIBR = 2, TMACRO = 11, TUTIL = 13, TPASSANT = 12
Const TSi = 1, TFi = 2, SPi = 3, THi = 4, INI = 5, TABSYMB = 10, ALLMODULE = 16, CMODULE = 65, TXTFILE = 97
Const IHMFNT = 98, IHMBMP = 99, IHMRSC = 100, IHMINI = 101, IHMTXT = 102, IHMICO = 103, IHMCOD = 104
#End Region
#Region " Structures"
Structure tDNC20_Position_OPOM
Dim Valid As Byte
Dim Position As Long
Dim ToGo As Long
Dim offset As Long
End Structure
Structure tDNC20_Axes
' Dim axe(0 To 8) As tDNC20_Position_OPOM
Dim axe() As tDNC20_Position_OPOM
End Structure
Structure tDNC20_Spindle_i
Dim Valid As Byte
Dim Spindle As Long
End Structure
Structure tDNC20_Spindle
' Dim Data(0 To 3) As tDNC20_Spindle_i
Dim Data() As tDNC20_Spindle_i
End Structure
Structure tCorOutil
Dim L_X As Long
Dim RTore_Z As Long
Dim R_Radus As Long
Dim DL_DX As Long
Dim DR_DZ As Long
Dim Direc As Long
Dim Type As Long
End Structure
Public Structure My_data_struct
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> _
Public data As Byte()
End Structure
#End Region
#Region " Variabili "
Public Var600A As Byte
Public Var600B As Byte
Public Var600C As Byte
Public Var600D As Byte
Public Var600E As Byte
Public Var600F As Byte
Public var6010L As Long
Public var6014L As Long
Public var6018L As Long
Public var601CL As Long
Public var6020L As Long
Public var6024L As Long
Public var6028L As Long
Public var602CL As Long
Private iFirstVar As UInt16
Private n_portNC As Int16
Private Vmminch As Long = 1000
Private NumCifreDecP4 As Long = 1000
Private aTimer As System.Timers.Timer
Private b_busy As Boolean = False
Private b_OM_pos As Boolean = True
Private global_state As eStatetype = eStatetype.NOT_INIT
Private MyData As My_data_struct
Private MyData2 As My_data_struct
Private l_active_program As Long ' /* active CNC program number */
Private l_GFunction As Long ' /* G functions running */
Private n_BlocExe As UInt16 ' ; /* current block number */
Private n_ProgError As Int16 ' ; /* CNC error number detected */
Private n_BlocError As UInt16 ' ; /* block number where the error was detected */
Private n_Tool As UInt16 ' ; /* current tool number (T) */
Private n_Direction As UInt16 ' ; /* current tool direction */
Private n_Corrector As UInt16 ' ; /* current tool offset number (D) */
Private n_LeftFunct As UInt16 ' ; /* functions to be executed after current movement (see LADDER documentation) */
Private n_ErrorNumber As UInt16 ' //Error number
Private n_ErrorBlockNum As UInt16 ' //Block number in error
Private n_ReadStatus As UInt16 ' //Read Status: 0x0F=end of message 0x06=follow-up
Private n_MsgSize As UInt16 ' //Number of characters in the message
Private MsgTab(123) As Byte ' //Message read
#End Region
#Region " DLL import"
Declare Function SetPLCTool Lib "LIB_UNIT2.DLL" (ByVal chinit As String) As Int16
Declare Function Get_Port Lib "LIB_UNIT2.DLL" (ByRef Port As Int16) As Int16
Declare Function Free_Port Lib "LIB_UNIT2.DLL" (ByVal Port As Int16) As Int16
Declare Function Close_Unite Lib "LIB_UNIT2.DLL" () As Int16
Declare Function WriteObjectVarious2 Lib "dnc2.DLL" (ByVal Port As Int16, ByVal qui As UInt16, ByRef pData As Int32) As Int16
Declare Function ReadObjectVarious2 Lib "dnc2.DLL" (ByVal Port As Int16, ByVal qui As UInt16, ByRef pData As Int32, ByVal Mode As UInt16) As Int16
' Declare Function WriteLadderVar Lib "dnc2.DLL" (ByVal Port As Int16, ByVal qui As UInt16, ByVal num As Int16, ByVal Nb As Int16, ByRef pData As Int32) As Int16
Declare Function StartNC Lib "dnc2.dll" (ByVal Port As Int16) As Int16
Declare Function StopNC Lib "dnc2.dll" (ByVal Port As Int16) As Int16
Declare Function InitNC Lib "dnc2.dll" (ByVal Port As Int16) As Int16
Declare Function WriteTool Lib "dnc2.dll" (ByVal Port As Int16, ByVal number As Integer, ByVal Quantity As Integer, AdrData As tCorOutil) As Int16
Declare Function ReadTool Lib "dnc2.dll" (ByVal Port As Int16, ByVal number As Integer, ByVal Quantity As Integer, ByRef d As My_data_struct, ByVal Mode As UInt16) As Int16
Declare Function DNC20_DialWithModes_2 Lib "dnc20_2.dll" (ByVal Port As Int16, ByVal pstring As String, ByVal Mode As UInt16) As Int16
Declare Function DNC20_Spindle Lib "dnc20_2.dll" (ByVal Port As Int16, ByVal Group As Int16, ByRef pData As tDNC20_Spindle, ByVal Mode As UInt16) As Int16
Declare Function ReadLadderVar Lib "dnc2.DLL" (ByVal Port As Int16, ByVal qui As UInt16, ByVal num As UInt16, ByVal Nb As UInt16, ByRef d As My_data_struct, ByVal Mode As UInt16) As Int16
Declare Function UpLoadFile Lib "dnc2.dll" (ByVal Port As Int16, ByVal prog As Int32, ByVal filename As String) As Int16
Declare Function DownLoadFile Lib "dnc2.dll" (ByVal Port As Int16, ByVal prog As Int32, ByVal filename As String) As Int16
Declare Function DncDeleteFile Lib "dnc2.dll" (ByVal Port As Int16, ByVal prog As Int32) As Int16
Declare Function DNC20_Position_OM Lib "dnc20_2.dll" (ByVal Port As Int16, ByVal Groupe As Int16, ByRef d As My_data_struct, ByVal Mode As UInt16) As Int16
Declare Function DNC20_Position_OP Lib "dnc20_2.dll" (ByVal Port As Int16, ByVal Groupe As Int16, ByRef d As My_data_struct, ByVal Mode As UInt16) As Int16
Declare Function ReadObjectVarious4 Lib "dnc2.dll" (ByVal Port As Int16, ByVal qui As UInt16, ByVal Prem As UInt16, ByVal Quantity As UInt16, ByRef d As My_data_struct, ByVal Mode As UInt16) As Int16
Declare Function WriteObjectVarious4 Lib "dnc2.dll" (ByVal Port As Int16, ByVal qui As UInt16, ByVal Prem As UInt16, ByVal Quantity As UInt16, ByRef d As My_data_struct) As Int16
Declare Function ReadMemoryFree Lib "dnc2.dll" (ByVal port As Int16, ByRef pData As Long, ByVal zone As Int16) As Int16
Declare Function ReadProgStatus Lib "dnc2.dll" (ByVal port As Int16, ByVal PremGr As Int16, ByVal NbGr As Int16, ByRef d As My_data_struct, ByVal Mode As Int16) As Int16
Declare Function DNC40_ReadCncError Lib "dnc40_2.dll" (ByVal Port As Int16, ByVal Group As UInt16, ByVal ErrorLineNum As Int16, ByRef d As My_data_struct, ByVal Mode As Int16) As Int16
'.
#End Region
#Region " Constructor"
Sub New()
Dim nret As Integer
sz_NC_error_messages = New List(Of String)
' !!!!!!!!!!!!!!!!!!!!!!!!!1 da leggere da file di configurazione !!!!!!!
'nret = NC_connect("COM")
nret = NC_connect("XIP01, 0, 10, 0, 0, 0")
' Create a timer and set an half second interval.
aTimer = New System.Timers.Timer()
aTimer.Interval = 500 ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' Hook up the Elapsed event for the timer.
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
aTimer.AutoReset = True ' Have the timer fire repeated events (true is the default)
aTimer.Enabled = True ' Start the timer
End Sub
Private Sub OnTimedEvent(source As Object, e As System.Timers.ElapsedEventArgs)
If Not b_busy Then
aTimer.Enabled = False
b_busy = True
Call timer_read_var() ' leggo un mucchio di variabili in un colpo solo
Call Read_machine_pos() ' leggo posizioni assi
Call get_errors() ' leggo eventueli errori PLC e CN
b_busy = False
aTimer.Enabled = True
End If
End Sub
Function NC_connect(sz_connect_string As String)
Dim nret As Integer
Dim msga As String
'nret = SetPLCTool("XIP01, 0, 10, 0, 0, 0")
'nret = SetPLCTool("COM")
nret = SetPLCTool(sz_connect_string)
If nret <> 0 Then
msga = " Communication not availabe - ret = " & nret.ToString & " - " & sz_connect_string
MsgBox(msga, vbExclamation, "SetPLCTool")
End
End If
'Richiedo porta comunicazione PC-CN 2
' iport2 = 1
nret = Get_Port(n_portNC)
If nret <> 0 Then
Beep()
msga = " Gate 2 not available "
MsgBox(msga, vbOKOnly, "Get_Port - ret = " & nret.ToString)
End
End If
' eventualmente aggiungere apertura porta per PPP
'iport3 = 3
'nret = Get_Port(iport3)
global_state = eStatetype.READY
Return nret
End Function
Function NC_disconnect()
Dim nret As Integer
nret = Free_Port(n_portNC)
'nret = Close_Unite()
' eventualmente pchidere porta per PPP
' Free_Port(iport3)
Return nret
End Function
#End Region
Function timer_read_var()
Dim nret As Int16 = -1
If global_state <> eStatetype.READY Then
Return global_state
Exit Function
Else
global_state = eStatetype.BUSY
End If
'lettura variabili da %V600A.B a %V600D.B tramite un solo accesso in memoria per %V600A.B e lettura di 4 in serie
iFirstVar = &H600A
nret = ReadLadderVar(n_portNC, VBY, iFirstVar, 5, MyData, SYN)
If nret = 0 Then
Var600A = MyData.data(0) ' Feed_override
Var600B = MyData.data(1) ' spindle_override
Var600C = MyData.data(2)
Var600D = MyData.data(3) ' active_mode
Var600E = MyData.data(4)
b_feed_override_changed = True
d_DInterpo_Feed_override = Math.Round(Var600A * 120.0 / 255, 0)
m_MainWindow.m_CNCommunication.m_CN.b_spindle_data_changed = True
n_spindle_override(0) = Math.Round((Var600B * 50 / 255) + 50)
End If
'Fine lettura %V600D.B
' lettura variabile assorbimento mandrino ( %V250F )
iFirstVar = &H250F
nret = ReadLadderVar(n_portNC, VW, iFirstVar, 1, MyData, SYN)
If nret = 0 Then
d_spindle_current = CDbl(BitConverter.ToInt16(MyData.data, 0)) / 10.0
End If
'lettura variabile S effettiva
iFirstVar = &H2600
nret = ReadLadderVar(n_portNC, VL, iFirstVar, 1, MyData, SYN)
If nret = 0 Then
d_spindle_eff(0) = CDbl(BitConverter.ToInt32(MyData.data, 0)) ' progr. Feed
End If
'lettura variabili da %V6010.L a %V601C.L
iFirstVar = &H6010
nret = ReadLadderVar(n_portNC, VL, iFirstVar, 4, MyData, SYN)
If nret = 0 Then
var6010L = BitConverter.ToInt32(MyData.data, 0) ' progr. Feed
var6014L = BitConverter.ToInt32(MyData.data, 4) ' progr. speed
var6018L = BitConverter.ToInt32(MyData.data, 8)
var601CL = BitConverter.ToInt32(MyData.data, 12)
End If
d_DInterpo_Prog_Feed = CDbl(var6010L)
d_spindle_prog(0) = CDbl(var6014L)
'lettura variabili da %V6020.L a %V602C.L
iFirstVar = &H6020
nret = ReadLadderVar(n_portNC, VL, iFirstVar, 4, MyData, SYN)
If nret = 0 Then
var6020L = BitConverter.ToInt32(MyData.data, 0)
var6024L = BitConverter.ToInt32(MyData.data, 4) ' potenziometro tablet
var6028L = BitConverter.ToInt32(MyData.data, 8) ' disponibile
var602CL = BitConverter.ToInt32(MyData.data, 12) ' disponibile
End If
global_state = eStatetype.READY
Return nret
End Function
Private Function set_NC_mode(n_mode As Integer) As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
nret = WriteObjectVarious2(n_portNC, Mode, n_mode) ' 0 AUTO 1 SEQUENZIALE 2 IMD 7 MANUALE
global_state = eStatetype.READY
Return nret
End Function
Private Function set_MDI_command(sz_command As String) As Int16
Dim nret As Int16 = -1
Dim nret2 As Int16 = -1
Dim nret3 As Int16 = -1
If global_state <> eStatetype.READY Then
Return global_state
Exit Function
Else
global_state = eStatetype.BUSY
End If
nret = WriteObjectVarious2(n_portNC, Mode, MDI_M) ' SELEZIONE MODO IMD
If nret = 0 Then
nret2 = DNC20_DialWithModes_2(n_portNC, sz_command, SYN) ' PASSO IL COMANDO SU UN BUFFER
If nret2 = 0 Then
nret3 = StartNC(n_portNC) ' DO IL CICLO
If nret3 = 0 Then
nret = WriteObjectVarious2(n_portNC, Mode, MANUAL_M) ' ' SELEZIONO MODO MANUALE
Else
nret = nret3 + 3000 ' codice di errore della StartNC
End If ' If nret3 = 0
Else
nret = nret2 + 2000 ' codice di errore della DNC20_DialWithModes_2
End If ' If nret2 = 0
End If ' If nret = 0
global_state = eStatetype.READY
Return nret
End Function
Function Read_machine_pos()
Dim nret As Int16
Dim i As Short, n As Short
If global_state <> eStatetype.READY Then
Return global_state
Exit Function
Else
global_state = eStatetype.BUSY
End If
If (b_OM_pos) Then ' quote rispetto a 0 Macchina
nret = DNC20_Position_OM(n_portNC, 0, MyData, SYN)
Else ' quote rispetto A 0 Pezzo
nret = DNC20_Position_OP(n_portNC, 0, MyData, SYN)
End If
For i = 0 To MAX_AXES - 2 ' la costante è 10 per cui per fare da 0 a 8....
n = i * 16
b_axis_valid(i) = (MyData.data(n) <> 0)
If (i < A_AXIS) Then
d_axis_position(i) = (BitConverter.ToInt32(MyData.data, n + 4)) / Vmminch ' X
d_axis_delta(i) = (BitConverter.ToInt32(MyData.data, n + 8)) / Vmminch
Else
d_axis_position(i) = (BitConverter.ToInt32(MyData.data, n + 4)) / NumCifreDecP4 ' A
d_axis_delta(i) = (BitConverter.ToInt32(MyData.data, n + 8)) / NumCifreDecP4
End If
Next
If b_axis_events_enable Then
MyBase.OnNewPositionData()
MyBase.OnNewPosDeltaData()
End If
global_state = eStatetype.READY
Return nret
End Function
#Region " Metodi pubblici"
Public Overrides Sub ReadEls_Add_Parameter(sz_var As String, n_par As Short)
End Sub
'
' call DVariables_WriteVariables("E80000;E80001" , "1;2" )
'
Public Overrides Sub DVariables_WriteVariables(sz_parameters As String, sz_values As String)
End Sub
Public Overrides Sub DVariables_WriteVariables2(sz_parameters As String, sz_values As String)
End Sub
Public Overrides Sub MDI_command()
Dim nret As Int16 = set_MDI_command(sz_ManualDataInput)
If nret <> 0 Then
MessageBox.Show("Error Execute MDI Command :" + " " + nret.ToString())
End If
End Sub
'
' Activate program
' returns 0 = OK ; > 0 error
'
Public Overrides Function ActivateProgram(n_part_program As Integer) As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
nret = WriteObjectVarious2(n_portNC, Mode, AUTO_M) ' potrebbe essere anche modo 11 !
If nret = 0 Then
nret = WriteObjectVarious2(n_portNC, ACTIVE_PROG, n_part_program) ' notare : numero non moltiplicato * 10
End If
If nret <> 0 Then
MessageBox.Show("Error in Activate program :" + " " + nret.ToString())
End If
global_state = eStatetype.READY
Return nret
End Function
'
' Set DPOsition Mode OP/OM
'
Public Overrides Sub set_OP_OM(n As Short)
End Sub
'
' Read Once position
' returns 0 = OK ; > 0 error
'
Public Overrides Function DPOsition_ReadOnce() As Int16
Return 1
End Function
'
' Set Cycle Start
'
Public Overrides Function DGeneralFunctions_CycleStart() As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
nret = StartNC(n_portNC)
global_state = eStatetype.READY
Return nret
End Function
'
' Set Feed Hold
'
Public Overrides Function DGeneralFunctions_FeedHold() As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
nret = StopNC(n_portNC)
global_state = eStatetype.READY
Return nret
End Function
'
' Set NC Reset
'
Public Overrides Function DGeneralFunctions_Reset() As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
nret = InitNC(n_portNC)
global_state = eStatetype.READY
Return nret
End Function
Public Overrides Function DGeneralFunctions_WriteCncMode(nmode As Short) As Int16
Dim nret As Int16 = -1
nret = set_NC_mode(nmode)
Return nret
End Function
Public Overrides Function Write_var_1(sz_par As String, lvalue As Long) As Int16
Dim nret As Int16 = -1
Dim n_what As UInt16
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
If sz_par = "E80000" Then ' !!! da sistemare per beccare anche gli altri indirizzi
n_what = E80000
MyData.data = BitConverter.GetBytes(lvalue)
nret = WriteObjectVarious4(n_portNC, n_what, 0, 1, MyData)
Else
nret = -997
End If
global_state = eStatetype.READY
Return nret
End Function
'
' da PC a CN
'
Public Overrides Function Download_NC_prog(sz_PC_filename As String, sz_NC_filename As String) As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
Dim l As Long = get_Num_prog_number(sz_NC_filename)
' nret = DncDeleteFile(iport2, l)
nret = DownLoadFile(n_portNC, l, sz_PC_filename)
global_state = eStatetype.READY
Return nret
End Function
'
' da CN a pc
'
Public Overrides Function Upload_NC_prog(sz_PC_filename As String, sz_NC_filename As String) As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
Dim l As Long = get_Num_prog_number(sz_NC_filename)
nret = UpLoadFile(n_portNC, l, sz_PC_filename)
global_state = eStatetype.READY
Return nret
End Function
Private Function get_Num_prog_number(sz_in As String) As Long
Dim sz_n As String = sz_in
Dim l_prog_num As Long
If InStr(sz_n, "%") Then sz_n = sz_n.Replace("%", "")
If InStr(sz_n, ".") Then
sz_n = sz_n.Replace(".", "")
l_prog_num = CLng(sz_n)
Else
l_prog_num = CLng(sz_n) * 10
End If
Return l_prog_num
End Function
Public Overrides Function Delete_NC_prog(sz_NC_filename As String) As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
Dim l As Long = get_Num_prog_number(sz_NC_filename)
nret = DncDeleteFile(n_portNC, l)
global_state = eStatetype.READY
Return nret
End Function
Public Overrides Function Start_Transfer_NC_prog() As Int16
Return 0
End Function
Public Overrides Function DTool_set_read_range(n_start As Short, n_stop As Short) As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
nret = ReadTool(n_portNC, n_start, 1, MyData, SYN)
If nret = RET_OK Then
Tools(0).lenght = 0 ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Tools(0).radius = 0
Tools(0).comp_num = 0
b_Tool_data_changed = True
End If
global_state = eStatetype.READY
Return nret
End Function
Public Overrides Function DTool_write_tool(n_tool_number As Short, Length_X As Double, Radius As Double, TipRadius_Z As Double,
DLength_X As Double, DTipRadius_Z As Double,
nDirection As Short, nType As Short, nH As Integer) As Int16
Dim Tool As tCorOutil
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
' da rifare !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Tool.L_X = CLng(Length_X * 1000)
Tool.R_Radus = CLng(Radius * 1000)
Tool.RTore_Z = CLng(TipRadius_Z * 1000)
Tool.DL_DX = 0
Tool.DR_DZ = 0
Tool.Direc = 0
Tool.Type = 0
nret = WriteTool(n_portNC, n_tool_number, 1, Tool)
global_state = eStatetype.READY
Return nret
End Function
Public Function readE80000() As Int16 ' temporanea di prova .....
Dim nret As Int16 = -1
Dim ldata As Int32
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
nret = ReadObjectVarious4(n_portNC, E80000, 0, 1, MyData, SYN)
If nret = 0 Then
ldata = BitConverter.ToInt32(MyData.data, 0)
End If
global_state = eStatetype.READY
Return nret
End Function
Public Overrides Function get_free_memory(n_zone As Int16) As Long
'
'
' usare zona 0
'
Dim nret As Int16 = -1
Dim l_free_mem As Long
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
nret = ReadMemoryFree(n_portNC, l_free_mem, n_zone)
global_state = eStatetype.READY
If nret = 0 Then
Return l_free_mem
Else
Return -9999
End If
End Function
Public Overrides Function read_active_mode() As Int16
Return (Var600D) ' es 0 = auto, ecc.
End Function
Public Overrides Function get_program_status() As Int16
Dim nret As Int16 = -1
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
nret = ReadProgStatus(n_portNC, 0, 1, MyData, SYN)
If nret = 0 Then
l_GFunction = (BitConverter.ToInt32(MyData.data, 0))
l_active_program = (BitConverter.ToInt32(MyData.data, 4))
n_BlocExe = (BitConverter.ToInt16(MyData.data, 8))
n_ProgError = (BitConverter.ToInt16(MyData.data, 10))
n_BlocError = (BitConverter.ToInt16(MyData.data, 12))
n_Tool = (BitConverter.ToInt16(MyData.data, 14))
n_Direction = (BitConverter.ToInt16(MyData.data, 16))
n_Corrector = (BitConverter.ToInt16(MyData.data, 18))
n_LeftFunct = (BitConverter.ToInt16(MyData.data, 20))
End If
global_state = eStatetype.READY
Return nret
End Function
Public Overrides Function get_plc_messages() As Int16
Return get_errors()
End Function
Private Function get_errors() As Int16
Const GROUP_ACTIVE As UInt16 = &HFFFF ' 0xFFFF=Groupe Actif
Const MORE_MESSAGES As UInt16 = 6
Const NO_MORE_MESSAGES As UInt16 = 15
Dim nret As Int16 = -1
Dim nErrorLineNum As Int16 = 0
Dim b_int_NC_error As Boolean = False
sz_PLC_error_messages = "PLC Errors : "
Do While global_state = eStatetype.BUSY
System.Threading.Thread.Sleep(SLEEP_TIME)
Loop
global_state = eStatetype.BUSY
' PLC errors
b_PLC_error = False
iFirstVar = &H7000 ' messaggio 0 " MACCHINA OK "
nret = ReadLadderVar(n_portNC, VBY, iFirstVar, 100, MyData, SYN) ' max 120 bytes....
If nret = 0 Then ' 253 = troppi dati
For i As Short = 0 To 100 - 1
If MyData.data(i) <> 0 Then
b_PLC_error = True
sz_PLC_error_messages = sz_PLC_error_messages & " " & i.ToString
End If
Next
iFirstVar = &H7000 + 100 ' messaggio 100
nret = ReadLadderVar(n_portNC, VBY, iFirstVar, 50, MyData2, SYN)
If nret = 0 Then ' 253 = troppi dati
For i As Short = 0 To 50 - 1
If MyData2.data(i) <> 0 Then
b_PLC_error = True
sz_PLC_error_messages = sz_PLC_error_messages & " " & (i + 100).ToString
End If
Next
End If
End If
'--------------------------------------------------------------------------
' Visualizzazione errore CN
b_NC_error = False
b_int_NC_error = False
iFirstVar = &H3
nret = ReadLadderVar(n_portNC, R6, iFirstVar, 1, MyData, SYN)
If MyData.data(0) <> 0 Then
b_int_NC_error = True
End If
If b_int_NC_error Then
sz_NC_error_messages.Clear()
nErrorLineNum = 0
n_ReadStatus = MORE_MESSAGES
While (n_ReadStatus = MORE_MESSAGES)
nret = DNC40_ReadCncError(n_portNC, GROUP_ACTIVE, nErrorLineNum, MyData, SYN)
If nret = 0 Then
' ErrorNumber As Integer 'Numéro d'erreur
' ErrorBlockNum As Integer 'Numéro de bloc en erreur
' ReadStatus As Byte 'Status de lecture: 0x0F=pas de suite 0x06=suite
' MsgSize As Byte 'Nombre de caractères dans le message
' MsgTab As String * 122 'Message lu
n_ErrorNumber = (BitConverter.ToInt16(MyData.data, 0))
n_ErrorBlockNum = (BitConverter.ToInt16(MyData.data, 2))
n_ReadStatus = MyData.data(4)
n_MsgSize = MyData.data(5)
For i As Short = 0 To n_MsgSize - 1
MsgTab(i) = MyData.data(i + 6)
Next
MsgTab(n_MsgSize) = 0
If n_ErrorNumber <> 0 Then
sz_NC_error_messages.Add(System.Text.ASCIIEncoding.ASCII.GetString(MsgTab))
End If
For i As Short = 0 To 122 - 1
MsgTab(i) = 0
Next
nErrorLineNum = nErrorLineNum + 1
Else
n_ReadStatus = NO_MORE_MESSAGES
End If
End While
b_NC_error = True
End If
global_state = eStatetype.READY
Return nret
End Function
#Region "fuffa"
#If 0 Then
Attribute VB_Name = "Var"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim LineaStringaV As String
Dim iV As Integer
Dim jV As Integer
Dim NomeOggettoV(40) As String
Dim NomeCaptionV(40) As String
Dim TestoCommentoV(40) As String
Dim iport2 As Integer
Dim NumeroRigheLetteRusso As Integer
Private Sub Form_Unload(Cancel As Integer)
Assi1.Timer1.Enabled = True
End Sub
'-------------------------
'Pulsanti in Pagina VAR
'-------------------------
Private Sub Leggi_Click()
Dim StringaDaInserire As String
If LineaDialogo <> "" Then
StringaDaInserire = LineaDialogo.Text
iret = DNC20_DialWithModes_2(iport2, StringaDaInserire, SYN)
LineaDialogo.Text = ""
End If
End Sub
Private Sub pf1_Click()
Pagina = 1
End Sub
Private Sub pf2_Click()
Pagina = 2
End Sub
Private Sub pf3_Click()
Pagina = 3
End Sub
Private Sub pf4_Click()
Pagina = 4
End Sub
Private Sub pf5_Click()
Pagina = 5
End Sub
Private Sub RichiamaEVar_Click()
Unload Var
VarE.Show
End Sub
Private Sub StopPul_Click()
iret = StopNC(iport2)
End Sub
Private Sub TastRaz_Click()
iret = InitNC(iport2)
End Sub
Private Sub CicloStart_Click()
iret = StartNC(iport2)
End Sub
Private Sub F7var_Click()
iret = Free_Port(iport2)
Assi1.Timer1.Enabled = True
Unload Var
Assi1.Show
End Sub
Private Sub Form_Load()
'Scrittura testo nel Assi1
Label4.Font.Charset = TipoFont
RichiamaEVar.Font.Charset = TipoFont
okassiv(9).Font.Charset = TipoFont
Var.Caption = NomeCaptionV(0)
Label4.Caption = NomeCaptionV(1)
PF1.ToolTipText = TestoCommentoV(2)
PF2.ToolTipText = TestoCommentoV(3)
PF3.ToolTipText = TestoCommentoV(4)
PF4.ToolTipText = TestoCommentoV(5)
PF5.ToolTipText = TestoCommentoV(6)
LineaDialogo.ToolTipText = TestoCommentoV(7)
LEGGI.ToolTipText = TestoCommentoV(8)
'MODOCONT* CONT'=NomeCaptionV(9)
'MODOSEQ* SEQ'=NomeCaptionV(10)
'MODOIMD* IMD'=NomeCaptionV(11)
'MODORAP* RAP'=NomeCaptionV(12)
'MODORNS* RNS'=NomeCaptionV(13)
'MODOMODIF* MODIF'=NomeCaptionV(14)
'MODOTEST* TEST'=NomeCaptionV(15)
'MODOMAN* MAN'=NomeCaptionV(16)
'MODOPOM* POM'=NomeCaptionV(17)
'MODORIF* RIF'=NomeCaptionV(18)
'MODOIN* IN%'=NomeCaptionV(19)
'MODOLOAD* OUT%'=NomeCaptionV(20)
'MODOTSET* TL SET'=NomeCaptionV(21)
'TIPOJOG* JOG'=NomeCaptionV(22)
'TIPOJOGV* Volantivo'=NomeCaptionV(23)
'INTER* INTER'=NomeCaptionV(24)
'INPOS* IN POS'=NomeCaptionV(25)
'Okassi* Ok Assi'=NomeCaptionV(26)
'StopPul* STOP'=NomeCaptionV(27)
RichiamaEVar.Caption = NomeCaptionV(28)
Private Sub Timer2_Timer()
Dim pVarR As Byte
Dim pVarRj As Byte
Dim pVarRjo As Byte
Dim pVarRErr As Byte
Dim le As tDNC20_ObjectList4
Dim leV As tDNC20_ObjectList4
Dim leV2 As tDNC20_ObjectList4
Static VarLxxx As tDNC20_SingleList
Static ModoAttivo As tDNC20_LongList
Dim Vmminch As Long
If mminchv(10) = "mm" Then
Vmminch = 1000
Else
Vmminch = 25400
End If
'Visualizzazione E41000=Modo Attivo
le.Data(0).ElemNum = 4
le.Data(0).First = 1000
le.Data(0).Quantity = 1
iret = DNC20_ReadExxxxx(iport2, 0, 1, le, ModoAttivo, SYN)
Select Case ModoAttivo.Data(1)
Case Is = 0
Label1Var(0).Caption = NomeCaptionV(9)
Case Is = 1
Label1Var(0).Caption = NomeCaptionV(10)
Case Is = 2
Label1Var(0).Caption = NomeCaptionV(11)
Case Is = 3
Label1Var(0).Caption = NomeCaptionV(12)
Case Is = 4
Label1Var(0).Caption = NomeCaptionV(13)
Case Is = 5
Label1Var(0).Caption = NomeCaptionV(14)
Case Is = 6
Label1Var(0).Caption = NomeCaptionV(15)
Case Is = 7
Label1Var(0).Caption = NomeCaptionV(16)
Case Is = 8
Label1Var(0).Caption = NomeCaptionV(17)
Case Is = 9
Label1Var(0).Caption = NomeCaptionV(18)
Case Is = 10
Label1Var(0).Caption = NomeCaptionV(21)
Case Is = 13
Label1Var(0).Caption = NomeCaptionV(19)
Case Is = 15
Label1Var(0).Caption = NomeCaptionV(20)
Case Else
Label1Var(0).Caption = " "
End Select
' Visualizzazione errore CN??
iFirstVar = &H3
iret = ReadLadderVar(iport2, R6, iFirstVar, 1, pVarRj, SYN)
If pVarRj = 128 Then
MessErrVar(5).Caption = "CN??"
Else
MessErrVar(5).Caption = " "
End If
' Visualizzazione tipo di JOG
iFirstVar = &H15
iret = ReadLadderVar(iport2, RB, iFirstVar, 1, pVarRjo, SYN)
Select Case pVarRjo
Case Is = 6
JogVar(2).Caption = NomeCaptionV(22)
Case Is = 5
If Vmminch = 1000 Then
JogVar(2).Caption = "10mm"
Else
JogVar(2).Caption = "1 inch"
End If
Case Is = 4
If Vmminch = 1000 Then
JogVar(2).Caption = "1mm"
Else
JogVar(2).Caption = "1 inch"
End If
Case Is = 3
If Vmminch = 1000 Then
JogVar(2).Caption = "0.1mm"
Else
JogVar(2).Caption = "0.1 inch"
End If
Case Is = 2
If Vmminch = 1000 Then
JogVar(2).Caption = "0.01mm"
Else
JogVar(2).Caption = "0.01 inch"
End If
Case Is = 1
If Vmminch = 1000 Then
JogVar(2).Caption = "0.001mm"
Else
JogVar(2).Caption = "0.001 inch"
End If
Case Is = 8
JogVar(2).Caption = NomeCaptionV(23)
Case Else
JogVar(2).Caption = " "
End Select
' Visualizzazione HOLD
iFirstVar = &H3
iret = ReadLadderVar(iport2, R1, iFirstVar, 1, pVarRj, SYN)
If pVarRj = 128 Then
holdv(7).Caption = "HOLD"
Else
holdv(7).Caption = " "
End If
'Visualizzazione Assi OK
iQuantityVar = 1
iFirstVar = &H4
iret = ReadLadderVar(iport2, W0, iFirstVar, iQuantityVar, pVarR, SYN)
If pVarR = 128 Then
okassiv(9).Caption = NomeCaptionV(26)
Else
okassiv(9).Caption = NomeCaptionV(27)
End If
'Visualizzazione mm inch
iQuantityVar = 1
iFirstVar = &H4
iret = ReadLadderVar(iport2, W5, iFirstVar, iQuantityVar, pVarR, SYN)
If pVarR = 0 Then
mminchv(10).Caption = "mm"
Else
mminchv(10).Caption = "Inch"
End If
' Visualizzazione M02
iFirstVar = &H3
iret = ReadLadderVar(iport2, R2, iFirstVar, 1, pVarR, SYN)
If pVarR = 128 Then
ciclov(8).Caption = "CYCLE"
Else
iret = ReadLadderVar(iport2, R6, iFirstVar, 1, pVarRErr, SYN)
If pVarRErr = 128 Then
ciclov(8).Caption = " "
Else
If StateOfM0M1M2.FunzM0 Or StateOfM0M1M2.FunzM1 Then 'M0
ciclov(8).Caption = "M00"
Else
ciclov(8).Caption = "M02"
End If
End If
End If
' Visualizzazione M01
iFirstVar = &H2601
iret = ReadLadderVar(iport2, V5, iFirstVar, 1, pVarR, SYN)
If pVarR = 128 Then
SM01v(4).Caption = "M01"
Else
SM01v(4).Caption = " "
End If
' Visualizzazione /
iFirstVar = &H2
iret = ReadLadderVar(iport2, R6, iFirstVar, 1, pVarR, SYN)
If pVarR = 128 Then
SeeBarrav(3).Caption = "/"
Else
SeeBarrav(3).Caption = " "
End If
End Sub
#End If
#End Region
#End Region
End Class
End Namespace