Files
Samuele Locatelli a2171e643d Aggiunta proxy iniziale:
- FTP
- Gomba
- Icoel
- MultiCcn
- OSAI
- SqlDB
2024-12-23 09:01:29 +01:00

368 lines
10 KiB
VB.net

Imports System
Imports System.IO
Imports System.Collections
Imports Microsoft.VisualBasic
Public Class FrmMain
Public Const VERSION_ID = "1"
Public b_timer_busy As Boolean
Public n_simulated_index As Integer = 0
Public sz_usb_barcode_string As String
Dim b_exit_busy As Boolean = False
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
Private Sub My_initialize() Handles Me.Load
Call CheckForExistingInstance()
Me.Show()
' read ini file & init global variables
Call IniRead.Ini_read()
' read messages
Call Message.init()
' init logger on file
Call Log.init(IniRead.szLogFileName)
Call Log.write("-----------START PROGRAM test Sam -------------------")
' init modules
Call Init_Modules()
' Init NC connection
Call M_cn_connection.StartConnection()
' check NC connection reading a ver and waiting
Call M_cn_connection.CheckConnection()
' timer enable
Call Timer_enable()
End Sub
#Region " Closing...."
Private Sub Dispose_form(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Disposed
Call Terminate_properly()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Call Terminate_properly()
End Sub 'Form1_Closing
Sub Terminate_properly()
If Not b_exit_busy Then
b_exit_busy = True
Timer_disable()
System.Threading.Thread.Sleep(SLEEP_TIME)
If (Not IniRead.b_debug) Then
If Not (CnOsai Is Nothing) Then
CnOsai.CloseSession()
End If
End If
Application.Exit()
End If ' busy
End Sub
#End Region
#Region " Buttons"
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
Call Terminate_properly()
End Sub
#End Region
#Region " Init routines"
Private Sub Init_Modules()
Call M_state_machine.init()
Call M_aspect.init()
End Sub
Public Sub CheckForExistingInstance()
'~~> Get number of processes of you program
If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
MessageBox.Show("Another copy of this program is already running",
"More than 1 copy not allowed", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Application.Exit()
End If
End Sub
#End Region
#Region " Timer"
' -------------------------------------------------------------------------------
' ---- Enable Timer
' -------------------------------------------------------------------------------
Private Sub Timer_enable()
' set timer interval
Tmr_Main.Interval = IniRead.lTimerInterval
' Enable Timer
Tmr_Main.Enabled = True
End Sub
' -------------------------------------------------------------------------------
' ---- DisAble timer
' -------------------------------------------------------------------------------
Private Sub Timer_disable()
Tmr_Main.Enabled = False
End Sub
'_____________________________________________________________________________
' -------------------------------------------------------------------------------
' ---- Tick timer d,... ------
' -------------------------------------------------------------------------------
Private Sub Tmr_Main_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tmr_Main.Tick
If Not b_timer_busy Then
b_timer_busy = True
Tmr_Main.Enabled = False
Call M_state_machine.go()
b_timer_busy = False
Tmr_Main.Enabled = True
End If
End Sub
#End Region
#Region " Simulation "
Private Sub BtnSim0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSim0.Click
n_simulated_index = 0
Call gray_them_all()
BtnSim0.BackColor = Color.LightCoral
End Sub
Private Sub BtnSim1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSim1.Click
n_simulated_index = 1
Call gray_them_all()
BtnSim1.BackColor = Color.LightCoral
End Sub
Private Sub BtnSim2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSim2.Click
n_simulated_index = 2
Call gray_them_all()
BtnSim2.BackColor = Color.LightCoral
End Sub
Private Sub BtnSim3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSim3.Click
n_simulated_index = 3
Call gray_them_all()
BtnSim3.BackColor = Color.LightCoral
End Sub
Private Sub BtnSim4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSim4.Click
n_simulated_index = 4
Call gray_them_all()
BtnSim4.BackColor = Color.LightCoral
End Sub
Private Sub BtnSim5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSim5.Click
n_simulated_index = 5
Call gray_them_all()
BtnSim5.BackColor = Color.LightCoral
End Sub
Private Sub gray_them_all()
BtnSim0.BackColor = Color.LightGray
BtnSim1.BackColor = Color.LightGray
BtnSim2.BackColor = Color.LightGray
BtnSim3.BackColor = Color.LightGray
BtnSim4.BackColor = Color.LightGray
BtnSim5.BackColor = Color.LightGray
End Sub
Private Sub LblSimPrgSent1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblSimPrgSent1.Click
LblSimPrgSent1.BackColor = Color.Azure
End Sub
Private Sub LblSimPrgSent2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblSimPrgSent2.Click
LblSimPrgSent2.BackColor = Color.Azure
End Sub
Private Sub BtnReadOldOsai_Click(sender As Object, e As EventArgs) Handles BtnReadOldOsai.Click
Dim Var_tmp As ComCNOsai.stVAR
Var_tmp.nAddress = IniRead.nVar_NC_state
Var_tmp.nBit = 0 ' solo x evitare warning ...
Var_tmp.nNumCn = 1 ' solo x evitare warning ...
Var_tmp.szVarName = "" ' solo x evitare warning ...
LblReadOldOsai.Text = CnOsai.ReadShortVar(Var_tmp).ToString
End Sub
Private Sub BtnWrite1OldOsai_Click(sender As Object, e As EventArgs) Handles BtnWrite1OldOsai.Click
Dim Var_tmp As ComCNOsai.stVAR
Var_tmp.nAddress = IniRead.nVar_NC_state
Var_tmp.nBit = 0 ' solo x evitare warning ...
Var_tmp.nNumCn = 1 ' solo x evitare warning ...
Var_tmp.szVarName = "" ' solo x evitare warning ...
CnOsai.WriteShortVar(Var_tmp, 1)
End Sub
Private Sub BtnWrite2OldOsai_Click(sender As Object, e As EventArgs) Handles BtnWrite2OldOsai.Click
Dim Var_tmp As ComCNOsai.stVAR
Var_tmp.nAddress = IniRead.nVar_NC_state
Var_tmp.nBit = 0 ' solo x evitare warning ...
Var_tmp.nNumCn = 1 ' solo x evitare warning ...
Var_tmp.szVarName = "" ' solo x evitare warning ...
CnOsai.WriteShortVar(Var_tmp, 2)
End Sub
Private Sub BtnWrite3OldOsai_Click(sender As Object, e As EventArgs) Handles BtnWrite3OldOsai.Click
Dim Var_tmp As ComCNOsai.stVAR
Var_tmp.nAddress = IniRead.nVar_NC_state
Var_tmp.nBit = 0 ' solo x evitare warning ...
Var_tmp.nNumCn = 1 ' solo x evitare warning ...
Var_tmp.szVarName = "" ' solo x evitare warning ...
CnOsai.WriteShortVar(Var_tmp, 3)
End Sub
Private Sub BtnWrite4OldOsai_Click(sender As Object, e As EventArgs) Handles BtnWrite4OldOsai.Click
Dim Var_tmp As ComCNOsai.stVAR
Var_tmp.nAddress = IniRead.nVar_NC_state
Var_tmp.nBit = 0 ' solo x evitare warning ...
Var_tmp.nNumCn = 1 ' solo x evitare warning ...
Var_tmp.szVarName = "" ' solo x evitare warning ...
CnOsai.WriteShortVar(Var_tmp, 4)
End Sub
Private Sub BtnWrite5OldOsai_Click(sender As Object, e As EventArgs) Handles BtnWrite5OldOsai.Click
Dim Var_tmp As ComCNOsai.stVAR
Var_tmp.nAddress = IniRead.nVar_NC_state
Var_tmp.nBit = 0 ' solo x evitare warning ...
Var_tmp.nNumCn = 1 ' solo x evitare warning ...
Var_tmp.szVarName = "" ' solo x evitare warning ...
CnOsai.WriteShortVar(Var_tmp, 5)
End Sub
Private Sub Btn_test_file_Click(sender As Object, e As EventArgs) Handles Btn_test_file.Click
Dim sz_geppo_filename As String = IniRead.sz_temporary_path & "\geppo.cn"
Dim sz_NC_program_name As String
If (IniRead.b_send_file) Then
sz_geppo_filename = Ask_file()
sz_NC_program_name = Path.GetFileNameWithoutExtension(sz_geppo_filename)
sz_NC_program_name = IniRead.szDefaultPathNC & "\" & sz_NC_program_name
my_f_____copy_file_to_nc(sz_geppo_filename, sz_NC_program_name)
Else
' crea un filettino e lo manda
Dim Writer As New StreamWriter(sz_geppo_filename) ' Opens stream and begins writing
Writer.WriteLine("; ")
Writer.WriteLine("; Ciao Mamma !")
Writer.WriteLine("; ")
Writer.WriteLine("; saluti da Geppo")
Writer.WriteLine("G00")
Writer.WriteLine("M00")
Writer.Close()
Call CnOsai.CopyFileToNC("", sz_geppo_filename, "GEPPO")
System.IO.File.Delete(sz_geppo_filename) ' sempre per non far nulla ....
End If
End Sub
Function Ask_file() As String
Dim sz_filename As String = ""
Try
With OpenFileDialog1
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
sz_filename = .FileName
End If
End With
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
End Try
Return sz_filename
End Function
#End Region
End Class