Public Class FormMain
    Inherits System.Windows.Forms.Form

    'global decalrations
    Private commPort As New Rs232()
    Private videoSwitchState(15) As Integer
    Private sourceNameStr(15) As String
    Private sourceIndex As Integer
    Private defaultBtnColor As Color
    Private undoLastSrcDst(2) As Integer

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ButtonSrc0 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc1 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc2 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc3 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc4 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc5 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc6 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc7 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc8 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc9 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc10 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc11 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc12 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc13 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc14 As System.Windows.Forms.Button
    Friend WithEvents ButtonSrc15 As System.Windows.Forms.Button
    Friend WithEvents ButtonDst0 As System.Windows.Forms.Button
    Friend WithEvents ButtonDst1 As System.Windows.Forms.Button
    Friend WithEvents ButtonDst2 As System.Windows.Forms.Button
    Friend WithEvents ButtonDst3 As System.Windows.Forms.Button
    Friend WithEvents ButtonDst4 As System.Windows.Forms.Button
    Friend WithEvents ButtonDst5 As System.Windows.Forms.Button
    Friend WithEvents ButtonDst6 As System.Windows.Forms.Button
    Friend WithEvents ButtonDst7 As System.Windows.Forms.Button
    Friend WithEvents GroupBoxSrc As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBoxDst As System.Windows.Forms.GroupBox
    Friend WithEvents LabelStatus As System.Windows.Forms.Label
    Friend WithEvents LabelCurrentStatus As System.Windows.Forms.Label
    Friend WithEvents LabelDst0 As System.Windows.Forms.Label
    Friend WithEvents LabelDst1 As System.Windows.Forms.Label
    Friend WithEvents LabelDst2 As System.Windows.Forms.Label
    Friend WithEvents LabelDst3 As System.Windows.Forms.Label
    Friend WithEvents LabelDst7 As System.Windows.Forms.Label
    Friend WithEvents LabelDst6 As System.Windows.Forms.Label
    Friend WithEvents LabelDst4 As System.Windows.Forms.Label
    Friend WithEvents LabelDst5 As System.Windows.Forms.Label
    Friend WithEvents ButtonUndo As System.Windows.Forms.Button
    Friend WithEvents TimerStatus As System.Windows.Forms.Timer
    Friend WithEvents LabelSrc1 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc2 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc3 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc4 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc5 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc6 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc7 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc8 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc9 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc10 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc11 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc12 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc13 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc14 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc15 As System.Windows.Forms.Label
    Friend WithEvents LabelSrc16 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FormMain))
        Me.GroupBoxSrc = New System.Windows.Forms.GroupBox()
        Me.LabelSrc16 = New System.Windows.Forms.Label()
        Me.LabelSrc15 = New System.Windows.Forms.Label()
        Me.LabelSrc14 = New System.Windows.Forms.Label()
        Me.LabelSrc13 = New System.Windows.Forms.Label()
        Me.LabelSrc12 = New System.Windows.Forms.Label()
        Me.LabelSrc11 = New System.Windows.Forms.Label()
        Me.LabelSrc10 = New System.Windows.Forms.Label()
        Me.LabelSrc9 = New System.Windows.Forms.Label()
        Me.LabelSrc8 = New System.Windows.Forms.Label()
        Me.LabelSrc7 = New System.Windows.Forms.Label()
        Me.LabelSrc6 = New System.Windows.Forms.Label()
        Me.LabelSrc5 = New System.Windows.Forms.Label()
        Me.LabelSrc4 = New System.Windows.Forms.Label()
        Me.LabelSrc3 = New System.Windows.Forms.Label()
        Me.LabelSrc2 = New System.Windows.Forms.Label()
        Me.LabelSrc1 = New System.Windows.Forms.Label()
        Me.ButtonSrc15 = New System.Windows.Forms.Button()
        Me.ButtonSrc14 = New System.Windows.Forms.Button()
        Me.ButtonSrc7 = New System.Windows.Forms.Button()
        Me.ButtonSrc6 = New System.Windows.Forms.Button()
        Me.ButtonSrc13 = New System.Windows.Forms.Button()
        Me.ButtonSrc12 = New System.Windows.Forms.Button()
        Me.ButtonSrc11 = New System.Windows.Forms.Button()
        Me.ButtonSrc10 = New System.Windows.Forms.Button()
        Me.ButtonSrc9 = New System.Windows.Forms.Button()
        Me.ButtonSrc8 = New System.Windows.Forms.Button()
        Me.ButtonSrc5 = New System.Windows.Forms.Button()
        Me.ButtonSrc4 = New System.Windows.Forms.Button()
        Me.ButtonSrc3 = New System.Windows.Forms.Button()
        Me.ButtonSrc2 = New System.Windows.Forms.Button()
        Me.ButtonSrc1 = New System.Windows.Forms.Button()
        Me.ButtonSrc0 = New System.Windows.Forms.Button()
        Me.GroupBoxDst = New System.Windows.Forms.GroupBox()
        Me.LabelDst3 = New System.Windows.Forms.Label()
        Me.LabelDst2 = New System.Windows.Forms.Label()
        Me.ButtonDst7 = New System.Windows.Forms.Button()
        Me.ButtonDst6 = New System.Windows.Forms.Button()
        Me.ButtonDst5 = New System.Windows.Forms.Button()
        Me.ButtonDst4 = New System.Windows.Forms.Button()
        Me.ButtonDst3 = New System.Windows.Forms.Button()
        Me.ButtonDst2 = New System.Windows.Forms.Button()
        Me.ButtonDst1 = New System.Windows.Forms.Button()
        Me.ButtonDst0 = New System.Windows.Forms.Button()
        Me.LabelDst1 = New System.Windows.Forms.Label()
        Me.LabelDst4 = New System.Windows.Forms.Label()
        Me.LabelDst7 = New System.Windows.Forms.Label()
        Me.LabelDst5 = New System.Windows.Forms.Label()
        Me.LabelDst6 = New System.Windows.Forms.Label()
        Me.LabelStatus = New System.Windows.Forms.Label()
        Me.LabelCurrentStatus = New System.Windows.Forms.Label()
        Me.LabelDst0 = New System.Windows.Forms.Label()
        Me.ButtonUndo = New System.Windows.Forms.Button()
        Me.TimerStatus = New System.Windows.Forms.Timer(Me.components)
        Me.GroupBoxSrc.SuspendLayout()
        Me.GroupBoxDst.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBoxSrc
        '
        Me.GroupBoxSrc.Controls.AddRange(New System.Windows.Forms.Control() {Me.LabelSrc16, Me.LabelSrc15, Me.LabelSrc14, Me.LabelSrc13, Me.LabelSrc12, Me.LabelSrc11, Me.LabelSrc10, Me.LabelSrc9, Me.LabelSrc8, Me.LabelSrc7, Me.LabelSrc6, Me.LabelSrc5, Me.LabelSrc4, Me.LabelSrc3, Me.LabelSrc2, Me.LabelSrc1, Me.ButtonSrc15, Me.ButtonSrc14, Me.ButtonSrc7, Me.ButtonSrc6, Me.ButtonSrc13, Me.ButtonSrc12, Me.ButtonSrc11, Me.ButtonSrc10, Me.ButtonSrc9, Me.ButtonSrc8, Me.ButtonSrc5, Me.ButtonSrc4, Me.ButtonSrc3, Me.ButtonSrc2, Me.ButtonSrc1, Me.ButtonSrc0})
        Me.GroupBoxSrc.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.GroupBoxSrc.Location = New System.Drawing.Point(8, 8)
        Me.GroupBoxSrc.Name = "GroupBoxSrc"
        Me.GroupBoxSrc.Size = New System.Drawing.Size(384, 480)
        Me.GroupBoxSrc.TabIndex = 0
        Me.GroupBoxSrc.TabStop = False
        Me.GroupBoxSrc.Text = "Video Source"
        '
        'LabelSrc16
        '
        Me.LabelSrc16.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc16.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc16.Location = New System.Drawing.Point(336, 416)
        Me.LabelSrc16.Name = "LabelSrc16"
        Me.LabelSrc16.Size = New System.Drawing.Size(32, 48)
        Me.LabelSrc16.TabIndex = 35
        Me.LabelSrc16.Text = "15"
        Me.LabelSrc16.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc15
        '
        Me.LabelSrc15.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc15.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc15.Location = New System.Drawing.Point(336, 360)
        Me.LabelSrc15.Name = "LabelSrc15"
        Me.LabelSrc15.Size = New System.Drawing.Size(32, 48)
        Me.LabelSrc15.TabIndex = 34
        Me.LabelSrc15.Text = "14"
        Me.LabelSrc15.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc14
        '
        Me.LabelSrc14.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc14.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc14.Location = New System.Drawing.Point(336, 304)
        Me.LabelSrc14.Name = "LabelSrc14"
        Me.LabelSrc14.Size = New System.Drawing.Size(32, 48)
        Me.LabelSrc14.TabIndex = 33
        Me.LabelSrc14.Text = "13"
        Me.LabelSrc14.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc13
        '
        Me.LabelSrc13.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc13.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc13.Location = New System.Drawing.Point(336, 248)
        Me.LabelSrc13.Name = "LabelSrc13"
        Me.LabelSrc13.Size = New System.Drawing.Size(32, 48)
        Me.LabelSrc13.TabIndex = 32
        Me.LabelSrc13.Text = "12"
        Me.LabelSrc13.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc12
        '
        Me.LabelSrc12.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc12.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc12.Location = New System.Drawing.Point(336, 192)
        Me.LabelSrc12.Name = "LabelSrc12"
        Me.LabelSrc12.Size = New System.Drawing.Size(32, 48)
        Me.LabelSrc12.TabIndex = 31
        Me.LabelSrc12.Text = "11"
        Me.LabelSrc12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc11
        '
        Me.LabelSrc11.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc11.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc11.Location = New System.Drawing.Point(336, 136)
        Me.LabelSrc11.Name = "LabelSrc11"
        Me.LabelSrc11.Size = New System.Drawing.Size(32, 48)
        Me.LabelSrc11.TabIndex = 30
        Me.LabelSrc11.Text = "10"
        Me.LabelSrc11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc10
        '
        Me.LabelSrc10.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc10.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc10.Location = New System.Drawing.Point(336, 80)
        Me.LabelSrc10.Name = "LabelSrc10"
        Me.LabelSrc10.Size = New System.Drawing.Size(32, 48)
        Me.LabelSrc10.TabIndex = 29
        Me.LabelSrc10.Text = "9"
        Me.LabelSrc10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc9
        '
        Me.LabelSrc9.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc9.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc9.Location = New System.Drawing.Point(336, 24)
        Me.LabelSrc9.Name = "LabelSrc9"
        Me.LabelSrc9.Size = New System.Drawing.Size(32, 48)
        Me.LabelSrc9.TabIndex = 28
        Me.LabelSrc9.Text = "8"
        Me.LabelSrc9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc8
        '
        Me.LabelSrc8.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc8.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc8.Location = New System.Drawing.Point(160, 416)
        Me.LabelSrc8.Name = "LabelSrc8"
        Me.LabelSrc8.Size = New System.Drawing.Size(24, 48)
        Me.LabelSrc8.TabIndex = 27
        Me.LabelSrc8.Text = "7"
        Me.LabelSrc8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc7
        '
        Me.LabelSrc7.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc7.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc7.Location = New System.Drawing.Point(160, 360)
        Me.LabelSrc7.Name = "LabelSrc7"
        Me.LabelSrc7.Size = New System.Drawing.Size(24, 48)
        Me.LabelSrc7.TabIndex = 26
        Me.LabelSrc7.Text = "6"
        Me.LabelSrc7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc6
        '
        Me.LabelSrc6.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc6.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc6.Location = New System.Drawing.Point(160, 304)
        Me.LabelSrc6.Name = "LabelSrc6"
        Me.LabelSrc6.Size = New System.Drawing.Size(24, 48)
        Me.LabelSrc6.TabIndex = 25
        Me.LabelSrc6.Text = "5"
        Me.LabelSrc6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc5
        '
        Me.LabelSrc5.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc5.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc5.Location = New System.Drawing.Point(160, 248)
        Me.LabelSrc5.Name = "LabelSrc5"
        Me.LabelSrc5.Size = New System.Drawing.Size(24, 48)
        Me.LabelSrc5.TabIndex = 24
        Me.LabelSrc5.Text = "4"
        Me.LabelSrc5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc4
        '
        Me.LabelSrc4.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc4.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc4.Location = New System.Drawing.Point(160, 192)
        Me.LabelSrc4.Name = "LabelSrc4"
        Me.LabelSrc4.Size = New System.Drawing.Size(24, 48)
        Me.LabelSrc4.TabIndex = 23
        Me.LabelSrc4.Text = "3"
        Me.LabelSrc4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc3
        '
        Me.LabelSrc3.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc3.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc3.Location = New System.Drawing.Point(160, 136)
        Me.LabelSrc3.Name = "LabelSrc3"
        Me.LabelSrc3.Size = New System.Drawing.Size(24, 48)
        Me.LabelSrc3.TabIndex = 22
        Me.LabelSrc3.Text = "2"
        Me.LabelSrc3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc2
        '
        Me.LabelSrc2.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc2.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc2.Location = New System.Drawing.Point(160, 80)
        Me.LabelSrc2.Name = "LabelSrc2"
        Me.LabelSrc2.Size = New System.Drawing.Size(24, 48)
        Me.LabelSrc2.TabIndex = 21
        Me.LabelSrc2.Text = "1"
        Me.LabelSrc2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelSrc1
        '
        Me.LabelSrc1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelSrc1.ImageAlign = System.Drawing.ContentAlignment.TopLeft
        Me.LabelSrc1.Location = New System.Drawing.Point(160, 24)
        Me.LabelSrc1.Name = "LabelSrc1"
        Me.LabelSrc1.Size = New System.Drawing.Size(24, 48)
        Me.LabelSrc1.TabIndex = 19
        Me.LabelSrc1.Text = "0"
        Me.LabelSrc1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'ButtonSrc15
        '
        Me.ButtonSrc15.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc15.Location = New System.Drawing.Point(192, 416)
        Me.ButtonSrc15.Name = "ButtonSrc15"
        Me.ButtonSrc15.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc15.TabIndex = 18
        Me.ButtonSrc15.Text = "Source 15"
        '
        'ButtonSrc14
        '
        Me.ButtonSrc14.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc14.Location = New System.Drawing.Point(192, 360)
        Me.ButtonSrc14.Name = "ButtonSrc14"
        Me.ButtonSrc14.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc14.TabIndex = 17
        Me.ButtonSrc14.Text = "Source 14"
        '
        'ButtonSrc7
        '
        Me.ButtonSrc7.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc7.Location = New System.Drawing.Point(16, 416)
        Me.ButtonSrc7.Name = "ButtonSrc7"
        Me.ButtonSrc7.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc7.TabIndex = 16
        Me.ButtonSrc7.Text = "Source 7"
        '
        'ButtonSrc6
        '
        Me.ButtonSrc6.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc6.Location = New System.Drawing.Point(16, 360)
        Me.ButtonSrc6.Name = "ButtonSrc6"
        Me.ButtonSrc6.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc6.TabIndex = 15
        Me.ButtonSrc6.Text = "Source 6"
        '
        'ButtonSrc13
        '
        Me.ButtonSrc13.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc13.Location = New System.Drawing.Point(192, 304)
        Me.ButtonSrc13.Name = "ButtonSrc13"
        Me.ButtonSrc13.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc13.TabIndex = 14
        Me.ButtonSrc13.Text = "Source 13"
        '
        'ButtonSrc12
        '
        Me.ButtonSrc12.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc12.Location = New System.Drawing.Point(192, 248)
        Me.ButtonSrc12.Name = "ButtonSrc12"
        Me.ButtonSrc12.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc12.TabIndex = 13
        Me.ButtonSrc12.Text = "Source 12"
        '
        'ButtonSrc11
        '
        Me.ButtonSrc11.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc11.Location = New System.Drawing.Point(192, 192)
        Me.ButtonSrc11.Name = "ButtonSrc11"
        Me.ButtonSrc11.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc11.TabIndex = 12
        Me.ButtonSrc11.Text = "Source 11"
        '
        'ButtonSrc10
        '
        Me.ButtonSrc10.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc10.Location = New System.Drawing.Point(192, 136)
        Me.ButtonSrc10.Name = "ButtonSrc10"
        Me.ButtonSrc10.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc10.TabIndex = 11
        Me.ButtonSrc10.Text = "Source 10"
        '
        'ButtonSrc9
        '
        Me.ButtonSrc9.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc9.Location = New System.Drawing.Point(192, 80)
        Me.ButtonSrc9.Name = "ButtonSrc9"
        Me.ButtonSrc9.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc9.TabIndex = 10
        Me.ButtonSrc9.Text = "Source 9"
        '
        'ButtonSrc8
        '
        Me.ButtonSrc8.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc8.Location = New System.Drawing.Point(192, 24)
        Me.ButtonSrc8.Name = "ButtonSrc8"
        Me.ButtonSrc8.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc8.TabIndex = 9
        Me.ButtonSrc8.Text = "Source 8"
        '
        'ButtonSrc5
        '
        Me.ButtonSrc5.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc5.Location = New System.Drawing.Point(16, 304)
        Me.ButtonSrc5.Name = "ButtonSrc5"
        Me.ButtonSrc5.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc5.TabIndex = 7
        Me.ButtonSrc5.Text = "Source 5"
        '
        'ButtonSrc4
        '
        Me.ButtonSrc4.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc4.Location = New System.Drawing.Point(16, 248)
        Me.ButtonSrc4.Name = "ButtonSrc4"
        Me.ButtonSrc4.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc4.TabIndex = 6
        Me.ButtonSrc4.Text = "Source 4"
        '
        'ButtonSrc3
        '
        Me.ButtonSrc3.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc3.Location = New System.Drawing.Point(16, 192)
        Me.ButtonSrc3.Name = "ButtonSrc3"
        Me.ButtonSrc3.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc3.TabIndex = 5
        Me.ButtonSrc3.Text = "Source 3"
        '
        'ButtonSrc2
        '
        Me.ButtonSrc2.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc2.Location = New System.Drawing.Point(16, 136)
        Me.ButtonSrc2.Name = "ButtonSrc2"
        Me.ButtonSrc2.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc2.TabIndex = 4
        Me.ButtonSrc2.Text = "Source 2"
        '
        'ButtonSrc1
        '
        Me.ButtonSrc1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc1.Location = New System.Drawing.Point(16, 80)
        Me.ButtonSrc1.Name = "ButtonSrc1"
        Me.ButtonSrc1.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc1.TabIndex = 3
        Me.ButtonSrc1.Text = "Source 1"
        '
        'ButtonSrc0
        '
        Me.ButtonSrc0.BackColor = System.Drawing.SystemColors.Control
        Me.ButtonSrc0.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonSrc0.Location = New System.Drawing.Point(16, 24)
        Me.ButtonSrc0.Name = "ButtonSrc0"
        Me.ButtonSrc0.Size = New System.Drawing.Size(136, 48)
        Me.ButtonSrc0.TabIndex = 2
        Me.ButtonSrc0.Text = "Source 0"
        '
        'GroupBoxDst
        '
        Me.GroupBoxDst.Controls.AddRange(New System.Windows.Forms.Control() {Me.LabelDst3, Me.LabelDst2, Me.ButtonDst7, Me.ButtonDst6, Me.ButtonDst5, Me.ButtonDst4, Me.ButtonDst3, Me.ButtonDst2, Me.ButtonDst1, Me.ButtonDst0, Me.LabelDst1, Me.LabelDst4, Me.LabelDst7, Me.LabelDst5, Me.LabelDst6})
        Me.GroupBoxDst.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.GroupBoxDst.Location = New System.Drawing.Point(408, 8)
        Me.GroupBoxDst.Name = "GroupBoxDst"
        Me.GroupBoxDst.Size = New System.Drawing.Size(312, 480)
        Me.GroupBoxDst.TabIndex = 16
        Me.GroupBoxDst.TabStop = False
        Me.GroupBoxDst.Text = "Focal Channel"
        '
        'LabelDst3
        '
        Me.LabelDst3.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelDst3.Location = New System.Drawing.Point(168, 192)
        Me.LabelDst3.Name = "LabelDst3"
        Me.LabelDst3.Size = New System.Drawing.Size(136, 48)
        Me.LabelDst3.TabIndex = 22
        Me.LabelDst3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'LabelDst2
        '
        Me.LabelDst2.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelDst2.Location = New System.Drawing.Point(168, 136)
        Me.LabelDst2.Name = "LabelDst2"
        Me.LabelDst2.Size = New System.Drawing.Size(136, 48)
        Me.LabelDst2.TabIndex = 21
        Me.LabelDst2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'ButtonDst7
        '
        Me.ButtonDst7.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonDst7.Location = New System.Drawing.Point(16, 416)
        Me.ButtonDst7.Name = "ButtonDst7"
        Me.ButtonDst7.Size = New System.Drawing.Size(136, 48)
        Me.ButtonDst7.TabIndex = 15
        '
        'ButtonDst6
        '
        Me.ButtonDst6.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonDst6.Location = New System.Drawing.Point(16, 360)
        Me.ButtonDst6.Name = "ButtonDst6"
        Me.ButtonDst6.Size = New System.Drawing.Size(136, 48)
        Me.ButtonDst6.TabIndex = 14
        '
        'ButtonDst5
        '
        Me.ButtonDst5.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonDst5.Location = New System.Drawing.Point(16, 304)
        Me.ButtonDst5.Name = "ButtonDst5"
        Me.ButtonDst5.Size = New System.Drawing.Size(136, 48)
        Me.ButtonDst5.TabIndex = 13
        '
        'ButtonDst4
        '
        Me.ButtonDst4.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonDst4.Location = New System.Drawing.Point(16, 248)
        Me.ButtonDst4.Name = "ButtonDst4"
        Me.ButtonDst4.Size = New System.Drawing.Size(136, 48)
        Me.ButtonDst4.TabIndex = 12
        '
        'ButtonDst3
        '
        Me.ButtonDst3.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonDst3.Location = New System.Drawing.Point(16, 192)
        Me.ButtonDst3.Name = "ButtonDst3"
        Me.ButtonDst3.Size = New System.Drawing.Size(136, 48)
        Me.ButtonDst3.TabIndex = 11
        '
        'ButtonDst2
        '
        Me.ButtonDst2.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonDst2.Location = New System.Drawing.Point(16, 136)
        Me.ButtonDst2.Name = "ButtonDst2"
        Me.ButtonDst2.Size = New System.Drawing.Size(136, 48)
        Me.ButtonDst2.TabIndex = 10
        '
        'ButtonDst1
        '
        Me.ButtonDst1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonDst1.Location = New System.Drawing.Point(16, 80)
        Me.ButtonDst1.Name = "ButtonDst1"
        Me.ButtonDst1.Size = New System.Drawing.Size(136, 48)
        Me.ButtonDst1.TabIndex = 9
        '
        'ButtonDst0
        '
        Me.ButtonDst0.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonDst0.Location = New System.Drawing.Point(16, 24)
        Me.ButtonDst0.Name = "ButtonDst0"
        Me.ButtonDst0.Size = New System.Drawing.Size(136, 48)
        Me.ButtonDst0.TabIndex = 8
        '
        'LabelDst1
        '
        Me.LabelDst1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelDst1.Location = New System.Drawing.Point(168, 80)
        Me.LabelDst1.Name = "LabelDst1"
        Me.LabelDst1.Size = New System.Drawing.Size(136, 48)
        Me.LabelDst1.TabIndex = 20
        Me.LabelDst1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'LabelDst4
        '
        Me.LabelDst4.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelDst4.Location = New System.Drawing.Point(168, 248)
        Me.LabelDst4.Name = "LabelDst4"
        Me.LabelDst4.Size = New System.Drawing.Size(136, 48)
        Me.LabelDst4.TabIndex = 23
        Me.LabelDst4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'LabelDst7
        '
        Me.LabelDst7.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelDst7.Location = New System.Drawing.Point(168, 416)
        Me.LabelDst7.Name = "LabelDst7"
        Me.LabelDst7.Size = New System.Drawing.Size(136, 48)
        Me.LabelDst7.TabIndex = 26
        Me.LabelDst7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'LabelDst5
        '
        Me.LabelDst5.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelDst5.Location = New System.Drawing.Point(168, 304)
        Me.LabelDst5.Name = "LabelDst5"
        Me.LabelDst5.Size = New System.Drawing.Size(136, 48)
        Me.LabelDst5.TabIndex = 24
        Me.LabelDst5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'LabelDst6
        '
        Me.LabelDst6.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelDst6.Location = New System.Drawing.Point(168, 360)
        Me.LabelDst6.Name = "LabelDst6"
        Me.LabelDst6.Size = New System.Drawing.Size(136, 48)
        Me.LabelDst6.TabIndex = 25
        Me.LabelDst6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'LabelStatus
        '
        Me.LabelStatus.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelStatus.Location = New System.Drawing.Point(24, 504)
        Me.LabelStatus.Name = "LabelStatus"
        Me.LabelStatus.Size = New System.Drawing.Size(72, 24)
        Me.LabelStatus.TabIndex = 17
        Me.LabelStatus.Text = "Status:"
        '
        'LabelCurrentStatus
        '
        Me.LabelCurrentStatus.BackColor = System.Drawing.Color.Red
        Me.LabelCurrentStatus.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.LabelCurrentStatus.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelCurrentStatus.ForeColor = System.Drawing.Color.Black
        Me.LabelCurrentStatus.Location = New System.Drawing.Point(96, 504)
        Me.LabelCurrentStatus.Name = "LabelCurrentStatus"
        Me.LabelCurrentStatus.Size = New System.Drawing.Size(152, 24)
        Me.LabelCurrentStatus.TabIndex = 18
        Me.LabelCurrentStatus.Text = "Dissconnected"
        Me.LabelCurrentStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'LabelDst0
        '
        Me.LabelDst0.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LabelDst0.Location = New System.Drawing.Point(576, 32)
        Me.LabelDst0.Name = "LabelDst0"
        Me.LabelDst0.Size = New System.Drawing.Size(136, 48)
        Me.LabelDst0.TabIndex = 19
        Me.LabelDst0.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'ButtonUndo
        '
        Me.ButtonUndo.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonUndo.Location = New System.Drawing.Point(400, 504)
        Me.ButtonUndo.Name = "ButtonUndo"
        Me.ButtonUndo.Size = New System.Drawing.Size(136, 24)
        Me.ButtonUndo.TabIndex = 20
        Me.ButtonUndo.Text = "Undo Last"
        '
        'TimerStatus
        '
        Me.TimerStatus.Interval = 1000
        '
        'FormMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(9, 22)
        Me.ClientSize = New System.Drawing.Size(730, 549)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ButtonUndo, Me.LabelDst0, Me.LabelCurrentStatus, Me.LabelStatus, Me.GroupBoxSrc, Me.GroupBoxDst})
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "FormMain"
        Me.Text = "Video Switch"
        Me.GroupBoxSrc.ResumeLayout(False)
        Me.GroupBoxDst.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'open the ini file
        Dim iniFileName As String = CurDir() + "\vidgui.ini"
        Dim iniFile As New IniFile(CurDir() + "\vidgui.ini")
        Dim Index As Integer

        Try
            FileLen(iniFileName)   ' Returns file length (bytes).
        Catch Ex As System.IO.FileNotFoundException
            'create a default cfg file
            MsgBox("Initialization file '" + iniFileName + "' not found, creating default file")

            'write the src names
            For Index = 0 To 15
                iniFile.WriteString("VideoSource", "src" + Trim(Str(Index)), "Source" + Str(Index))
            Next

            'write the dst names
            For Index = 0 To 7
                iniFile.WriteString("VideoDest", "dst" + Trim(Str(Index)), "Dest" + Str(Index))
            Next

            'write the defualt serial port entry
            iniFile.WriteInteger("SerialPort", "port", 1)


        End Try

        'grab the source buttons names
        For Index = 0 To 15
            sourceNameStr(Index) = _
                iniFile.GetString("VideoSource", "src" + Trim(Str(Index)), "Source" + Str(Index))
        Next

        'init the source button names
        'somebody needs to learn how to use control arrays
        ButtonSrc0.Text = sourceNameStr(0)
        ButtonSrc1.Text = sourceNameStr(1)
        ButtonSrc2.Text = sourceNameStr(2)
        ButtonSrc3.Text = sourceNameStr(3)
        ButtonSrc4.Text = sourceNameStr(4)
        ButtonSrc5.Text = sourceNameStr(5)
        ButtonSrc6.Text = sourceNameStr(6)
        ButtonSrc7.Text = sourceNameStr(7)
        ButtonSrc8.Text = sourceNameStr(8)
        ButtonSrc9.Text = sourceNameStr(9)
        ButtonSrc10.Text = sourceNameStr(10)
        ButtonSrc11.Text = sourceNameStr(11)
        ButtonSrc12.Text = sourceNameStr(12)
        ButtonSrc13.Text = sourceNameStr(13)
        ButtonSrc14.Text = sourceNameStr(14)
        ButtonSrc15.Text = sourceNameStr(15)

        'init desitnation labels
        LabelDst0.Text = iniFile.GetString("VideoDest", "dst0", "Dest 0")
        LabelDst1.Text = iniFile.GetString("VideoDest", "dst1", "Dest 1")
        LabelDst2.Text = iniFile.GetString("VideoDest", "dst2", "Dest 2")
        LabelDst3.Text = iniFile.GetString("VideoDest", "dst3", "Dest 3")
        LabelDst4.Text = iniFile.GetString("VideoDest", "dst4", "Dest 4")
        LabelDst5.Text = iniFile.GetString("VideoDest", "dst5", "Dest 5")
        LabelDst6.Text = iniFile.GetString("VideoDest", "dst6", "Dest 6")
        LabelDst7.Text = iniFile.GetString("VideoDest", "dst7", "Dest 7")

        'disable the dest buttons
        ButtonDst0.Enabled = False
        ButtonDst1.Enabled = False
        ButtonDst2.Enabled = False
        ButtonDst3.Enabled = False
        ButtonDst4.Enabled = False
        ButtonDst5.Enabled = False
        ButtonDst6.Enabled = False
        ButtonDst7.Enabled = False

        'gray out undo last until you get sate hsitory
        ButtonUndo.Enabled = False

        'get the default button color
        defaultBtnColor = ButtonSrc0.BackColor

        'intialize the source index
        sourceIndex = 0

        'set the source index label
        ButtonSrc0.BackColor = System.Drawing.Color.LightBlue

        'open the serial port to the switchter
        commPort.Open(iniFile.GetInteger("SerialPort", "port", 1), 9600, 8, _
                                         Rs232.DataParity.Parity_None, _
                                         Rs232.DataStopBit.StopBit_1, 1024)

        'shut the echo off
        SendCommand("echo 0")

        'get the state of the video switch and set the destination button names
        GetVideoSwitchState()

    End Sub

    Private Sub ButtonDst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDst0.Click, _
    ButtonDst1.Click, ButtonDst2.Click, ButtonDst3.Click, ButtonDst4.Click, ButtonDst5.Click, ButtonDst6.Click, ButtonDst7.Click
        Dim cmdStr As String
        Dim destIndex As Integer = -1

        'determine the dst index
        'need to use control array here
        If (sender.Equals(ButtonDst0)) Then
            destIndex = 0
            ButtonDst0.Text = sourceNameStr(sourceIndex)
        ElseIf (sender.Equals(ButtonDst1)) Then
            destIndex = 1
            ButtonDst1.Text = sourceNameStr(sourceIndex)
        ElseIf (sender.Equals(ButtonDst2)) Then
            destIndex = 2
            ButtonDst2.Text = sourceNameStr(sourceIndex)
        ElseIf (sender.Equals(ButtonDst3)) Then
            destIndex = 3
            ButtonDst3.Text = sourceNameStr(sourceIndex)
        ElseIf (sender.Equals(ButtonDst4)) Then
            destIndex = 4
            ButtonDst4.Text = sourceNameStr(sourceIndex)
        ElseIf (sender.Equals(ButtonDst5)) Then
            destIndex = 5
            ButtonDst5.Text = sourceNameStr(sourceIndex)
        ElseIf (sender.Equals(ButtonDst6)) Then
            destIndex = 6
            ButtonDst6.Text = sourceNameStr(sourceIndex)
        ElseIf (sender.Equals(ButtonDst7)) Then
            destIndex = 7
            ButtonDst7.Text = sourceNameStr(sourceIndex)
        End If


        'if you got a valid destination go for it
        If (destIndex > -1) Then

            'form the command "S [DST] [SRC]"
            cmdStr = "S " + Trim(Str(destIndex)) + " " + Trim(Str(sourceIndex))

            ' save last source dest combo and enable undo button
            undoLastSrcDst(0) = videoSwitchState(destIndex)
            undoLastSrcDst(1) = destIndex
            ButtonUndo.Enabled = True

            'update the videoSwitchstate
            videoSwitchState(destIndex) = sourceIndex

            'send the command
            SendCommand(cmdStr)

            'you need error checking here to make sure that the button is in the ritght state
            'resync with get switch state it there is a problem

        End If

    End Sub

    Private Sub ButtonSrc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSrc0.Click, _
    ButtonSrc1.Click, ButtonSrc2.Click, ButtonSrc3.Click, ButtonSrc4.Click, ButtonSrc5.Click, ButtonSrc6.Click, _
    ButtonSrc7.Click, ButtonSrc8.Click, ButtonSrc9.Click, ButtonSrc10.Click, ButtonSrc11.Click, ButtonSrc12.Click, _
    ButtonSrc13.Click, ButtonSrc14.Click, ButtonSrc15.Click

        'set the back collor of all buttons to default
        'this is a cheezy way to do this, again control array is the ticket
        ButtonSrc0.BackColor = defaultBtnColor
        ButtonSrc1.BackColor = defaultBtnColor
        ButtonSrc2.BackColor = defaultBtnColor
        ButtonSrc3.BackColor = defaultBtnColor
        ButtonSrc4.BackColor = defaultBtnColor
        ButtonSrc5.BackColor = defaultBtnColor
        ButtonSrc6.BackColor = defaultBtnColor
        ButtonSrc7.BackColor = defaultBtnColor
        ButtonSrc8.BackColor = defaultBtnColor
        ButtonSrc9.BackColor = defaultBtnColor
        ButtonSrc10.BackColor = defaultBtnColor
        ButtonSrc11.BackColor = defaultBtnColor
        ButtonSrc12.BackColor = defaultBtnColor
        ButtonSrc13.BackColor = defaultBtnColor
        ButtonSrc14.BackColor = defaultBtnColor
        ButtonSrc15.BackColor = defaultBtnColor

        'figure out who sent it and set button color and sourceIndex accordingly
        If (sender.Equals(ButtonSrc0)) Then
            sourceIndex = 0
            ButtonSrc0.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc1)) Then
            sourceIndex = 1
            ButtonSrc1.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc2)) Then
            sourceIndex = 2
            ButtonSrc2.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc3)) Then
            sourceIndex = 3
            ButtonSrc3.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc4)) Then
            sourceIndex = 4
            ButtonSrc4.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc5)) Then
            sourceIndex = 5
            ButtonSrc5.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc6)) Then
            sourceIndex = 6
            ButtonSrc6.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc7)) Then
            sourceIndex = 7
            ButtonSrc7.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc8)) Then
            sourceIndex = 8
            ButtonSrc8.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc9)) Then
            sourceIndex = 9
            ButtonSrc9.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc10)) Then
            sourceIndex = 10
            ButtonSrc10.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc11)) Then
            sourceIndex = 11
            ButtonSrc11.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc12)) Then
            sourceIndex = 12
            ButtonSrc12.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc13)) Then
            sourceIndex = 13
            ButtonSrc13.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc14)) Then
            sourceIndex = 14
            ButtonSrc14.BackColor = System.Drawing.Color.LightBlue()
        ElseIf (sender.Equals(ButtonSrc15)) Then
            sourceIndex = 15
            ButtonSrc15.BackColor = System.Drawing.Color.LightBlue()
        End If


    End Sub


    Private Sub ButtonUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUndo.Click

        'perfrom source button click according to undo last array
        If (undoLastSrcDst(0) = 0) Then
            ButtonSrc0.PerformClick()
        ElseIf (undoLastSrcDst(0) = 1) Then
            ButtonSrc1.PerformClick()
        ElseIf (undoLastSrcDst(0) = 2) Then
            ButtonSrc2.PerformClick()
        ElseIf (undoLastSrcDst(0) = 3) Then
            ButtonSrc3.PerformClick()
        ElseIf (undoLastSrcDst(0) = 4) Then
            ButtonSrc4.PerformClick()
        ElseIf (undoLastSrcDst(0) = 5) Then
            ButtonSrc5.PerformClick()
        ElseIf (undoLastSrcDst(0) = 6) Then
            ButtonSrc6.PerformClick()
        ElseIf (undoLastSrcDst(0) = 7) Then
            ButtonSrc7.PerformClick()
        ElseIf (undoLastSrcDst(0) = 8) Then
            ButtonSrc8.PerformClick()
        ElseIf (undoLastSrcDst(0) = 9) Then
            ButtonSrc9.PerformClick()
        ElseIf (undoLastSrcDst(0) = 10) Then
            ButtonSrc10.PerformClick()
        ElseIf (undoLastSrcDst(0) = 11) Then
            ButtonSrc11.PerformClick()
        ElseIf (undoLastSrcDst(0) = 12) Then
            ButtonSrc12.PerformClick()
        ElseIf (undoLastSrcDst(0) = 13) Then
            ButtonSrc13.PerformClick()
        ElseIf (undoLastSrcDst(0) = 14) Then
            ButtonSrc14.PerformClick()
        ElseIf (undoLastSrcDst(0) = 15) Then
            ButtonSrc15.PerformClick()
        End If

        'perfrom destination button click according to undo last array
        If (undoLastSrcDst(1) = 0) Then
            ButtonDst0.PerformClick()
        ElseIf (undoLastSrcDst(1) = 1) Then
            ButtonDst1.PerformClick()
        ElseIf (undoLastSrcDst(1) = 2) Then
            ButtonDst2.PerformClick()
        ElseIf (undoLastSrcDst(1) = 3) Then
            ButtonDst3.PerformClick()
        ElseIf (undoLastSrcDst(1) = 4) Then
            ButtonDst4.PerformClick()
        ElseIf (undoLastSrcDst(1) = 5) Then
            ButtonDst5.PerformClick()
        ElseIf (undoLastSrcDst(1) = 6) Then
            ButtonDst6.PerformClick()
        ElseIf (undoLastSrcDst(1) = 7) Then
            ButtonDst7.PerformClick()
        End If

        'there is only one level of undo so disable the button
        ButtonUndo.Enabled = False

    End Sub

    Private Sub TimerStatus_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerStatus.Tick

        Static lastCheckOK As Boolean = False

        'check for the version string
        If (Mid(SendCommand("V", 1000), 1, 7) = "Ventana") Then
            TimerStatus.Enabled = False

            'if you got the version and the last check was OK enable the timer and bail
            If lastCheckOK Then
                TimerStatus.Enabled = True
                Return
            End If

            'if the last check failed you are going from a disconnected to a connected state
            'make sure your house is in order
            lastCheckOK = True
            LabelCurrentStatus.Text = "Connected"
            LabelCurrentStatus.BackColor = System.Drawing.Color.LightGreen

            'shut the echo off just in case
            SendCommand("echo 0")

            'reinit the video switch state, again just in case
            GetVideoSwitchState()

            'enable the dest buttons, you are back in business
            ButtonDst0.Enabled = True
            ButtonDst1.Enabled = True
            ButtonDst2.Enabled = True
            ButtonDst3.Enabled = True
            ButtonDst4.Enabled = True
            ButtonDst5.Enabled = True
            ButtonDst6.Enabled = True
            ButtonDst7.Enabled = True

            'start the timer and bail
            TimerStatus.Enabled = True

            Return

        End If

        'the check failed
        lastCheckOK = False

        TimerStatus.Enabled = False

        'can't use the dest buttons if you are not connected
        ButtonDst0.Enabled = False
        ButtonDst1.Enabled = False
        ButtonDst2.Enabled = False
        ButtonDst3.Enabled = False
        ButtonDst4.Enabled = False
        ButtonDst5.Enabled = False
        ButtonDst6.Enabled = False
        ButtonDst7.Enabled = False

        'let the user know that something is rotten in Denmark
        LabelCurrentStatus.Text = "Disconnected"
        LabelCurrentStatus.BackColor = System.Drawing.Color.Red

        'start the timer and to keep rechecking
        TimerStatus.Enabled = True

    End Sub

    Private Sub LabelCurrentStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelCurrentStatus.Click
        'Display results in a message box
        MsgBox(SendCommand("G"))

    End Sub

    Private Function SendCommand(ByRef Cmd As String) As String
        Return SendCommand(Cmd, 3000)
    End Function

    Private Function SendCommand(ByRef Cmd As String, ByVal TimeOut As Integer) As String
        Dim Index As Integer
        Dim rxBuff(1024) As Byte
        Dim rxString As String
        Dim termStr As String = "RDY" + Chr(13)
        Dim termBuff(termStr.Length) As Byte
        Dim bytesRead As Integer

        'don't poll for status during a command exchange
        TimerStatus.Enabled = False

        'turn the terminator into a byte buffer
        For Index = 0 To termStr.Length - 1
            termBuff(Index) = Asc(Mid(termStr, Index + 1, 1))
        Next Index

        'send the command out followed by a CR
        commPort.Write(Cmd + Chr(13))

        'readUntil RDY
        bytesRead = ReadUntil(rxBuff, termBuff, TimeOut)

        'this should throw and exception that can be handled by the caller
        If (bytesRead < 0) Then
            Return ""
        End If

        'convert the response to a string
        For Index = 0 To bytesRead
            rxString = rxString & Chr(rxBuff(Index))
        Next

        'you can start polling the switch again
        TimerStatus.Enabled = True

        Return rxString

    End Function

    Private Sub GetVideoSwitchState()
        Dim switchState As String
        Dim Index As Integer
        Dim Src As Double
        Dim Dst As Double
        Dim tmpStr As String = ""

        'send the video switch a 'G' command
        switchState = SendCommand("G")

        'parse video state "SRC ## DST ##\r"
        For Index = 0 To 7
            'to grab dst do this Mid(switchState, Index * 14 + 5, 2)

            'grab the source channel for destination 0 through 7
            videoSwitchState(Index) = Val(Mid(switchState, Index * 14 + 12, 2))
        Next

        'set dest buttons accordingly
        'some body needs to learn how to use control arrays
        ButtonDst0.Text = sourceNameStr(videoSwitchState(0))
        ButtonDst1.Text = sourceNameStr(videoSwitchState(1))
        ButtonDst2.Text = sourceNameStr(videoSwitchState(2))
        ButtonDst3.Text = sourceNameStr(videoSwitchState(3))
        ButtonDst4.Text = sourceNameStr(videoSwitchState(4))
        ButtonDst5.Text = sourceNameStr(videoSwitchState(5))
        ButtonDst6.Text = sourceNameStr(videoSwitchState(6))
        ButtonDst7.Text = sourceNameStr(videoSwitchState(7))

        'convert the response to a string
        'For Index = 0 To 15
        '   tmpStr = tmpStr & ("src = " + Str(videoSwitchState(Index)) + Chr(13))
        'Next

        'MsgBox(tmpStr)
    End Sub

    Private Function ReadUntil(ByRef buffer As Byte(), ByVal term As Byte(), ByVal timeout As Integer) As Integer

        Dim StartTime As Date = Now   ' Starting date/time.
        ' Run the process that is to be timed.
        Dim Index As Integer = 0
        Dim termIndex As Integer = 0
        Dim elapsedTime As Integer = 0

        'MsgBox("term.Length = " + Str(term.Length))

        While ((elapsedTime < timeout) And (Index < buffer.Length))

            Try
                ' As long as there is information, read one byte at a time and 
                '   output it.
                If (commPort.Read(1) > 0) Then

                    buffer(Index) = commPort.InputStream(0)

                    If (buffer(Index) = term(termIndex)) Then

                        'MsgBox("Got term char '" + Str(buffer(Index)) + "'")
                        termIndex = termIndex + 1
                        If (term(termIndex) = 0) Then
                            Return Index - term.Length + 2
                        End If
                    Else
                        termIndex = 0
                    End If

                    Index = Index + 1
                End If
            Catch exc As Exception
                Application.DoEvents()
                System.Threading.Thread.Sleep(100)
                ' An exception is raised when there is no information to read.
                '   Don't do anything here, just let the exception go.
            End Try
            elapsedTime = Now.Subtract(StartTime).Milliseconds() + (Now.Subtract(StartTime).Seconds() * 1000)
        End While

        If (elapsedTime > timeout) Then
            Return Index - term.Length
        End If

        Return Index - term.Length

    End Function

End Class
