Imports ORiN2.interop.CAO
Public Class FrmAnyFeedProviderSample
    Private FCaoEngine As CaoEngine
    Private FAnyFeedCtrl As CaoController
    Private Sub FrmAnyFeedProviderSample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtBoxConnectionString.Text = "conn=com:1:9600:N:8:1, timeout = 2000"
    End Sub
    Private Sub Initialize()
        If (FCaoEngine Is Nothing) Then
            FCaoEngine = New CaoEngine
        End If
        If (FAnyFeedCtrl Is Nothing) Then
            FAnyFeedCtrl = FCaoEngine.Workspaces.Item(0).AddController("FeederTester", "CaoProv.FlexFactory.AnyFeed", "", _
                                       txtBoxConnectionString.Text)
        End If
    End Sub
    Private Sub UnInitialize()
        If FAnyFeedCtrl IsNot Nothing Then
            System.Runtime.InteropServices.Marshal.ReleaseComObject(FAnyFeedCtrl)
            FAnyFeedCtrl = Nothing
        End If
        If FCaoEngine IsNot Nothing Then
            System.Runtime.InteropServices.Marshal.ReleaseComObject(FCaoEngine)
            FCaoEngine = Nothing
        End If
    End Sub
    Private Sub bttnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnConnect.Click
        Initialize()
    End Sub
    Private Sub bttnDisConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnDisConnect.Click
        UnInitialize()
    End Sub
    Private Sub FrmAnyFeedProviderSample_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        UnInitialize()
    End Sub
    Private Sub bttnInitializeFeeder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnInitializeFeeder.Click
        bttnInitializeFeeder.Enabled = False
        FAnyFeedCtrl.Execute("init", "")
        bttnInitializeFeeder.Enabled = True
    End Sub
    Private Sub bttnFeedForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnFeedForward.Click
        bttnFeedForward.Enabled = False
        FAnyFeedCtrl.Execute("ffwd", "")
        bttnFeedForward.Enabled = True
    End Sub

    Private Sub bttnFeedFlipForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnFeedFlipForward.Click
        bttnFeedFlipForward.Enabled = False
        FAnyFeedCtrl.Execute("flipfwd", "")
        bttnFeedFlipForward.Enabled = True
    End Sub

    Private Sub bttnDispense_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnDispense.Click
        bttnDispense.Enabled = False
        FAnyFeedCtrl.Execute("dispense", "")
        bttnDispense.Enabled = True
    End Sub

    Private Sub bttnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnStop.Click
        bttnStop.Enabled = False
        FAnyFeedCtrl.Execute("stop", "")
        bttnStop.Enabled = True
    End Sub

    Private Sub bttnSetFfwdTurns_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnSetFfwdTurns.Click
        bttnSetFfwdTurns.Enabled = False
        FAnyFeedCtrl.Execute("SetFfwdTurns", CShort(txtFfwdTurns.Text))
        bttnSetFfwdTurns.Enabled = True
    End Sub

    Private Sub bttnSetFfwdSpeed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnSetFfwdSpeed.Click
        bttnSetFfwdSpeed.Enabled = False
        FAnyFeedCtrl.Execute("SetFfwdSpeed", CShort(txtFfwdSpeed.Text))
        bttnSetFfwdSpeed.Enabled = True
    End Sub

    Private Sub bttnSetFlipFfwdTurns_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnSetFlipFfwdTurns.Click
        bttnSetFlipFfwdTurns.Enabled = False
        FAnyFeedCtrl.Execute("SetFlipfwdTurns", CShort(txtFlipfwdTurns.Text))
        bttnSetFlipFfwdTurns.Enabled = True
    End Sub

    Private Sub bttnSetFlipFfwdSpeed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnSetFlipFfwdSpeed.Click
        bttnSetFlipFfwdSpeed.Enabled = False
        FAnyFeedCtrl.Execute("SetFlipfwdSpeed", CShort(txtFlipfwdSpeed.Text))
        bttnSetFlipFfwdSpeed.Enabled = True
    End Sub

    Private Sub bttnSetDispenseTurns_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnSetDispenseTurns.Click
        bttnSetDispenseTurns.Enabled = False
        FAnyFeedCtrl.Execute("SetDispenseTurns", CShort(txtDispenseTurns.Text))
        bttnSetDispenseTurns.Enabled = True
    End Sub

    Private Sub bttnSetDispenseSpeed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnSetDispenseSpeed.Click
        bttnSetDispenseSpeed.Enabled = False
        FAnyFeedCtrl.Execute("SetDispenseSpeed", CShort(txtDispenseSpeed.Text))
        bttnSetDispenseSpeed.Enabled = True
    End Sub
End Class
