Files
Emmanuele Sassi 6e4645875b - Primo commit
- Tpa funzionante
2021-09-29 11:35:42 +02:00

254 lines
12 KiB
VB.net

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Namespace fx_DGeneralFunctions
Partial Public Class MainForm
Inherits Form
Private objDRunTimeSystem As FXServer.DRunTimeSystem
Private objDGroupManager As FXServer.DGroupManager
Private objDGeneralFunction As FXServer.DGeneralFunctions
Private objDMainCncData As FXServer.DMainCncData
Private IsFlexiumPlus As Boolean = False
Private _PartProgramNumber As Single
Private _CNCAxisChannelArray As String() = New String() {"Channel 1", "Channel 2"}
Public Sub New()
InitializeComponent()
End Sub
Private Sub MainForm_Load(ByVal sender As Object, ByVal e As EventArgs)
_comboCncAxisChannel.Items.AddRange(_CNCAxisChannelArray)
End Sub
Private Sub InitFxServer()
objDRunTimeSystem = New FXServer.DRunTimeSystem()
objDRunTimeSystem.ServerInitializationFinished += New FXServer.IDRunTimeSystemEvents_ServerInitializationFinishedEventHandler(AddressOf objDRunTimeSystem_ServerInitializationFinished)
objDRunTimeSystem.ServerReinitializationStarted += New FXServer.IDRunTimeSystemEvents_ServerReinitializationStartedEventHandler(AddressOf objDRunTimeSystem_ServerReinitializationStarted)
objDRunTimeSystem.Init()
End Sub
Private Sub InitFxObjects()
objDGroupManager = New FXServer.DGroupManager()
objDGroupManager.ErrorHandler += New FXServer.IDGroupManagerEvents_ErrorHandlerEventHandler(AddressOf objDGroupManager_ErrorHandler)
objDGroupManager.CncNumber = 0
objDGeneralFunction = New FXServer.DGeneralFunctions()
objDGeneralFunction.ProgramActivated += New FXServer.IDGeneralFunctionsEvents_ProgramActivatedEventHandler(AddressOf objDGeneralFunction_ProgramActivated)
objDGeneralFunction.OnCncStart += New FXServer.IDGeneralFunctionsEvents_OnCncStartEventHandler(AddressOf objDGeneralFunction_OnCncStart)
objDGeneralFunction.OnCncStop += New FXServer.IDGeneralFunctionsEvents_OnCncStopEventHandler(AddressOf objDGeneralFunction_OnCncStop)
objDGeneralFunction.OnCncReset += New FXServer.IDGeneralFunctionsEvents_OnCncResetEventHandler(AddressOf objDGeneralFunction_OnCncReset)
objDGeneralFunction.CncModeWritten += New FXServer.IDGeneralFunctionsEvents_CncModeWrittenEventHandler(AddressOf objDGeneralFunction_CncModeWritten)
objDGeneralFunction.VariableWritten += New FXServer.IDGeneralFunctionsEvents_VariableWrittenEventHandler(AddressOf objDGeneralFunction_VariableWritten)
objDGeneralFunction.OnSkipLevelWritten += New FXServer.IDGeneralFunctionsEvents_OnSkipLevelWrittenEventHandler(AddressOf objDGeneralFunction_OnSkipLevelWritten)
objDGeneralFunction.Init(objDGroupManager.Handle)
objDMainCncData = New FXServer.DMainCncData()
objDMainCncData.Init(objDGroupManager.Handle)
Dim CncFxIdentifier As String = objDMainCncData.GetCncIdentifier()
_txtGetCncIdentification.Invoke(CType(Function()
_txtGetCncIdentification.Text = CncFxIdentifier
End Function, MethodInvoker))
If CncFxIdentifier = "Flexium 6" OrElse CncFxIdentifier = "Flexium 8" OrElse CncFxIdentifier = "Flexium 68" Then
IsFlexiumPlus = False
Else
IsFlexiumPlus = True
End If
End Sub
Private Sub CloseFxObjects()
System.Runtime.InteropServices.Marshal.ReleaseComObject(objDGroupManager)
objDGroupManager = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(objDGeneralFunction)
objDGeneralFunction = Nothing
MessageBox.Show("CloseFxObjects")
End Sub
Private Sub GetGeneralFunctions()
Dim _GetConnectState As Int16 = objDGeneralFunction.ConnectionStatus
Select Case _GetConnectState
Case 0
_txtConnectionState.Text = "Not connected"
Case 1
_txtConnectionState.Text = " Connection error"
Case 2
_txtConnectionState.Text = "Connected"
Case Else
End Select
End Sub
Private Sub _btnRuntimeSystemStart_Click(ByVal sender As Object, ByVal e As EventArgs)
InitFxServer()
End Sub
Private Sub _btnCycleStartCommon_Click(ByVal sender As Object, ByVal e As EventArgs)
objDGeneralFunction.CncStart()
End Sub
Private Sub _BtnFeedHoldCommon_Click(ByVal sender As Object, ByVal e As EventArgs)
objDGeneralFunction.CncStop()
End Sub
Private Sub _btnCNCResetCommon_Click(ByVal sender As Object, ByVal e As EventArgs)
objDGeneralFunction.CncReset()
End Sub
Private Sub _btnCncModeAuto_Click(ByVal sender As Object, ByVal e As EventArgs)
objDGeneralFunction.WriteCncMode(0, 0)
End Sub
Private Sub _btnCncModeMDI_Click(ByVal sender As Object, ByVal e As EventArgs)
objDGeneralFunction.WriteCncMode(2, 0)
End Sub
Private Sub _btnCncModeManual_Click(ByVal sender As Object, ByVal e As EventArgs)
objDGeneralFunction.WriteCncMode(7, 0)
End Sub
Private Sub _btnWriteVariable_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim _E80011FxStd As Int32 = 88888
Dim _FXReturn As Short = objDGeneralFunction.WriteVariable("E80011", _E80011FxStd)
If _FXReturn <> 0 Then
MessageBox.Show("Error from WriteVariable:" & " " & _FXReturn.ToString())
End If
End Sub
Private Sub _btnWriteVariable2_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim _E80010FxPlus As Double = 51515.6161
Dim _FXReturn As Short = objDGeneralFunction.WriteVariable2("E80010", _E80010FxPlus)
If _FXReturn <> 0 Then
MessageBox.Show("Error from WriteVariable2:" & " " & _FXReturn.ToString())
End If
End Sub
Private Sub objDRunTimeSystem_ServerInitializationFinished()
InitFxObjects()
GetGeneralFunctions()
If IsFlexiumPlus = True Then
_txtBlockSkipLevel.Text = "100"
_txtBlockSkipLevel.Enabled = True
Else
_txtBlockSkipLevel.Text = ""
_txtBlockSkipLevel.Enabled = True
End If
_txtServerInitStatus.Invoke(CType(Function()
_txtServerInitStatus.ForeColor = Color.DarkBlue
_txtServerInitStatus.Text = "FXServer objects initialized !"
End Function, MethodInvoker))
_txtServerReinitStatus.Invoke(CType(Function()
_txtServerReinitStatus.ForeColor = Color.DarkGreen
_txtServerReinitStatus.Text = "FXServer no objects closed !"
End Function, MethodInvoker))
End Sub
Private Sub objDRunTimeSystem_ServerReinitializationStarted()
CloseFxObjects()
_txtServerReinitStatus.Invoke(CType(Function()
_txtServerReinitStatus.ForeColor = Color.Red
_txtServerReinitStatus.Text = "FXServer objects closed !"
End Function, MethodInvoker))
_txtServerInitStatus.Invoke(CType(Function()
_txtServerInitStatus.ForeColor = Color.DarkOrange
_txtServerInitStatus.Text = "FXServer objects not initialized !"
End Function, MethodInvoker))
End Sub
Private Sub objDGeneralFunction_ProgramActivated(ByVal nerrorCode As Short)
MessageBox.Show("Part program activated:" & " " & nerrorCode)
End Sub
Private Sub objDGeneralFunction_OnCncReset(ByVal errorCode As Short)
If errorCode <> 0 Then
MessageBox.Show("Error CNC Reset:" & " " & errorCode.ToString())
End If
End Sub
Private Sub objDGeneralFunction_OnCncStop(ByVal errorCode As Short)
If errorCode <> 0 Then
MessageBox.Show("Error Feed Hold:" & " " & errorCode.ToString())
End If
End Sub
Private Sub objDGeneralFunction_OnCncStart(ByVal errorCode As Short)
If errorCode <> 0 Then
MessageBox.Show("Error Cycle Start:" & " " & errorCode.ToString())
End If
End Sub
Private Sub objDGeneralFunction_CncModeWritten(ByVal errorCode As Short)
MessageBox.Show("Error CNC Mode selection completed:" & " " & errorCode.ToString())
End Sub
Private Sub _txtPartProgramNumber_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If e.KeyChar = CChar(Keys.[Return]) Then
e.Handled = True
Dim _CncAxisChannelIndependent As Int16
_PartProgramNumber = Single.Parse(_txtPartProgramNumber.Text)
MessageBox.Show("PartProgNumber:" & " " & _PartProgramNumber.ToString())
Dim _PartProgramNumberActivate As Int32 = Convert.ToInt32(_PartProgramNumber * 10)
MessageBox.Show("PartProgNumberActivate:" & " " & _PartProgramNumberActivate.ToString())
If _checkChannelTypeState.Checked = True Then
_CncAxisChannelIndependent = 1
Else
_CncAxisChannelIndependent = 0
End If
Dim _FXReturn As Int16 = objDGeneralFunction.ActivateProgram(_PartProgramNumberActivate, _CncAxisChannelIndependent)
If _FXReturn <> 0 Then
MessageBox.Show("Error Activate Program:" & " " & _FXReturn.ToString())
End If
End If
End Sub
Private Sub objDGroupManager_ErrorHandler(ByVal sError As String, ByVal nTextNumber As Short)
MessageBox.Show("ErrorHandler message:" & " " & sError & " " & "ErrorHandler number:" & " " & nTextNumber.ToString())
End Sub
Private Sub _comboCncAxisChannel_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Select Case _comboCncAxisChannel.SelectedItem.ToString()
Case "Channel 1"
objDGroupManager.AxisGroup = 0
Case "Channel 2"
objDGroupManager.AxisGroup = 1
Case Else
End Select
End Sub
Private Sub objDGeneralFunction_VariableWritten(ByVal errorCode As Short)
If errorCode <> 0 Then
MessageBox.Show("Error from VariableWritten:" & " " & errorCode.ToString())
Else
MessageBox.Show("VariableWritten successfully")
End If
End Sub
Private Sub _txtBlockSkipLevel_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If e.KeyChar = CChar(Keys.[Return]) Then
e.Handled = True
Dim _GetBlockSkipLevelDecimalValue As UInt32 = Convert.ToUInt32(_txtBlockSkipLevel.Text)
Dim _FXReturn As Int16 = objDGeneralFunction.WriteSkipLevel(20, _GetBlockSkipLevelDecimalValue)
If _FXReturn <> 0 Then
MessageBox.Show("Error from WriteSkipLevel:" & " " & _FXReturn.ToString())
End If
End If
End Sub
Private Sub objDGeneralFunction_OnSkipLevelWritten(ByVal lHandle As Integer, ByVal errorCode As Short)
MessageBox.Show("OnSkipLevelWritten:" & "" & "Handle:" & lHandle & " " & "errorCode:" & errorCode)
End Sub
End Class
End Namespace