Files
mapo-iob-net/CVCncLib/Modules/IniRead.vb
T
Samuele Locatelli be164fb527 Aggiunta libs base
2021-12-01 18:05:28 +01:00

465 lines
14 KiB
VB.net

Public Module IniRead
Public Const OVERWRITE As Boolean = True
Public Const APPEND As Boolean = True
Public Const DO_NOT_APPEND As Boolean = False
Public sz_ini_file_name As String
Public sz_program_path As String
Public sz_temporary_path As String
Public sz_allowed_extension As String
Public b_debug As Boolean
Public b_verbose As Boolean
Public b_test_nc As Boolean
Public b_send_file As Boolean
Public b_log_enabled As Boolean
Public szLogFileName As String
Public b_win7 As Boolean
Public b_open_control As Boolean
Public b_force_S10WLK32 As Boolean
Public b_no_WinNBI As Boolean
Public szNameNC As String
Public nVar_NC_state As Integer ' @STATUS_PRG PLC var number ( GW ) : Nc program state
Public nVar_prg_1_ok As Integer
Public nVar_prg_2_ok As Integer
Public sz_ODD_program_name As String
Public sz_EVEN_program_name As String
Public sz_AUTO_program_name As String
Public n_program_to_send As Short
Public szDefaultNameNC As String
Public szDefaultPathNC As String
Public lTimerInterval As Long
Public b_SerialBarCodeReader_enabled As Boolean
Public n_SerialBarCodeReader_comm_port As Int16
Public sz_SerialBarCodeReader_settings As String
Public b_UsbBarCodeReader_enabled As String
Public b_BarCodeInput_enabled As Boolean
Public b_FileInputMode_enabled As Boolean
Public sz_FileInputName As String
Public n_num_barcode_fields As Short
Public sz_barcode_mask As String
Public sz_barcode_preprocessing As String
Public b_Table_enabled As Boolean
Public sz_table_filename As String
Public b_reload_table As Boolean
Public b_ext_program_enabled As Boolean
Public sz_ext_program_filename As String
Public sz_ext_return_filename As String
Public sz_ext_temp_filename As String
Public b_CAM_program_enabled As Boolean
Public sz_CAM_program_exefilename As String
Public sz_CAM_data_path As String
Public sz_CAM_data_ext As String
Public sz_CAM_arguments As String
Public sz_CAM_return_ext As String
Public sz_CAM_Probe_ext As String
Public b_direct_mode_enabled As Boolean
Public sz_direct_prefix As String
Public sz_direct_suffix As String
Public b_select_mode_enabled As Boolean
Public sz_probe_arguments As String
Public sz_cn_arguments As String
Public n_L_var_1 As Int16
Public n_L_var_2 As Int16
Public n_L_value_1_on As Int16
Public n_L_value_1_off As Int16
Public n_L_value_2_on As Int16
Public n_L_value_2_off As Int16
Public n_timeout As Int16
Public sz_nc_probe_path As String
Public sz_nc_probe_ext As String
Public b_fixed_probe_file As Boolean
Public sz_nc_fixed_probe_file As String
Public b_read_DDF_file As Boolean
Public sz_property_1 As String
Public sz_property_2 As String
Public b_toolcomp_update As Boolean
Public n_toolcomp_number As Int16
Public sz_toolcomp_file As String
Public sz_toolcomp_command As String
#Region "registration"
'Questo campo e' il campo di referenza serve a creare la relativa KEy di sblocco
Public developerKey As String
'Richiede solo numeri interi
Public regTry As Integer
'Flag per identificare la registrazione del programma
Public pRegistered As Boolean
Public PC_serial_number As Long
Public sPC_serial_number As String
Public SW_version As String
Public registered_key As String
Public registered_key2 As String
Public registered_key3 As String
Public registered_customer As String
#End Region
#Region "example of INI file"
' file door_pro.ini
'[General]
'Program path = c:\Users\carlo\Documents\Projects\vs2008\door_pro\door_pro\programs
'allowed ext = .anc .TXT
'temp path = c:\Users\carlo\Documents\Projects\vs2008\door_pro\door_pro\temp
'
'w7 = true
'timer = 1000
'[Debug]
'debug = true
'verbose = false
'[Log]
'enabled = true
'Log file = c:\Users\carlo\Documents\Projects\vs2008\door_pro\door_pro\temp\log
'[NC]
'name = NC9000
'NC state = 230
'Prog1 ok = 232
'Prog2 ok = 233
'default_name = MAIN
'default_path = Y:\UPP\
'ODD_name = 1000
'EVEN_name = 2000
'AUTO_name = UPP\MAINAUTO
'program_to_send = 4
'[BarCode]
'fields = 1
'MASK = xx11111xxx223333xx44xxxxxx
'PreProcessing = "1-2"
'[SerialBarCodeReader]
'enabled = true
'Port = 4
'Settings=9600,n,8,1
'[UsbBarCodeReader]
'enabled = false
'[Table]
'enabled = true
'file = c:\pro_d\pro_d\prg\worklist.aut
'[CAM]
'enabled = true
'program = C:\abc\ww.exe
'datapath
'arguments
'return_file_ext = txt
'[Direct]
'enabled = true
'pre = C:\door_pro\programs\
'post = .cnc
'[Key]
' regkey = 12345
' regkey2 = 2345
' regkey3 = 2345
' customer = qwe
#End Region
Sub Ini_read()
sz_ini_file_name = Application.StartupPath & "\config\" & Application.ProductName & ".ini"
Dim ini As New IniReader(sz_ini_file_name)
ini.Section = "General" '-----------------------------------------------------
sz_program_path = clear_ending_bar(ini.ReadString("Program path"))
sz_temporary_path = clear_ending_bar(ini.ReadString("temp path"))
sz_allowed_extension = clear_starting_point(ini.ReadString("allowed ext").ToLower)
lTimerInterval = ini.ReadLong("timer", 1000)
b_win7 = ini.ReadBoolean("w7", False)
ini.Section = "Debug" '-----------------------------------------------------
b_debug = ini.ReadBoolean("debug", False)
b_verbose = ini.ReadBoolean("verbose", False)
b_test_nc = ini.ReadBoolean("test_nc", False)
b_send_file = ini.ReadBoolean("send_file", False)
ini.Section = "Log" '-----------------------------------------------------
b_log_enabled = ini.ReadBoolean("enabled", False)
szLogFileName = ini.ReadString("Log file")
ini.Section = "NC" '-----------------------------------------------------
b_open_control = ini.ReadBoolean("OpenControl", False)
b_force_S10WLK32 = ini.ReadBoolean("S10WLK32", False)
b_no_WinNBI = ini.ReadBoolean("No WinNBI", False)
szNameNC = ini.ReadString("name")
nVar_NC_state = ini.ReadInteger("NC state")
nVar_prg_1_ok = ini.ReadInteger("Prog1 ok")
nVar_prg_2_ok = ini.ReadInteger("Prog2 ok")
szDefaultNameNC = ini.ReadString("default_name")
szDefaultPathNC = clear_ending_bar(ini.ReadString("default_path"))
sz_ODD_program_name = ini.ReadString("ODD_name")
sz_EVEN_program_name = ini.ReadString("EVEN_name")
n_program_to_send = ini.ReadInteger("program_to_send", 1)
ini.Section = "BarCode" '-----------------------------------------------------
'[BarCode]
'fields = 1
'MASK = xx11111xxx223333xx44xxxxxx
'PreProcessing = "1-2"
n_num_barcode_fields = ini.ReadInteger("fields", 1)
sz_barcode_mask = ini.ReadString(ini.Section, "MASK", "11111111")
sz_barcode_preprocessing = ini.ReadString(ini.Section, "PreProcessing", "=")
ini.Section = "SerialBarCodeReader" '-----------------------------------------------------
'[SerialBarCodeReader]
'enabled = true
'Port = 4
'Settings=9600,n,8,1
b_SerialBarCodeReader_enabled = ini.ReadBoolean("enabled", False)
n_SerialBarCodeReader_comm_port = ini.ReadInteger("Port", 1)
sz_SerialBarCodeReader_settings = ini.ReadString(ini.Section, "Settings", "9600,None,8,1")
ini.Section = "UsbBarCodeReader" '-----------------------------------------------------
'[UsbBarCodeReader]
'enabled = true
b_UsbBarCodeReader_enabled = ini.ReadBoolean("enabled", False)
If b_UsbBarCodeReader_enabled And b_SerialBarCodeReader_enabled Then
Log.write_and_messagebox(" Both USB and serial bar code reader enabled - please disable one ... ", 34)
'End
End If
b_BarCodeInput_enabled = b_UsbBarCodeReader_enabled Or b_SerialBarCodeReader_enabled
ini.Section = "FileInput" '-----------------------------------------------------
'[FileInput]
'enabled = true
'InputFile = C:\input\data.txt
b_FileInputMode_enabled = ini.ReadBoolean("enabled", False)
sz_FileInputName = ini.ReadString(ini.Section, "InputFile", "")
If b_BarCodeInput_enabled And b_FileInputMode_enabled Then
Log.write_and_messagebox(" Both file input and bar code mode enabled - please disable one ... ", 35)
'End
End If
If (Not b_BarCodeInput_enabled) And (Not b_FileInputMode_enabled) Then
Log.write_and_messagebox(" No file input mode nor bar code mode enabled - please enable one ... ", 36)
'End
End If
ini.Section = "Table" '-----------------------------------------------------
'[Table]
'enabled = true
'file = c:\pro_d\pro_d\prg\worklist.aut
b_Table_enabled = ini.ReadBoolean("enabled", False)
sz_table_filename = ini.ReadString("file")
b_reload_table = ini.ReadBoolean("reload", False)
ini.Section = "EXT" '-----------------------------------------------------
'[EXT]
'enabled = true
'program = C:\abc\ww.exe
'return_file = c:\pro_d\pro_d\prg\worklist.aut
b_ext_program_enabled = ini.ReadBoolean("enabled", False)
sz_ext_program_filename = ini.ReadString("program")
sz_ext_return_filename = ini.ReadString("return_file")
sz_ext_temp_filename = ini.ReadString("temp_file")
ini.Section = "CAM" '-----------------------------------------------------
'[CAM]
'enabled = true
'program = C:\abc\ww.exe
'datapath
'arguments
'return_file_ext = c:\pro_d\pro_d\prg\worklist.aut
b_CAM_program_enabled = ini.ReadBoolean("enabled", False)
sz_CAM_program_exefilename = ini.ReadString("program")
sz_CAM_data_path = (ini.ReadString("datapath"))
sz_CAM_data_path = sz_CAM_data_path.Replace("""", "")
sz_CAM_data_path = clear_ending_bar(sz_CAM_data_path)
sz_CAM_data_ext = clear_starting_point(ini.ReadString("dataext"))
sz_CAM_arguments = ini.ReadString("arguments")
sz_CAM_return_ext = clear_starting_point(ini.ReadString("return_file_ext"))
sz_CAM_Probe_ext = clear_starting_point(ini.ReadString("probe_file_ext"))
ini.Section = "Direct" '-----------------------------------------------------
'[Direct]
'enabled = true
'pre = C:\abc\ww\
'post = .cnc
b_direct_mode_enabled = ini.ReadBoolean("enabled", False)
sz_direct_prefix = ini.ReadString("pre")
sz_direct_suffix = ini.ReadString("post")
ini.Section = "Select" '-----------------------------------------------------
'[Select]
'enabled = true
'p_arguments = " 3"
'c_arguments = " 4"
'L var 1 = 916
'L var 2 = 919
'L value 1 on = 1
'L value 1 off = 0
'L value 2 on = 2
'L value 2 off = 2
'timeout = 300
' NC probe file path = m: \Cnc\DDF\
' NC probe file ext = dat
' fixed probe file = true
' NC_probe_file = UPP\PROGRA1\Data.prb
' read file = true
' prop1 = properties:
' prop2 = skinned
b_select_mode_enabled = ini.ReadBoolean("enabled", False)
sz_probe_arguments = ini.ReadString("p_arguments")
sz_cn_arguments = ini.ReadString("c_arguments")
n_L_var_1 = ini.ReadInteger("L var 1")
n_L_var_2 = ini.ReadInteger("L var 2")
n_L_value_1_on = ini.ReadInteger("L value 1 on")
n_L_value_1_off = ini.ReadInteger("L value 1 off")
n_L_value_2_on = ini.ReadInteger("L value 2 on")
n_L_value_2_off = ini.ReadInteger("L value 2 off")
n_timeout = ini.ReadInteger("timeout")
sz_nc_probe_path = ini.ReadString("NC probe file path")
sz_nc_probe_path = clear_ending_bar(sz_nc_probe_path)
sz_nc_probe_ext = clear_starting_point(ini.ReadString("NC probe file ext"))
b_fixed_probe_file = ini.ReadBoolean("fixed probe file", False)
sz_nc_fixed_probe_file = Trim(ini.ReadString("NC_probe_file"))
b_read_DDF_file = ini.ReadBoolean("read DDF file", False)
sz_property_1 = Trim(ini.ReadString("prop1"))
sz_property_2 = Trim(ini.ReadString("prop2"))
'----------- check that only one method is enabled
Dim n_methods As Short = 0
If b_Table_enabled Then n_methods = n_methods + 1
If b_ext_program_enabled Then n_methods = n_methods + 1
If b_CAM_program_enabled Then n_methods = n_methods + 1
If b_direct_mode_enabled Then n_methods = n_methods + 1
If b_select_mode_enabled Then n_methods = n_methods + 1
If n_methods > 1 Then
Log.write_and_messagebox(" Too many input modes enabled .. - please enable only one ... ", 38)
'End
End If
If n_methods < 1 Then
Log.write_and_messagebox(" No input mode enabled ( CAM / Table / external / direct /.. - please enable one ... ", 40)
'End
End If
ini.Section = "Key" '-----------------------------------------------------
' [Key]
' regkey = 12345
' regkey2 = 2345
' customer = qwe
registered_key = UCase$(ini.ReadString("regkey"))
registered_key2 = UCase$(ini.ReadString("regkey2"))
registered_key3 = UCase$(ini.ReadString("regkey3"))
registered_customer = ini.ReadString("Customer")
End Sub
Sub write_customer(ByVal sz_customer As String)
Dim ini As New IniReader(sz_ini_file_name)
ini.Write("Key", "Customer", sz_customer)
End Sub
Sub write_Program_path(ByVal sz_data_file_name As String)
Dim ini As New IniReader(sz_ini_file_name)
ini.Write("General", "Program path", sz_data_file_name)
End Sub
#Region "fuffa"
#End Region
End Module