Index: trunk/desktop/mainWindow.rbfrm
===================================================================
--- trunk/desktop/mainWindow.rbfrm	(revision 15)
+++ trunk/desktop/mainWindow.rbfrm	(revision 16)
@@ -138,5 +138,5 @@
       Top             =   32
       Underline       =   ""
-      Value           =   2
+      Value           =   0
       Visible         =   True
       Width           =   637
@@ -2698,4 +2698,37 @@
 		  //Set the default car type
 		  ICSSerialPort1.setCarType("MR-03")
+		  
+		  readPreferences()
+		  
+		  //Set and open the COM Port
+		  dim i, count as integer
+		  count = System.SerialPortCount
+		  
+		  for i = 0 to count - 1
+		    PopupMenu_SerialPort.AddRow( System.SerialPort(i).Name )
+		  next
+		  
+		  if comPort <> "" then
+		    //We can try opening the com port and set the popup menu to that port
+		    
+		    for i = 0 to PopupMenu_SerialPort.ListCount - 1
+		      
+		      if PopupMenu_SerialPort.list(i) = comPort then
+		        //Found a match, set and open
+		        PopupMenu_SerialPort.ListIndex = i
+		        ICSSerialPort1.SerialPort = System.SerialPort(i)
+		        
+		        if not ICSSerialPort1.Open then
+		          //Could not open
+		          MsgBox "Error opening defined com port"
+		        end if
+		        //No need to continue loop
+		        exit
+		      end if
+		      
+		    next
+		    
+		  end if
+		  
 		End Sub
 	#tag EndEvent
@@ -2967,23 +3000,23 @@
 		  //Read the settings from the preferences file
 		  if filePreference <> Nil then
-		    xdoc = New XmlDocument(filePreference)
-		    
-		    count = xdoc.DocumentElement.ChildCount
-		    
-		    for i = 0 to count - 1
-		      root = xdoc.DocumentElement.Child(i)
+		    if filePreference.Exists then
+		      xdoc = New XmlDocument(filePreference)
 		      
-		      item = root.FirstChild.Value
+		      count = xdoc.DocumentElement.ChildCount
 		      
-		      select case root.Name
-		      case "comPort"
-		        comPort = item
-		      end select
-		    next
-		    
-		  else
-		    //Do nothing
-		    
+		      for i = 0 to count - 1
+		        root = xdoc.DocumentElement.Child(i)
+		        
+		        item = root.FirstChild.Value
+		        
+		        select case root.Name
+		        case "comPort"
+		          comPort = item
+		        end select
+		      next
+		    end if
 		  end if
+		  
+		  
 		End Sub
 	#tag EndMethod
@@ -3060,4 +3093,38 @@
 	#tag EndEvent
 #tag EndEvents
+#tag Events PopupMenu_SerialPort
+	#tag Event
+		Sub Change()
+		  //Set and open the COM Port
+		  dim i, count as integer
+		  count = System.SerialPortCount
+		  
+		  if comPort <> "" then
+		    //We can try opening the com port and set the popup menu to that port
+		    
+		    for i = 0 to PopupMenu_SerialPort.ListCount - 1
+		      
+		      if PopupMenu_SerialPort.list(i) = me.Text then
+		        //Found a match, set and open
+		        ICSSerialPort1.SerialPort = System.SerialPort(i)
+		        ICSSerialPort1.Close
+		        
+		        
+		        if not ICSSerialPort1.Open then
+		          //Could not open
+		          MsgBox "Error opening defined com port"
+		        end if
+		        //Save and exit
+		        comPort = me.Text
+		        savePreferences
+		        exit
+		      end if
+		      
+		    next
+		    
+		  end if
+		End Sub
+	#tag EndEvent
+#tag EndEvents
 #tag Events PopupMenu_Profile
 	#tag Event
