Changeset 16 for trunk


Ignore:
Timestamp:
04/08/10 11:04:20 (14 years ago)
Author:
pinwc4
Message:

Added logic for opening and saving com port settings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/desktop/mainWindow.rbfrm

    r15 r16  
    138138      Top             =   32 
    139139      Underline       =   "" 
    140       Value           =   2 
     140      Value           =   0 
    141141      Visible         =   True 
    142142      Width           =   637 
     
    26982698                  //Set the default car type 
    26992699                  ICSSerialPort1.setCarType("MR-03") 
     2700                   
     2701                  readPreferences() 
     2702                   
     2703                  //Set and open the COM Port 
     2704                  dim i, count as integer 
     2705                  count = System.SerialPortCount 
     2706                   
     2707                  for i = 0 to count - 1 
     2708                    PopupMenu_SerialPort.AddRow( System.SerialPort(i).Name ) 
     2709                  next 
     2710                   
     2711                  if comPort <> "" then 
     2712                    //We can try opening the com port and set the popup menu to that port 
     2713                     
     2714                    for i = 0 to PopupMenu_SerialPort.ListCount - 1 
     2715                       
     2716                      if PopupMenu_SerialPort.list(i) = comPort then 
     2717                        //Found a match, set and open 
     2718                        PopupMenu_SerialPort.ListIndex = i 
     2719                        ICSSerialPort1.SerialPort = System.SerialPort(i) 
     2720                         
     2721                        if not ICSSerialPort1.Open then 
     2722                          //Could not open 
     2723                          MsgBox "Error opening defined com port" 
     2724                        end if 
     2725                        //No need to continue loop 
     2726                        exit 
     2727                      end if 
     2728                       
     2729                    next 
     2730                     
     2731                  end if 
     2732                   
    27002733                End Sub 
    27012734        #tag EndEvent 
     
    29673000                  //Read the settings from the preferences file 
    29683001                  if filePreference <> Nil then 
    2969                     xdoc = New XmlDocument(filePreference) 
    2970                      
    2971                     count = xdoc.DocumentElement.ChildCount 
    2972                      
    2973                     for i = 0 to count - 1 
    2974                       root = xdoc.DocumentElement.Child(i) 
     3002                    if filePreference.Exists then 
     3003                      xdoc = New XmlDocument(filePreference) 
    29753004                       
    2976                       item = root.FirstChild.Value 
     3005                      count = xdoc.DocumentElement.ChildCount 
    29773006                       
    2978                       select case root.Name 
    2979                       case "comPort" 
    2980                         comPort = item 
    2981                       end select 
    2982                     next 
    2983                      
    2984                   else 
    2985                     //Do nothing 
    2986                      
     3007                      for i = 0 to count - 1 
     3008                        root = xdoc.DocumentElement.Child(i) 
     3009                         
     3010                        item = root.FirstChild.Value 
     3011                         
     3012                        select case root.Name 
     3013                        case "comPort" 
     3014                          comPort = item 
     3015                        end select 
     3016                      next 
     3017                    end if 
    29873018                  end if 
     3019                   
     3020                   
    29883021                End Sub 
    29893022        #tag EndMethod 
     
    30603093        #tag EndEvent 
    30613094#tag EndEvents 
     3095#tag Events PopupMenu_SerialPort 
     3096        #tag Event 
     3097                Sub Change() 
     3098                  //Set and open the COM Port 
     3099                  dim i, count as integer 
     3100                  count = System.SerialPortCount 
     3101                   
     3102                  if comPort <> "" then 
     3103                    //We can try opening the com port and set the popup menu to that port 
     3104                     
     3105                    for i = 0 to PopupMenu_SerialPort.ListCount - 1 
     3106                       
     3107                      if PopupMenu_SerialPort.list(i) = me.Text then 
     3108                        //Found a match, set and open 
     3109                        ICSSerialPort1.SerialPort = System.SerialPort(i) 
     3110                        ICSSerialPort1.Close 
     3111                         
     3112                         
     3113                        if not ICSSerialPort1.Open then 
     3114                          //Could not open 
     3115                          MsgBox "Error opening defined com port" 
     3116                        end if 
     3117                        //Save and exit 
     3118                        comPort = me.Text 
     3119                        savePreferences 
     3120                        exit 
     3121                      end if 
     3122                       
     3123                    next 
     3124                     
     3125                  end if 
     3126                End Sub 
     3127        #tag EndEvent 
     3128#tag EndEvents 
    30623129#tag Events PopupMenu_Profile 
    30633130        #tag Event 
Note: See TracChangeset for help on using the changeset viewer.