‘*******************************************************
‘        Declarations for trajectory module
‘*******************************************************

‘——-file operation variables——————-

  Public TextChanged As Boolean
  Public FileName As String
  Public LogFileName As String
  Public OldProfileName As String
 
  ‘—Log File Type Declaration—
  Private Type Log_Entry
    Time_Point As String * 9
    Set_Point_Temp As String * 5
    Actual_Point_Temp As String * 5
    CRLF As String * 2
  End Type

‘——–software state variables——————

  Public BootUp_Flag As Boolean
  Public Profile_Run_Flag As Boolean
  Public Profile_AutoLoad_Flag As Boolean      ‘Flags to signal AutoLoad at startup
  Public Logfile_AutoLoad_Flag As Boolean
  Public Valid_Profile_Loaded As Boolean       ‘used to prevent run if valid profile not loaded yet
  Public CommPortNumber As Integer
 
‘——–Control state variables——————–

  Public Elapsed_Time_Interval As Double                 ‘–update:during CI,manual update
 
  Public Twait As Double                                 ‘Delay time until Temp catches up

 
  Public Base_Elapsed_Time As Double                     ‘–tracks Elapsed except during control updates
  Public Toggle_Start_Time As Variant                    ‘–records when CI is toggled on
  Public Previous_Elapsed_Time_Interval As Double        ‘–tracks elapsed except during manual updates
  Public New_Elapsed_Time_Interval As Double             ‘–use for input, if valid=>elapsed
  Public Time_Update_Flag As Boolean
  Public Current_Segment As Byte
  Public Desired_Temperature As Integer
  Public Thermocouple_Temperature_1 As Integer
  Public Process_Setpoint_Readback_1 As Integer

‘———- Display State Variables —————-
  Public Email_Destination As String
  
  Dim Display_WorkSheet() As Variant                    ‘–grid state params
  Public Run_Profile_String As String
  Private DisplayRowCount As Long                        ‘–number rows in traj. disp. grid
         
     ‘—translated profile segment arrays
  Dim Segment_Number(1 To 256) As Integer
  Dim Start_Time(1 To 256) As Double                    ‘–all times dbl (except var for datediff func )
  Dim End_Time(1 To 256) As Double
  Dim Interval_Start_Temperature(1 To 256) As Double    ‘–temps dbl to cover RTD dec pt.
  Dim Interval_Final_Temperature(1 To 256) As Double
  Dim Temperature_Tolerance(1 To 256)   As Double
  Dim SegmentCMD(1 To 256) As String
  Dim SegmentDoneFlag(1 To 256)  As Boolean                          ‘Waiting done flag ?
 
     ‘—profile parameters
  Public Profile_Line_Count As Byte
  Public Profile_Max_Time As Double
  
  Public Timer_Interrupt_Count As Byte
 
 
  Public Serial_Receive_Data As String
 
 
 
  ‘—-PID controller state variables
  Public PF_Input_Type As String
  Public RunProfile_TempScale As String
  Public RunProfile_TimeScale As String
 
  Dim DisplayChartValues() As Double                     ‘–dynamically sized array
 
  Public Traj_DebugFlag_Not As Boolean
 

‘*******************************************************
Private Sub form_load()
‘*******************************************************

Dim Filter As String
Dim newcnt As Integer

Traj_DebugFlag_Not = True       ‘————–SHIPPABLE HAS THIS SET=TRUE———————-

If Traj_DebugFlag_Not = True Then On Error Resume Next

           ‘———–Pop Up Product registration form————
    Do While Not IsRegistered()                      ‘Check program registration
                                                     ‘If Not registered
    frmRegistration.Show vbModal                     ‘     show registration form
        If ExitApp Then
            Unload Me                                ‘The user canceled. Exit Application
            Exit Sub
        End If
    Loop
           ‘———–end of added registration form code
          
          
       
  ‘——————–chart inits———————
   ProfileChart.chartType = VtChChartType2dXY
   ProfileChart.Plot.UniformAxis = False            ‘–de-couples x-y axii so plots square
   ReDim DisplayChartValues(1 To 10, 1 To 2)
   For i = 1 To 10                                  ‘–zero out chart to elim random fill
      DisplayChartValues(i, 1) = i
      DisplayChartValues(i, 2) = 0
   Next i
   ProfileChart.ChartData = DisplayChartValues
   ProfileChart.Plot.UniformAxis = False            ‘–de-couples x-y axii so plots square

BootUp_Flag = True                                     ‘set true upon startup, set false when init done

‘————-Elapsed Time Preset————–
Elapsed_Time_Interval = 0                              ‘–init all Intervals=0
Base_Elapsed_Time = 0
Previous_Elapsed_Time_Interval = 0
Elapsed_Time.Text = CStr(Elapsed_Time_Interval)
Time_Update_Flag = False

CommPortNumber = 1                                     ‘failsafe CommPortNumber
Current_Segment = 1

Profile_Line_Count = 0
Profile_Max_Time = 0
Twait = 0

Profile_Run_Flag = False
Valid_Profile_Loaded = False

‘—initialize AutoLoad Flags
Profile_AutoLoad_Flag = False
Logfile_AutoLoad_Flag = False

TextChanged = False

Filter = "Text files (*.txt) | *.txt"                  ‘Load filters into common dialog box
Filter = Filter & "|All files (*.*) | *.*"
CommonDialog3.Filter = Filter

Traj_form.WindowState = 2

‘————————————————
‘— Load Instrumentation Setup From DiskFile —
‘————————————————
‘flag : use last log file time point as start ?  GOAL = easy reboot and restart !
‘     : Last profile used ?
‘     : append to log file ?
   ‘– unconditional recall
‘Email_Destination
‘Email enable/disable state
‘Temp Error limit
‘Update Setup File Anytime ANY of the setup parameters change

            ‘————————-
            ‘—Grid SetUp and Init—
            ‘—Setup Grid         —
            ‘————————-

ReDim Display_WorkSheet(0 To 255, 0 To 9)
DisplayRowCount = 256

    RunProfile_FlexGrid.FixedCols = 0
    RunProfile_FlexGrid.Cols = 10
    RunProfile_FlexGrid.FixedRows = 1
    RunProfile_FlexGrid.Rows = 256

        ‘—-Size the columns in the grid—-
    For i = 0 To RunProfile_FlexGrid.Cols – 1
       RunProfile_FlexGrid.ColWidth(i) = 1058
       RunProfile_FlexGrid.ColAlignment(i) = flexAlignRightCenter
    Next i
   
        ‘—-Initialize the Profile Headers—-
    RunProfile_FlexGrid.TextMatrix(0, 0) = "Seg"
    RunProfile_FlexGrid.TextMatrix(0, 1) = "Start Time"
    RunProfile_FlexGrid.TextMatrix(0, 2) = "Duration"
    RunProfile_FlexGrid.TextMatrix(0, 3) = "Action"
    RunProfile_FlexGrid.TextMatrix(0, 4) = "Start Temp"
    RunProfile_FlexGrid.TextMatrix(0, 5) = "End Temp"
    RunProfile_FlexGrid.TextMatrix(0, 6) = "Ramp Rate"
    RunProfile_FlexGrid.TextMatrix(0, 7) = "Error Limits"
    RunProfile_FlexGrid.TextMatrix(0, 8) = "Command"
    RunProfile_FlexGrid.TextMatrix(0, 9) = "Notify= t,T"

‘—————————-end of grid init’s———————————————-
 
Unit_Addr = 1

Timer_Interrupt_Count = 0

Display "SKC copyright 2008 Embeddedrf.com" & vbCrLf
     
Recall_Setup                    ‘  recall setup from hard drive
BootUp_Flag = False             ‘  set to indicate bootup COMPLETE
Serial_Port.Show                ‘–force phantom form load to initialize comm port
Serial_Port.Visible = False     ‘–user does not see this form

Serial_Port.Ram_Only_Mode (Unit_Addr)               ‘–assure ram only mode to prevent NV RAM overuse and early death

PollingModeSet "monitor"        ‘–monitor setpoint and actual temp when not running profile
Monitor_Interval_Timer

Exit Sub

GEHandler:                      ‘Generic Error Handler added to routines covers all errors                               ‘Before customization of routines
  Resume Next                   ‘Ignores error and prevents program shutdown
End Sub

Categories: CodingVisual-Basic

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *