'Copyright (C) 2002 Microsoft Corporation
'All rights reserved.
'THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 
'EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
'MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

'Requires the Trial or Release version of Visual Studio .NET Professional (or greater).

Option Strict On

Imports System.Text
Imports System.IO
'\Windows\System32\Drivers\FTD2XX.SYS
'C:\Windows\System32\Drivers\FTSER2K.SYS

Public Class frmMain
	Inherits System.Windows.Forms.Form

    ' Declare necessary class variables.
    Private m_CommPort As New COMport_DirectUSB
    Dim Detected_Driver As String
    Private m_IsLCICFound As Boolean = False
    Private m_LCICPort As Integer = 0
    Dim iBaudRate As Integer = 115200
    Public cMaxNumberOfPorts As Integer = 255
    Public RealMaxNumberOfPorts As Integer = 255
    Dim NumDevs As Integer
    Public Serial_Number(255) As String
    Dim PortType As String = "COM"


#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

        ' So that we only need to set the title of the application once,
        ' we use the AssemblyInfo class (defined in the AssemblyInfo.vb file)
        ' to read the AssemblyTitle attribute.
        Dim ainfo As New AssemblyInfo

        Me.Text = ainfo.Title
        Me.mnuAbout.Text = String.Format("&About {0} ...", ainfo.Title)

    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 mnuMain As System.Windows.Forms.MainMenu
    Friend WithEvents mnuFile As System.Windows.Forms.MenuItem
    Friend WithEvents mnuExit As System.Windows.Forms.MenuItem
    Friend WithEvents mnuHelp As System.Windows.Forms.MenuItem
    Friend WithEvents mnuAbout As System.Windows.Forms.MenuItem
    Friend WithEvents txtStatus As System.Windows.Forms.TextBox
    Friend WithEvents clstPorts As System.Windows.Forms.CheckedListBox
    Friend WithEvents btnCheckForPorts As System.Windows.Forms.Button
    Friend WithEvents btnSendUserCommand As System.Windows.Forms.Button
    Friend WithEvents btnClear As System.Windows.Forms.Button
    Friend WithEvents GrUserCommand As System.Windows.Forms.GroupBox
    Friend WithEvents ChkWithRet As System.Windows.Forms.CheckBox
    Friend WithEvents txtUserCommand As System.Windows.Forms.TextBox
    Friend WithEvents btnCheckLCIC As System.Windows.Forms.Button
    Friend WithEvents txtSelectedLCIC As System.Windows.Forms.TextBox
    Friend WithEvents GrBaudrate As System.Windows.Forms.GroupBox
    Friend WithEvents cbxBaudrate As System.Windows.Forms.ComboBox
    Friend WithEvents btnStop_Fast_Mode As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmMain))
        Me.mnuMain = New System.Windows.Forms.MainMenu
        Me.mnuFile = New System.Windows.Forms.MenuItem
        Me.mnuExit = New System.Windows.Forms.MenuItem
        Me.mnuHelp = New System.Windows.Forms.MenuItem
        Me.mnuAbout = New System.Windows.Forms.MenuItem
        Me.btnCheckForPorts = New System.Windows.Forms.Button
        Me.txtStatus = New System.Windows.Forms.TextBox
        Me.clstPorts = New System.Windows.Forms.CheckedListBox
        Me.btnCheckLCIC = New System.Windows.Forms.Button
        Me.txtSelectedLCIC = New System.Windows.Forms.TextBox
        Me.btnSendUserCommand = New System.Windows.Forms.Button
        Me.btnClear = New System.Windows.Forms.Button
        Me.GrUserCommand = New System.Windows.Forms.GroupBox
        Me.ChkWithRet = New System.Windows.Forms.CheckBox
        Me.txtUserCommand = New System.Windows.Forms.TextBox
        Me.GrBaudrate = New System.Windows.Forms.GroupBox
        Me.cbxBaudrate = New System.Windows.Forms.ComboBox
        Me.btnStop_Fast_Mode = New System.Windows.Forms.Button
        Me.GrUserCommand.SuspendLayout()
        Me.GrBaudrate.SuspendLayout()
        Me.SuspendLayout()
        '
        'mnuMain
        '
        Me.mnuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuHelp})
        Me.mnuMain.RightToLeft = CType(resources.GetObject("mnuMain.RightToLeft"), System.Windows.Forms.RightToLeft)
        '
        'mnuFile
        '
        Me.mnuFile.Enabled = CType(resources.GetObject("mnuFile.Enabled"), Boolean)
        Me.mnuFile.Index = 0
        Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuExit})
        Me.mnuFile.Shortcut = CType(resources.GetObject("mnuFile.Shortcut"), System.Windows.Forms.Shortcut)
        Me.mnuFile.ShowShortcut = CType(resources.GetObject("mnuFile.ShowShortcut"), Boolean)
        Me.mnuFile.Text = resources.GetString("mnuFile.Text")
        Me.mnuFile.Visible = CType(resources.GetObject("mnuFile.Visible"), Boolean)
        '
        'mnuExit
        '
        Me.mnuExit.Enabled = CType(resources.GetObject("mnuExit.Enabled"), Boolean)
        Me.mnuExit.Index = 0
        Me.mnuExit.Shortcut = CType(resources.GetObject("mnuExit.Shortcut"), System.Windows.Forms.Shortcut)
        Me.mnuExit.ShowShortcut = CType(resources.GetObject("mnuExit.ShowShortcut"), Boolean)
        Me.mnuExit.Text = resources.GetString("mnuExit.Text")
        Me.mnuExit.Visible = CType(resources.GetObject("mnuExit.Visible"), Boolean)
        '
        'mnuHelp
        '
        Me.mnuHelp.Enabled = CType(resources.GetObject("mnuHelp.Enabled"), Boolean)
        Me.mnuHelp.Index = 1
        Me.mnuHelp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuAbout})
        Me.mnuHelp.Shortcut = CType(resources.GetObject("mnuHelp.Shortcut"), System.Windows.Forms.Shortcut)
        Me.mnuHelp.ShowShortcut = CType(resources.GetObject("mnuHelp.ShowShortcut"), Boolean)
        Me.mnuHelp.Text = resources.GetString("mnuHelp.Text")
        Me.mnuHelp.Visible = CType(resources.GetObject("mnuHelp.Visible"), Boolean)
        '
        'mnuAbout
        '
        Me.mnuAbout.Enabled = CType(resources.GetObject("mnuAbout.Enabled"), Boolean)
        Me.mnuAbout.Index = 0
        Me.mnuAbout.Shortcut = CType(resources.GetObject("mnuAbout.Shortcut"), System.Windows.Forms.Shortcut)
        Me.mnuAbout.ShowShortcut = CType(resources.GetObject("mnuAbout.ShowShortcut"), Boolean)
        Me.mnuAbout.Text = resources.GetString("mnuAbout.Text")
        Me.mnuAbout.Visible = CType(resources.GetObject("mnuAbout.Visible"), Boolean)
        '
        'btnCheckForPorts
        '
        Me.btnCheckForPorts.AccessibleDescription = resources.GetString("btnCheckForPorts.AccessibleDescription")
        Me.btnCheckForPorts.AccessibleName = resources.GetString("btnCheckForPorts.AccessibleName")
        Me.btnCheckForPorts.Anchor = CType(resources.GetObject("btnCheckForPorts.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnCheckForPorts.BackgroundImage = CType(resources.GetObject("btnCheckForPorts.BackgroundImage"), System.Drawing.Image)
        Me.btnCheckForPorts.Dock = CType(resources.GetObject("btnCheckForPorts.Dock"), System.Windows.Forms.DockStyle)
        Me.btnCheckForPorts.Enabled = CType(resources.GetObject("btnCheckForPorts.Enabled"), Boolean)
        Me.btnCheckForPorts.FlatStyle = CType(resources.GetObject("btnCheckForPorts.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnCheckForPorts.Font = CType(resources.GetObject("btnCheckForPorts.Font"), System.Drawing.Font)
        Me.btnCheckForPorts.Image = CType(resources.GetObject("btnCheckForPorts.Image"), System.Drawing.Image)
        Me.btnCheckForPorts.ImageAlign = CType(resources.GetObject("btnCheckForPorts.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnCheckForPorts.ImageIndex = CType(resources.GetObject("btnCheckForPorts.ImageIndex"), Integer)
        Me.btnCheckForPorts.ImeMode = CType(resources.GetObject("btnCheckForPorts.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnCheckForPorts.Location = CType(resources.GetObject("btnCheckForPorts.Location"), System.Drawing.Point)
        Me.btnCheckForPorts.Name = "btnCheckForPorts"
        Me.btnCheckForPorts.RightToLeft = CType(resources.GetObject("btnCheckForPorts.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnCheckForPorts.Size = CType(resources.GetObject("btnCheckForPorts.Size"), System.Drawing.Size)
        Me.btnCheckForPorts.TabIndex = CType(resources.GetObject("btnCheckForPorts.TabIndex"), Integer)
        Me.btnCheckForPorts.Text = resources.GetString("btnCheckForPorts.Text")
        Me.btnCheckForPorts.TextAlign = CType(resources.GetObject("btnCheckForPorts.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnCheckForPorts.Visible = CType(resources.GetObject("btnCheckForPorts.Visible"), Boolean)
        '
        'txtStatus
        '
        Me.txtStatus.AccessibleDescription = resources.GetString("txtStatus.AccessibleDescription")
        Me.txtStatus.AccessibleName = resources.GetString("txtStatus.AccessibleName")
        Me.txtStatus.Anchor = CType(resources.GetObject("txtStatus.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.txtStatus.AutoSize = CType(resources.GetObject("txtStatus.AutoSize"), Boolean)
        Me.txtStatus.BackgroundImage = CType(resources.GetObject("txtStatus.BackgroundImage"), System.Drawing.Image)
        Me.txtStatus.Dock = CType(resources.GetObject("txtStatus.Dock"), System.Windows.Forms.DockStyle)
        Me.txtStatus.Enabled = CType(resources.GetObject("txtStatus.Enabled"), Boolean)
        Me.txtStatus.Font = CType(resources.GetObject("txtStatus.Font"), System.Drawing.Font)
        Me.txtStatus.ImeMode = CType(resources.GetObject("txtStatus.ImeMode"), System.Windows.Forms.ImeMode)
        Me.txtStatus.Location = CType(resources.GetObject("txtStatus.Location"), System.Drawing.Point)
        Me.txtStatus.MaxLength = CType(resources.GetObject("txtStatus.MaxLength"), Integer)
        Me.txtStatus.Multiline = CType(resources.GetObject("txtStatus.Multiline"), Boolean)
        Me.txtStatus.Name = "txtStatus"
        Me.txtStatus.PasswordChar = CType(resources.GetObject("txtStatus.PasswordChar"), Char)
        Me.txtStatus.ReadOnly = True
        Me.txtStatus.RightToLeft = CType(resources.GetObject("txtStatus.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.txtStatus.ScrollBars = CType(resources.GetObject("txtStatus.ScrollBars"), System.Windows.Forms.ScrollBars)
        Me.txtStatus.Size = CType(resources.GetObject("txtStatus.Size"), System.Drawing.Size)
        Me.txtStatus.TabIndex = CType(resources.GetObject("txtStatus.TabIndex"), Integer)
        Me.txtStatus.Text = resources.GetString("txtStatus.Text")
        Me.txtStatus.TextAlign = CType(resources.GetObject("txtStatus.TextAlign"), System.Windows.Forms.HorizontalAlignment)
        Me.txtStatus.Visible = CType(resources.GetObject("txtStatus.Visible"), Boolean)
        Me.txtStatus.WordWrap = CType(resources.GetObject("txtStatus.WordWrap"), Boolean)
        '
        'clstPorts
        '
        Me.clstPorts.AccessibleDescription = resources.GetString("clstPorts.AccessibleDescription")
        Me.clstPorts.AccessibleName = resources.GetString("clstPorts.AccessibleName")
        Me.clstPorts.Anchor = CType(resources.GetObject("clstPorts.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.clstPorts.BackgroundImage = CType(resources.GetObject("clstPorts.BackgroundImage"), System.Drawing.Image)
        Me.clstPorts.ColumnWidth = CType(resources.GetObject("clstPorts.ColumnWidth"), Integer)
        Me.clstPorts.Dock = CType(resources.GetObject("clstPorts.Dock"), System.Windows.Forms.DockStyle)
        Me.clstPorts.Enabled = CType(resources.GetObject("clstPorts.Enabled"), Boolean)
        Me.clstPorts.Font = CType(resources.GetObject("clstPorts.Font"), System.Drawing.Font)
        Me.clstPorts.HorizontalExtent = CType(resources.GetObject("clstPorts.HorizontalExtent"), Integer)
        Me.clstPorts.HorizontalScrollbar = CType(resources.GetObject("clstPorts.HorizontalScrollbar"), Boolean)
        Me.clstPorts.ImeMode = CType(resources.GetObject("clstPorts.ImeMode"), System.Windows.Forms.ImeMode)
        Me.clstPorts.IntegralHeight = CType(resources.GetObject("clstPorts.IntegralHeight"), Boolean)
        Me.clstPorts.Location = CType(resources.GetObject("clstPorts.Location"), System.Drawing.Point)
        Me.clstPorts.Name = "clstPorts"
        Me.clstPorts.RightToLeft = CType(resources.GetObject("clstPorts.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.clstPorts.ScrollAlwaysVisible = CType(resources.GetObject("clstPorts.ScrollAlwaysVisible"), Boolean)
        Me.clstPorts.Size = CType(resources.GetObject("clstPorts.Size"), System.Drawing.Size)
        Me.clstPorts.TabIndex = CType(resources.GetObject("clstPorts.TabIndex"), Integer)
        Me.clstPorts.TabStop = False
        Me.clstPorts.Visible = CType(resources.GetObject("clstPorts.Visible"), Boolean)
        '
        'btnCheckLCIC
        '
        Me.btnCheckLCIC.AccessibleDescription = resources.GetString("btnCheckLCIC.AccessibleDescription")
        Me.btnCheckLCIC.AccessibleName = resources.GetString("btnCheckLCIC.AccessibleName")
        Me.btnCheckLCIC.Anchor = CType(resources.GetObject("btnCheckLCIC.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnCheckLCIC.BackgroundImage = CType(resources.GetObject("btnCheckLCIC.BackgroundImage"), System.Drawing.Image)
        Me.btnCheckLCIC.Dock = CType(resources.GetObject("btnCheckLCIC.Dock"), System.Windows.Forms.DockStyle)
        Me.btnCheckLCIC.Enabled = CType(resources.GetObject("btnCheckLCIC.Enabled"), Boolean)
        Me.btnCheckLCIC.FlatStyle = CType(resources.GetObject("btnCheckLCIC.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnCheckLCIC.Font = CType(resources.GetObject("btnCheckLCIC.Font"), System.Drawing.Font)
        Me.btnCheckLCIC.Image = CType(resources.GetObject("btnCheckLCIC.Image"), System.Drawing.Image)
        Me.btnCheckLCIC.ImageAlign = CType(resources.GetObject("btnCheckLCIC.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnCheckLCIC.ImageIndex = CType(resources.GetObject("btnCheckLCIC.ImageIndex"), Integer)
        Me.btnCheckLCIC.ImeMode = CType(resources.GetObject("btnCheckLCIC.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnCheckLCIC.Location = CType(resources.GetObject("btnCheckLCIC.Location"), System.Drawing.Point)
        Me.btnCheckLCIC.Name = "btnCheckLCIC"
        Me.btnCheckLCIC.RightToLeft = CType(resources.GetObject("btnCheckLCIC.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnCheckLCIC.Size = CType(resources.GetObject("btnCheckLCIC.Size"), System.Drawing.Size)
        Me.btnCheckLCIC.TabIndex = CType(resources.GetObject("btnCheckLCIC.TabIndex"), Integer)
        Me.btnCheckLCIC.Text = resources.GetString("btnCheckLCIC.Text")
        Me.btnCheckLCIC.TextAlign = CType(resources.GetObject("btnCheckLCIC.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnCheckLCIC.Visible = CType(resources.GetObject("btnCheckLCIC.Visible"), Boolean)
        '
        'txtSelectedLCIC
        '
        Me.txtSelectedLCIC.AccessibleDescription = resources.GetString("txtSelectedLCIC.AccessibleDescription")
        Me.txtSelectedLCIC.AccessibleName = resources.GetString("txtSelectedLCIC.AccessibleName")
        Me.txtSelectedLCIC.Anchor = CType(resources.GetObject("txtSelectedLCIC.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.txtSelectedLCIC.AutoSize = CType(resources.GetObject("txtSelectedLCIC.AutoSize"), Boolean)
        Me.txtSelectedLCIC.BackgroundImage = CType(resources.GetObject("txtSelectedLCIC.BackgroundImage"), System.Drawing.Image)
        Me.txtSelectedLCIC.Dock = CType(resources.GetObject("txtSelectedLCIC.Dock"), System.Windows.Forms.DockStyle)
        Me.txtSelectedLCIC.Enabled = CType(resources.GetObject("txtSelectedLCIC.Enabled"), Boolean)
        Me.txtSelectedLCIC.Font = CType(resources.GetObject("txtSelectedLCIC.Font"), System.Drawing.Font)
        Me.txtSelectedLCIC.ImeMode = CType(resources.GetObject("txtSelectedLCIC.ImeMode"), System.Windows.Forms.ImeMode)
        Me.txtSelectedLCIC.Location = CType(resources.GetObject("txtSelectedLCIC.Location"), System.Drawing.Point)
        Me.txtSelectedLCIC.MaxLength = CType(resources.GetObject("txtSelectedLCIC.MaxLength"), Integer)
        Me.txtSelectedLCIC.Multiline = CType(resources.GetObject("txtSelectedLCIC.Multiline"), Boolean)
        Me.txtSelectedLCIC.Name = "txtSelectedLCIC"
        Me.txtSelectedLCIC.PasswordChar = CType(resources.GetObject("txtSelectedLCIC.PasswordChar"), Char)
        Me.txtSelectedLCIC.RightToLeft = CType(resources.GetObject("txtSelectedLCIC.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.txtSelectedLCIC.ScrollBars = CType(resources.GetObject("txtSelectedLCIC.ScrollBars"), System.Windows.Forms.ScrollBars)
        Me.txtSelectedLCIC.Size = CType(resources.GetObject("txtSelectedLCIC.Size"), System.Drawing.Size)
        Me.txtSelectedLCIC.TabIndex = CType(resources.GetObject("txtSelectedLCIC.TabIndex"), Integer)
        Me.txtSelectedLCIC.Text = resources.GetString("txtSelectedLCIC.Text")
        Me.txtSelectedLCIC.TextAlign = CType(resources.GetObject("txtSelectedLCIC.TextAlign"), System.Windows.Forms.HorizontalAlignment)
        Me.txtSelectedLCIC.Visible = CType(resources.GetObject("txtSelectedLCIC.Visible"), Boolean)
        Me.txtSelectedLCIC.WordWrap = CType(resources.GetObject("txtSelectedLCIC.WordWrap"), Boolean)
        '
        'btnSendUserCommand
        '
        Me.btnSendUserCommand.AccessibleDescription = resources.GetString("btnSendUserCommand.AccessibleDescription")
        Me.btnSendUserCommand.AccessibleName = resources.GetString("btnSendUserCommand.AccessibleName")
        Me.btnSendUserCommand.Anchor = CType(resources.GetObject("btnSendUserCommand.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnSendUserCommand.BackgroundImage = CType(resources.GetObject("btnSendUserCommand.BackgroundImage"), System.Drawing.Image)
        Me.btnSendUserCommand.Dock = CType(resources.GetObject("btnSendUserCommand.Dock"), System.Windows.Forms.DockStyle)
        Me.btnSendUserCommand.Enabled = CType(resources.GetObject("btnSendUserCommand.Enabled"), Boolean)
        Me.btnSendUserCommand.FlatStyle = CType(resources.GetObject("btnSendUserCommand.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnSendUserCommand.Font = CType(resources.GetObject("btnSendUserCommand.Font"), System.Drawing.Font)
        Me.btnSendUserCommand.Image = CType(resources.GetObject("btnSendUserCommand.Image"), System.Drawing.Image)
        Me.btnSendUserCommand.ImageAlign = CType(resources.GetObject("btnSendUserCommand.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnSendUserCommand.ImageIndex = CType(resources.GetObject("btnSendUserCommand.ImageIndex"), Integer)
        Me.btnSendUserCommand.ImeMode = CType(resources.GetObject("btnSendUserCommand.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnSendUserCommand.Location = CType(resources.GetObject("btnSendUserCommand.Location"), System.Drawing.Point)
        Me.btnSendUserCommand.Name = "btnSendUserCommand"
        Me.btnSendUserCommand.RightToLeft = CType(resources.GetObject("btnSendUserCommand.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnSendUserCommand.Size = CType(resources.GetObject("btnSendUserCommand.Size"), System.Drawing.Size)
        Me.btnSendUserCommand.TabIndex = CType(resources.GetObject("btnSendUserCommand.TabIndex"), Integer)
        Me.btnSendUserCommand.Text = resources.GetString("btnSendUserCommand.Text")
        Me.btnSendUserCommand.TextAlign = CType(resources.GetObject("btnSendUserCommand.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnSendUserCommand.Visible = CType(resources.GetObject("btnSendUserCommand.Visible"), Boolean)
        '
        'btnClear
        '
        Me.btnClear.AccessibleDescription = resources.GetString("btnClear.AccessibleDescription")
        Me.btnClear.AccessibleName = resources.GetString("btnClear.AccessibleName")
        Me.btnClear.Anchor = CType(resources.GetObject("btnClear.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnClear.BackgroundImage = CType(resources.GetObject("btnClear.BackgroundImage"), System.Drawing.Image)
        Me.btnClear.Dock = CType(resources.GetObject("btnClear.Dock"), System.Windows.Forms.DockStyle)
        Me.btnClear.Enabled = CType(resources.GetObject("btnClear.Enabled"), Boolean)
        Me.btnClear.FlatStyle = CType(resources.GetObject("btnClear.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnClear.Font = CType(resources.GetObject("btnClear.Font"), System.Drawing.Font)
        Me.btnClear.Image = CType(resources.GetObject("btnClear.Image"), System.Drawing.Image)
        Me.btnClear.ImageAlign = CType(resources.GetObject("btnClear.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnClear.ImageIndex = CType(resources.GetObject("btnClear.ImageIndex"), Integer)
        Me.btnClear.ImeMode = CType(resources.GetObject("btnClear.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnClear.Location = CType(resources.GetObject("btnClear.Location"), System.Drawing.Point)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.RightToLeft = CType(resources.GetObject("btnClear.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnClear.Size = CType(resources.GetObject("btnClear.Size"), System.Drawing.Size)
        Me.btnClear.TabIndex = CType(resources.GetObject("btnClear.TabIndex"), Integer)
        Me.btnClear.Text = resources.GetString("btnClear.Text")
        Me.btnClear.TextAlign = CType(resources.GetObject("btnClear.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnClear.Visible = CType(resources.GetObject("btnClear.Visible"), Boolean)
        '
        'GrUserCommand
        '
        Me.GrUserCommand.AccessibleDescription = resources.GetString("GrUserCommand.AccessibleDescription")
        Me.GrUserCommand.AccessibleName = resources.GetString("GrUserCommand.AccessibleName")
        Me.GrUserCommand.Anchor = CType(resources.GetObject("GrUserCommand.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.GrUserCommand.BackgroundImage = CType(resources.GetObject("GrUserCommand.BackgroundImage"), System.Drawing.Image)
        Me.GrUserCommand.Controls.Add(Me.ChkWithRet)
        Me.GrUserCommand.Controls.Add(Me.txtUserCommand)
        Me.GrUserCommand.Dock = CType(resources.GetObject("GrUserCommand.Dock"), System.Windows.Forms.DockStyle)
        Me.GrUserCommand.Enabled = CType(resources.GetObject("GrUserCommand.Enabled"), Boolean)
        Me.GrUserCommand.Font = CType(resources.GetObject("GrUserCommand.Font"), System.Drawing.Font)
        Me.GrUserCommand.ImeMode = CType(resources.GetObject("GrUserCommand.ImeMode"), System.Windows.Forms.ImeMode)
        Me.GrUserCommand.Location = CType(resources.GetObject("GrUserCommand.Location"), System.Drawing.Point)
        Me.GrUserCommand.Name = "GrUserCommand"
        Me.GrUserCommand.RightToLeft = CType(resources.GetObject("GrUserCommand.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.GrUserCommand.Size = CType(resources.GetObject("GrUserCommand.Size"), System.Drawing.Size)
        Me.GrUserCommand.TabIndex = CType(resources.GetObject("GrUserCommand.TabIndex"), Integer)
        Me.GrUserCommand.TabStop = False
        Me.GrUserCommand.Text = resources.GetString("GrUserCommand.Text")
        Me.GrUserCommand.Visible = CType(resources.GetObject("GrUserCommand.Visible"), Boolean)
        '
        'ChkWithRet
        '
        Me.ChkWithRet.AccessibleDescription = resources.GetString("ChkWithRet.AccessibleDescription")
        Me.ChkWithRet.AccessibleName = resources.GetString("ChkWithRet.AccessibleName")
        Me.ChkWithRet.Anchor = CType(resources.GetObject("ChkWithRet.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.ChkWithRet.Appearance = CType(resources.GetObject("ChkWithRet.Appearance"), System.Windows.Forms.Appearance)
        Me.ChkWithRet.BackgroundImage = CType(resources.GetObject("ChkWithRet.BackgroundImage"), System.Drawing.Image)
        Me.ChkWithRet.CheckAlign = CType(resources.GetObject("ChkWithRet.CheckAlign"), System.Drawing.ContentAlignment)
        Me.ChkWithRet.Dock = CType(resources.GetObject("ChkWithRet.Dock"), System.Windows.Forms.DockStyle)
        Me.ChkWithRet.Enabled = CType(resources.GetObject("ChkWithRet.Enabled"), Boolean)
        Me.ChkWithRet.FlatStyle = CType(resources.GetObject("ChkWithRet.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.ChkWithRet.Font = CType(resources.GetObject("ChkWithRet.Font"), System.Drawing.Font)
        Me.ChkWithRet.Image = CType(resources.GetObject("ChkWithRet.Image"), System.Drawing.Image)
        Me.ChkWithRet.ImageAlign = CType(resources.GetObject("ChkWithRet.ImageAlign"), System.Drawing.ContentAlignment)
        Me.ChkWithRet.ImageIndex = CType(resources.GetObject("ChkWithRet.ImageIndex"), Integer)
        Me.ChkWithRet.ImeMode = CType(resources.GetObject("ChkWithRet.ImeMode"), System.Windows.Forms.ImeMode)
        Me.ChkWithRet.Location = CType(resources.GetObject("ChkWithRet.Location"), System.Drawing.Point)
        Me.ChkWithRet.Name = "ChkWithRet"
        Me.ChkWithRet.RightToLeft = CType(resources.GetObject("ChkWithRet.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.ChkWithRet.Size = CType(resources.GetObject("ChkWithRet.Size"), System.Drawing.Size)
        Me.ChkWithRet.TabIndex = CType(resources.GetObject("ChkWithRet.TabIndex"), Integer)
        Me.ChkWithRet.Text = resources.GetString("ChkWithRet.Text")
        Me.ChkWithRet.TextAlign = CType(resources.GetObject("ChkWithRet.TextAlign"), System.Drawing.ContentAlignment)
        Me.ChkWithRet.Visible = CType(resources.GetObject("ChkWithRet.Visible"), Boolean)
        '
        'txtUserCommand
        '
        Me.txtUserCommand.AccessibleDescription = resources.GetString("txtUserCommand.AccessibleDescription")
        Me.txtUserCommand.AccessibleName = resources.GetString("txtUserCommand.AccessibleName")
        Me.txtUserCommand.Anchor = CType(resources.GetObject("txtUserCommand.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.txtUserCommand.AutoSize = CType(resources.GetObject("txtUserCommand.AutoSize"), Boolean)
        Me.txtUserCommand.BackgroundImage = CType(resources.GetObject("txtUserCommand.BackgroundImage"), System.Drawing.Image)
        Me.txtUserCommand.Dock = CType(resources.GetObject("txtUserCommand.Dock"), System.Windows.Forms.DockStyle)
        Me.txtUserCommand.Enabled = CType(resources.GetObject("txtUserCommand.Enabled"), Boolean)
        Me.txtUserCommand.Font = CType(resources.GetObject("txtUserCommand.Font"), System.Drawing.Font)
        Me.txtUserCommand.ImeMode = CType(resources.GetObject("txtUserCommand.ImeMode"), System.Windows.Forms.ImeMode)
        Me.txtUserCommand.Location = CType(resources.GetObject("txtUserCommand.Location"), System.Drawing.Point)
        Me.txtUserCommand.MaxLength = CType(resources.GetObject("txtUserCommand.MaxLength"), Integer)
        Me.txtUserCommand.Multiline = CType(resources.GetObject("txtUserCommand.Multiline"), Boolean)
        Me.txtUserCommand.Name = "txtUserCommand"
        Me.txtUserCommand.PasswordChar = CType(resources.GetObject("txtUserCommand.PasswordChar"), Char)
        Me.txtUserCommand.RightToLeft = CType(resources.GetObject("txtUserCommand.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.txtUserCommand.ScrollBars = CType(resources.GetObject("txtUserCommand.ScrollBars"), System.Windows.Forms.ScrollBars)
        Me.txtUserCommand.Size = CType(resources.GetObject("txtUserCommand.Size"), System.Drawing.Size)
        Me.txtUserCommand.TabIndex = CType(resources.GetObject("txtUserCommand.TabIndex"), Integer)
        Me.txtUserCommand.Text = resources.GetString("txtUserCommand.Text")
        Me.txtUserCommand.TextAlign = CType(resources.GetObject("txtUserCommand.TextAlign"), System.Windows.Forms.HorizontalAlignment)
        Me.txtUserCommand.Visible = CType(resources.GetObject("txtUserCommand.Visible"), Boolean)
        Me.txtUserCommand.WordWrap = CType(resources.GetObject("txtUserCommand.WordWrap"), Boolean)
        '
        'GrBaudrate
        '
        Me.GrBaudrate.AccessibleDescription = resources.GetString("GrBaudrate.AccessibleDescription")
        Me.GrBaudrate.AccessibleName = resources.GetString("GrBaudrate.AccessibleName")
        Me.GrBaudrate.Anchor = CType(resources.GetObject("GrBaudrate.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.GrBaudrate.BackgroundImage = CType(resources.GetObject("GrBaudrate.BackgroundImage"), System.Drawing.Image)
        Me.GrBaudrate.Controls.Add(Me.cbxBaudrate)
        Me.GrBaudrate.Dock = CType(resources.GetObject("GrBaudrate.Dock"), System.Windows.Forms.DockStyle)
        Me.GrBaudrate.Enabled = CType(resources.GetObject("GrBaudrate.Enabled"), Boolean)
        Me.GrBaudrate.Font = CType(resources.GetObject("GrBaudrate.Font"), System.Drawing.Font)
        Me.GrBaudrate.ImeMode = CType(resources.GetObject("GrBaudrate.ImeMode"), System.Windows.Forms.ImeMode)
        Me.GrBaudrate.Location = CType(resources.GetObject("GrBaudrate.Location"), System.Drawing.Point)
        Me.GrBaudrate.Name = "GrBaudrate"
        Me.GrBaudrate.RightToLeft = CType(resources.GetObject("GrBaudrate.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.GrBaudrate.Size = CType(resources.GetObject("GrBaudrate.Size"), System.Drawing.Size)
        Me.GrBaudrate.TabIndex = CType(resources.GetObject("GrBaudrate.TabIndex"), Integer)
        Me.GrBaudrate.TabStop = False
        Me.GrBaudrate.Text = resources.GetString("GrBaudrate.Text")
        Me.GrBaudrate.Visible = CType(resources.GetObject("GrBaudrate.Visible"), Boolean)
        '
        'cbxBaudrate
        '
        Me.cbxBaudrate.AccessibleDescription = resources.GetString("cbxBaudrate.AccessibleDescription")
        Me.cbxBaudrate.AccessibleName = resources.GetString("cbxBaudrate.AccessibleName")
        Me.cbxBaudrate.Anchor = CType(resources.GetObject("cbxBaudrate.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.cbxBaudrate.BackgroundImage = CType(resources.GetObject("cbxBaudrate.BackgroundImage"), System.Drawing.Image)
        Me.cbxBaudrate.Dock = CType(resources.GetObject("cbxBaudrate.Dock"), System.Windows.Forms.DockStyle)
        Me.cbxBaudrate.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cbxBaudrate.Enabled = CType(resources.GetObject("cbxBaudrate.Enabled"), Boolean)
        Me.cbxBaudrate.Font = CType(resources.GetObject("cbxBaudrate.Font"), System.Drawing.Font)
        Me.cbxBaudrate.ImeMode = CType(resources.GetObject("cbxBaudrate.ImeMode"), System.Windows.Forms.ImeMode)
        Me.cbxBaudrate.IntegralHeight = CType(resources.GetObject("cbxBaudrate.IntegralHeight"), Boolean)
        Me.cbxBaudrate.ItemHeight = CType(resources.GetObject("cbxBaudrate.ItemHeight"), Integer)
        Me.cbxBaudrate.Location = CType(resources.GetObject("cbxBaudrate.Location"), System.Drawing.Point)
        Me.cbxBaudrate.MaxDropDownItems = CType(resources.GetObject("cbxBaudrate.MaxDropDownItems"), Integer)
        Me.cbxBaudrate.MaxLength = CType(resources.GetObject("cbxBaudrate.MaxLength"), Integer)
        Me.cbxBaudrate.Name = "cbxBaudrate"
        Me.cbxBaudrate.RightToLeft = CType(resources.GetObject("cbxBaudrate.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.cbxBaudrate.Size = CType(resources.GetObject("cbxBaudrate.Size"), System.Drawing.Size)
        Me.cbxBaudrate.TabIndex = CType(resources.GetObject("cbxBaudrate.TabIndex"), Integer)
        Me.cbxBaudrate.Text = resources.GetString("cbxBaudrate.Text")
        Me.cbxBaudrate.Visible = CType(resources.GetObject("cbxBaudrate.Visible"), Boolean)
        '
        'btnStop_Fast_Mode
        '
        Me.btnStop_Fast_Mode.AccessibleDescription = resources.GetString("btnStop_Fast_Mode.AccessibleDescription")
        Me.btnStop_Fast_Mode.AccessibleName = resources.GetString("btnStop_Fast_Mode.AccessibleName")
        Me.btnStop_Fast_Mode.Anchor = CType(resources.GetObject("btnStop_Fast_Mode.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnStop_Fast_Mode.BackgroundImage = CType(resources.GetObject("btnStop_Fast_Mode.BackgroundImage"), System.Drawing.Image)
        Me.btnStop_Fast_Mode.Dock = CType(resources.GetObject("btnStop_Fast_Mode.Dock"), System.Windows.Forms.DockStyle)
        Me.btnStop_Fast_Mode.Enabled = CType(resources.GetObject("btnStop_Fast_Mode.Enabled"), Boolean)
        Me.btnStop_Fast_Mode.FlatStyle = CType(resources.GetObject("btnStop_Fast_Mode.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnStop_Fast_Mode.Font = CType(resources.GetObject("btnStop_Fast_Mode.Font"), System.Drawing.Font)
        Me.btnStop_Fast_Mode.Image = CType(resources.GetObject("btnStop_Fast_Mode.Image"), System.Drawing.Image)
        Me.btnStop_Fast_Mode.ImageAlign = CType(resources.GetObject("btnStop_Fast_Mode.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnStop_Fast_Mode.ImageIndex = CType(resources.GetObject("btnStop_Fast_Mode.ImageIndex"), Integer)
        Me.btnStop_Fast_Mode.ImeMode = CType(resources.GetObject("btnStop_Fast_Mode.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnStop_Fast_Mode.Location = CType(resources.GetObject("btnStop_Fast_Mode.Location"), System.Drawing.Point)
        Me.btnStop_Fast_Mode.Name = "btnStop_Fast_Mode"
        Me.btnStop_Fast_Mode.RightToLeft = CType(resources.GetObject("btnStop_Fast_Mode.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnStop_Fast_Mode.Size = CType(resources.GetObject("btnStop_Fast_Mode.Size"), System.Drawing.Size)
        Me.btnStop_Fast_Mode.TabIndex = CType(resources.GetObject("btnStop_Fast_Mode.TabIndex"), Integer)
        Me.btnStop_Fast_Mode.Text = resources.GetString("btnStop_Fast_Mode.Text")
        Me.btnStop_Fast_Mode.TextAlign = CType(resources.GetObject("btnStop_Fast_Mode.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnStop_Fast_Mode.Visible = CType(resources.GetObject("btnStop_Fast_Mode.Visible"), Boolean)
        '
        'frmMain
        '
        Me.AccessibleDescription = resources.GetString("$this.AccessibleDescription")
        Me.AccessibleName = resources.GetString("$this.AccessibleName")
        Me.AutoScaleBaseSize = CType(resources.GetObject("$this.AutoScaleBaseSize"), System.Drawing.Size)
        Me.AutoScroll = CType(resources.GetObject("$this.AutoScroll"), Boolean)
        Me.AutoScrollMargin = CType(resources.GetObject("$this.AutoScrollMargin"), System.Drawing.Size)
        Me.AutoScrollMinSize = CType(resources.GetObject("$this.AutoScrollMinSize"), System.Drawing.Size)
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = CType(resources.GetObject("$this.ClientSize"), System.Drawing.Size)
        Me.Controls.Add(Me.btnStop_Fast_Mode)
        Me.Controls.Add(Me.GrBaudrate)
        Me.Controls.Add(Me.GrUserCommand)
        Me.Controls.Add(Me.btnClear)
        Me.Controls.Add(Me.btnSendUserCommand)
        Me.Controls.Add(Me.txtSelectedLCIC)
        Me.Controls.Add(Me.txtStatus)
        Me.Controls.Add(Me.btnCheckLCIC)
        Me.Controls.Add(Me.clstPorts)
        Me.Controls.Add(Me.btnCheckForPorts)
        Me.Enabled = CType(resources.GetObject("$this.Enabled"), Boolean)
        Me.Font = CType(resources.GetObject("$this.Font"), System.Drawing.Font)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.ImeMode = CType(resources.GetObject("$this.ImeMode"), System.Windows.Forms.ImeMode)
        Me.Location = CType(resources.GetObject("$this.Location"), System.Drawing.Point)
        Me.MaximizeBox = False
        Me.MaximumSize = CType(resources.GetObject("$this.MaximumSize"), System.Drawing.Size)
        Me.Menu = Me.mnuMain
        Me.MinimumSize = CType(resources.GetObject("$this.MinimumSize"), System.Drawing.Size)
        Me.Name = "frmMain"
        Me.RightToLeft = CType(resources.GetObject("$this.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.StartPosition = CType(resources.GetObject("$this.StartPosition"), System.Windows.Forms.FormStartPosition)
        Me.Text = resources.GetString("$this.Text")
        Me.GrUserCommand.ResumeLayout(False)
        Me.GrBaudrate.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region " Standard Menu Code "
    ' <System.Diagnostics.DebuggerStepThrough()> has been added to some procedures since they are
    ' not the focus of the demo. Remove them if you wish to debug the procedures.
    ' This code simply shows the About form.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
        ' Open the About form in Dialog Mode
        Dim frm As New frmAbout
        frm.ShowDialog(Me)
        frm.Dispose()
    End Sub

    ' This code will close the form.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
        ' Close the current form
        Me.Close()
    End Sub
#End Region


    Private Sub btnCheckForPorts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckForPorts.Click
        Call CheckForPorts()
    End Sub
    Private Sub CheckForPorts()
        ' This subroutine checks for available ports on the local machine. It does 
        ' this by attempting to open ports 1 through 255.
        ' Check for Availability of each of the 255 Comm Ports, and
        ' place a check in the list box items that have openable ports.
        Dim i As Integer


        btnCheckForPorts.Enabled = False

        Dim iNumberOfPorts As Integer
        If m_CommPort.sPortType = COM_Port_Driver Then
            iNumberOfPorts = cMaxNumberOfPorts
            PortType = "COM"
        Else
            iNumberOfPorts = NumDevs
            PortType = "USB"
        End If

        For i = 1 To iNumberOfPorts
            clstPorts.Items.Add(PortType & i, False)
        Next
        clstPorts.Visible = True
        clstPorts.Refresh()

        For i = 1 To iNumberOfPorts

            Me.txtStatus.Text = "Testing " & PortType + i.ToString() + vbCrLf
            Me.txtStatus.Refresh()
            If IsPortAvailable(i) Then
                ' Check the box for available ports.
                Me.clstPorts.SetItemChecked(i - 1, True)
                RealMaxNumberOfPorts = i
            Else
                ' Uncheck the box for unavailable ports.
                Me.clstPorts.SetItemChecked(i - 1, False)
            End If
        Next
        ' Enable the 'Check for LCIC' button.
        Me.btnCheckLCIC.Enabled = True
        cbxBaudrate.Enabled = True

        'Call SendCursorDown()
    End Sub

    ' This subroutine attempts to send the "V" command to any active Comm Port.
    '   If a response is returned then a usable LCIC has been detected
    '   on that port.
    Private Sub btnCheckLCIC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckLCIC.Click
        Dim i As Integer

        btnCheckLCIC.Enabled = False
        'For i = 0 To clstPorts.Items.Count - 1
        For i = 0 To RealMaxNumberOfPorts - 1
            If Me.clstPorts.GetItemChecked(i) Then
                ' Item is checked so it MIGHT be a valid port.
                ' Test for validity.
                If IsPortAvailable(i + 1) Then
                    ' Check if port responds to the "V" command.
                    If Is_LCIC_Port(i + 1) Then
                        ' Set the class variables to the last LCIC found.
                        Me.m_IsLCICFound = True
                        Me.m_LCICPort = i + 1
                        ' Write message to the user.
                        WriteMessage("Port " + (i + 1).ToString() + _
                            " is a responsive LCIC.")
                    Else
                        ' Write message to the user.
                        WriteMessage("Port " + (i + 1).ToString() + _
                            " is not a responsive LCIC.")
                    End If
                End If
            End If
        Next
        ' If an LCIC was found, enable the rest of the buttons, so the user
        '   can communicate with the LCIC.
        If Me.m_IsLCICFound Then
            Me.txtSelectedLCIC.Text = "Using LCIC on " & PortType & _
                Me.m_LCICPort.ToString()

            Me.txtUserCommand.Enabled = True
            Me.ChkWithRet.Enabled = True
        End If
        Call SendCursorDown()
    End Sub


    ' This subroutine clears the TextBox.
    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Me.txtStatus.Clear()

    End Sub
    ' This subroutine sends a user specified command to the LCIC, and records its 
    '   response. 
    Private Sub btnSendUserCommand_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendUserCommand.Click
        Call SendUserCommand()
    End Sub
    Sub SendUserCommand()
        ' Always wrap up working with Comm Ports in exception handlers.
        Try

            btnSendUserCommand.Enabled = False

            ' Attempt to open the port.
            m_CommPort.Close()
            m_CommPort.Open(m_LCICPort, iBaudRate, 8, COMport_DirectUSB.DataParity.Parity_None, COMport_DirectUSB.DataStopBit.StopBit_1, 4096)

            Dim StringForSend As String
            If ChkWithRet.Checked = True Then
                StringForSend = Me.txtUserCommand.Text & Chr(13)
            Else
                StringForSend = Me.txtUserCommand.Text
            End If


            Dim i As Integer

            Try
                Dim CardAnswer As String
                m_CommPort.Write(StringForSend)

                Select Case StringForSend
                    Case "U", "u"
                        '' Starts Fast Mode 
                        ' To end Fast Mode to send "x"-command to the board
                        '
                        btnStop_Fast_Mode.Enabled = True

                        ' To prevet any other command during Fast mode
                        btnSendUserCommand.Enabled = Not btnStop_Fast_Mode.Enabled
                        txtUserCommand.Enabled = Not btnStop_Fast_Mode.Enabled
                        ChkWithRet.Enabled = Not btnStop_Fast_Mode.Enabled

                        'Show Fast Mode Results 3 times()
                        For i = 1 To 3
                            Call Read_Data_from_Board(5000)
                        Next


                        Exit Sub

                    Case Else
                        Call Read_Data_from_Board(50)

                End Select

Wait_for:
                System.Threading.Thread.Sleep(1)

                txtStatus.Text &= CardAnswer
                SendCursorDown()
            Catch ex As Exception
                If ex.Message.IndexOf("Read Error: Timeout error") >= 0 Then
                    GoTo Wait_for
                End If
                sCurrentStopMessage = "Stop 2"
                MessageBox.Show(sCurrentStopMessage, sCritical_Error, MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try



            ' Sleep long enough for the LCIC to respond 
            System.Threading.Thread.Sleep(70)
            Application.DoEvents()

            m_CommPort.Close()
            btnSendUserCommand.Enabled = True
        Catch ex As Exception
            ' Warn the user.
            MessageBox.Show("Unable to communicate with LCIC")
        Finally

        End Try


    End Sub
    '  This function checks if the port is an LCIC board
    '  by sending the "V" command to the port.  
    '  If the port responds, it is assumed to be an LCIC board. 
    '  --->>> The function returns a Boolean.
    Private Function Is_LCIC_Port(ByVal port As Integer) As Boolean

        ' Always wrap up working with Comm Ports in exception handlers.
        Try
            ' Attempt to open the port.
            If m_CommPort.sPortType = COM_Port_Driver Then
                m_CommPort.Open(port, iBaudRate, 8, COMport_DirectUSB.DataParity.Parity_None, _
                    COMport_DirectUSB.DataStopBit.StopBit_1, 4096)

            Else
                m_CommPort.SerialNumber = Serial_Number(port - 1)
                m_CommPort.Open(port, iBaudRate, 8, COMport_DirectUSB.DataParity.Parity_None, _
                  COMport_DirectUSB.DataStopBit.StopBit_1, 4096)


            End If

            'm_CommPort.Write(Encoding.ASCII.GetBytes(":a"))
            System.Threading.Thread.Sleep(200)
            m_CommPort.Write(Encoding.ASCII.GetBytes("V"))
            Dim CardAnswer As String

            ' Sleep long enough for the LCIC to respond.
            System.Threading.Thread.Sleep(200)
            Application.DoEvents()
            ' Try to get info from the Comm Port.
            Try

                ' Try to read a single byte. If you get it, then assume
                '   that the port contains an LCIC. Clear the buffer before 
                '   leaving.


                While (m_CommPort.Read(1) <> -1)

                    CardAnswer &= Chr(m_CommPort.InputStream(0))
                    Application.DoEvents()
                    'If CardAnswer = "LCIC" Then
                    If CardAnswer.IndexOf("LCIC") >= 0 Then
                        Exit While
                    End If

                End While

                m_CommPort.ClearInputBuffer()
                m_CommPort.Close()
                Return True
            Catch exc As Exception
                ' Nothing to read from the Comm Port, so set to False
                m_CommPort.Close()
                Return False
            End Try
        Catch exc As Exception
            ' Port could not be opened or written to.
            Me.clstPorts.SetItemChecked(port - 1, False)
            MsgBox("Could not open port.", MsgBoxStyle.OKOnly, Me.Text)
            Return False
        End Try


    End Function

    ' This function attempts to open the passed Comm Port. If it is
    '   available, it returns True; else it returns False. To determine
    '   availability a Try-Catch block is used.
    Private Function IsPortAvailable(ByVal ComPort As Integer) As Boolean
        Try
            If m_CommPort.sPortType = COM_Port_Driver Then
                m_CommPort.Open(ComPort, iBaudRate, 8, COMport_DirectUSB.DataParity.Parity_None, _
                    COMport_DirectUSB.DataStopBit.StopBit_1, 4096)
                ' If it gets here, then the Comm Port is available.

            Else
                m_CommPort.SerialNumber = Serial_Number(ComPort - 1) 'USB
                m_CommPort.Open(ComPort, iBaudRate, 8, COMport_DirectUSB.DataParity.Parity_None, _
                   COMport_DirectUSB.DataStopBit.StopBit_1, 4096)
                ' If it gets here, then the Comm Port is available.
            End If



            m_CommPort.Close()
            Return True
        Catch
            ' If it gets here, then the attempt to open the Comm Port
            '   was unsuccessful.
            Return False
        End Try
    End Function

    ' This subroutine writes a message to the txtStatus TextBox.
    Private Sub WriteMessage(ByVal message As String)
        Me.txtStatus.Text &= message + vbCrLf
    End Sub
    Private Sub txtUserCommand_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUserCommand.KeyPress
        If e.KeyChar = Chr(13) Then
            Call SendUserCommand()
        End If

    End Sub

    Private Sub txtUserCommand_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUserCommand.TextChanged
        If txtUserCommand.Text.Trim <> "" Then
            Me.btnSendUserCommand.Enabled = True
        Else
            Me.btnSendUserCommand.Enabled = False
        End If
    End Sub

    Private Sub SendCursorDown()
        Me.txtStatus.SelectAll()
        Me.txtStatus.ScrollToCaret()
        Me.txtStatus.Select(1, 1)

    End Sub
    Private Function GetLCIC_Driver_Type() As String
        Dim SysDir As String

        Try
            Dim i As Integer
            For i = 1 To 255
                SysDir &= "0"
            Next
            Dim nSize As Int32

            GetWindowsDirectory(SysDir, nSize)
            i = SysDir.IndexOf(Chr(0))
            Dim DRV_File_name As String
            SysDir = SysDir.Substring(0, i)

            DRV_File_name = SysDir & "\System32\Drivers\FTSER2K.SYS"
            Dim DLL_File_name As String = SysDir & "\System32\Drivers\FTD2XX.SYS"

            If File.Exists(DLL_File_name) Then
                Detected_Driver = Detected_Direct_Driver
                Me.Text &= Detected_Driver
                Return Direct_Driver
            Else
                If File.Exists(DRV_File_name) Then

                    Detected_Driver = Detected_COM_Port_Driver
                    Me.Text &= Detected_Driver
                    Return COM_Port_Driver
                Else
                    Return Driver_NONE
                End If
            End If
        Catch ex As Exception
            sCurrentStopMessage = "Stop 1"
            MessageBox.Show(sCurrentStopMessage, sCritical_Error, MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Function
    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Driver_TYPE = GetLCIC_Driver_Type()
        Select Case Driver_TYPE
            Case Direct_Driver
                Call GetUSB_Serial_Numbers()

            Case COM_Port_Driver

            Case Else
                MessageBox.Show("LCIC driver is not installed.", "Sorry...", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End
        End Select
        m_CommPort.sPortType = Driver_TYPE
        Init_Baudrate_List()
        btnCheckLCIC.Enabled = False
        cbxBaudrate.Enabled = False
    End Sub
    Private Function GetUSB_Serial_Numbers() As Integer
        Dim ReturnValue As Integer
        Dim Index As Integer
        Dim Flags As Integer
        Dim TheType As Integer
        Dim ID As Integer
        Dim LocId As Integer
        Dim SerialNumber As String
        Dim Description As String
        Dim Handle As Integer
        'Dim cd As Byte = Convert.ToByte(0)
        For Index = 1 To 256
            SerialNumber &= "_" 'cd
        Next
        Description = SerialNumber

        ReturnValue = m_CommPort.FT_CreateDeviceInfoList(NumDevs)

        For Index = 0 To NumDevs - 1
            ReturnValue = m_CommPort.FT_GetDeviceInfoDetail(Index, Flags, TheType, ID, LocId, SerialNumber, Description, Handle)
            Serial_Number(Index) = SerialNumber
        Next
        Return ReturnValue
    End Function
    Private Sub Read_Data_from_Board(ByVal iBlockSize As Integer)
        Dim kB As Integer
        Dim sBlock As String
        Try

            System.Threading.Thread.Sleep(100)
            kB = m_CommPort.Read(iBlockSize)
            If kB > 0 Then
                System.Threading.Thread.Sleep(100)
                sBlock = m_CommPort.InputStreamString
                txtStatus.Text &= sBlock
                SendCursorDown()
                txtStatus.Refresh()
            End If
            Application.DoEvents()


        Catch ex As Exception
            ': Stop
        End Try


    End Sub
    Private Sub Init_Baudrate_List()
        cbxBaudrate.Items.Clear()

        cbxBaudrate.Items.Add("14400") '0
        cbxBaudrate.Items.Add("19200") '1
        cbxBaudrate.Items.Add("28800") '2
        cbxBaudrate.Items.Add("38400") '3
        cbxBaudrate.Items.Add("57600") '4
        cbxBaudrate.Items.Add("115200") '5
        cbxBaudrate.Items.Add("921600") '6 Only USB port

        cbxBaudrate.Text = cbxBaudrate.Items(5).ToString()
        iBaudRate = Convert.ToInt32(cbxBaudrate.Text)
    End Sub

    Private Sub cbxBaudrate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbxBaudrate.SelectedIndexChanged

        iBaudRate = Convert.ToInt32(cbxBaudrate.Text)
        btnCheckLCIC.Enabled = True
        txtUserCommand.Enabled = False
    End Sub

    Private Sub btnStop_Fast_Mode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop_Fast_Mode.Click
        Dim kB As Integer
        Dim sResponse As String = ""

        m_CommPort.Write("x")

Wait_for_Fast_mode_end:

        System.Threading.Thread.Sleep(200)
        kB = m_CommPort.Read(50)
        If kB > 2 Then
            System.Threading.Thread.Sleep(100)
            sResponse &= m_CommPort.InputStreamString
            If sResponse.IndexOf("ms=") >= 0 Then
                txtStatus.Text &= sResponse
                SendCursorDown()
                txtStatus.Refresh()
                m_CommPort.Close()
                btnStop_Fast_Mode.Enabled = False
                btnSendUserCommand.Enabled = Not btnStop_Fast_Mode.Enabled
                txtUserCommand.Enabled = Not btnStop_Fast_Mode.Enabled
                ChkWithRet.Enabled = Not btnStop_Fast_Mode.Enabled

            Else
                Application.DoEvents()
                GoTo Wait_for_Fast_mode_end
            End If
        End If

    End Sub
End Class