Changeset 10
- Timestamp:
- 04/07/10 15:26:04 (14 years ago)
- Location:
- trunk/desktop
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/desktop/ICSSerialPort.rbbas
r9 r10 6 6 //This sends the command to reset the car back to a default configuration 7 7 //Defaults are different for each car type 8 9 dim sendstring as string 8 setDefaultValues 9 10 //Send the default values to the car 11 writeCar 12 End Sub 13 #tag EndMethod 14 15 #tag Method, Flags = &h0 16 Sub setDefaultValues() 17 //Set the defaults for the bytes sent to a car 10 18 11 19 select case carType 12 20 13 21 case "MR-03" 14 22 byte01 = chrb(&hD5) 23 byte02 = chrb(&h5A) 24 byte03 = chrb(&h64) 25 byte04 = chrb(&hFF) 26 byte05 = chrb(&h02) 27 byte06 = chrb(&h02) 28 byte07 = chrb(&h01) 29 byte08 = chrb(&hFF) 30 byte09 = chrb(&hBC) 31 byte10 = chrb(&h44) 32 byte11 = chrb(&h88) 33 byte12 = chrb(&h78) 34 byte13 = chrb(&hFF) 35 byte14 = chrb(&h2C) 36 byte15 = chrb(&h05) 37 byte16 = chrb(&h5A) 38 byte17 = chrb(&h3C) 39 byte18 = chrb(&h87) 15 40 16 41 case "dNaNo" 17 42 byte01 = chrb(&hD5) 43 byte02 = chrb(&h5A) 44 byte03 = chrb(&hFF) 45 byte04 = chrb(&hFF) 46 byte05 = chrb(&h0A) 47 byte06 = chrb(&h03) 48 byte07 = chrb(&h01) 49 byte08 = chrb(&h40) 50 byte09 = chrb(&hBC) 51 byte10 = chrb(&h44) 52 byte11 = chrb(&h88) 53 byte12 = chrb(&h78) 54 byte13 = chrb(&h03) 55 byte14 = chrb(&hFF) 56 byte15 = chrb(&hFF) 57 byte16 = chrb(&h80) 58 byte17 = chrb(&h80) 59 byte18 = chrb(&hA7) 18 60 19 61 case "ASF" 20 21 22 case "AD" 23 24 25 else 26 //default thing to do 27 MsgBox "Error invalid car type" 28 Return 29 30 end select 31 32 me.Write(sendstring) 33 End Sub 34 #tag EndMethod 35 36 #tag Method, Flags = &h0 37 Sub setDefaultValues() 38 //Set the defaults for the bytes sent to a car 39 40 dim sendstring as string 41 42 select case carType 43 44 case "MR-03" 45 46 47 case "dNaNo" 48 49 50 case "ASF" 51 52 53 case "AD" 54 62 byte01 = chrb(&hD5) 63 byte02 = chrb(&h5A) 64 byte03 = chrb(&hFF) 65 byte04 = chrb(&hFF) 66 byte05 = chrb(&h0A) 67 byte06 = chrb(&h03) 68 byte07 = chrb(&h01) 69 byte08 = chrb(&h78) 70 byte09 = chrb(&hBC) 71 byte10 = chrb(&h44) 72 byte11 = chrb(&h88) 73 byte12 = chrb(&h78) 74 byte13 = chrb(&h03) 75 byte14 = chrb(&hFF) 76 byte15 = chrb(&hFF) 77 byte16 = chrb(&hFF) 78 byte17 = chrb(&hFF) 79 byte18 = chrb(&hDD) 55 80 56 81 else … … 103 128 Sub calculateChecksum() 104 129 //Use this to calculate byte 18, the checksum 130 //The checksum is just adding bytes 2-17 together but rounded at each byte 131 132 dim i as integer 133 134 i = (asc(byte02) + asc(byte03)) mod &h100 135 i = (i + asc(byte04)) mod &h100 136 i = (i + asc(byte05)) mod &h100 137 i = (i + asc(byte06)) mod &h100 138 i = (i + asc(byte07)) mod &h100 139 i = (i + asc(byte08)) mod &h100 140 i = (i + asc(byte09)) mod &h100 141 i = (i + asc(byte10)) mod &h100 142 i = (i + asc(byte11)) mod &h100 143 i = (i + asc(byte12)) mod &h100 144 i = (i + asc(byte13)) mod &h100 145 i = (i + asc(byte14)) mod &h100 146 i = (i + asc(byte15)) mod &h100 147 i = (i + asc(byte16)) mod &h100 148 i = (i + asc(byte17)) mod &h100 149 150 byte18 = chrb(i) 105 151 106 152 valuesChanged() … … 111 157 Sub readCar() 112 158 //Read values from the currently attached car 159 End Sub 160 #tag EndMethod 161 162 #tag Method, Flags = &h0 163 Sub Constructor() 164 //Make sure we have a database and if not create it 165 dim exists as boolean 166 167 exists = prepareDB() 168 if exists = false then 169 //No database available, create one 170 createDB() 171 else 172 //Database exists, connect to it 173 if fsicsdb.Connect = false then 174 MsgBox "Database connection failed" 175 end if 176 end if 177 End Sub 178 #tag EndMethod 179 180 #tag Method, Flags = &h21 181 Private Function prepareDB() As Boolean 182 //Open the database file 183 fsicsdb = new REALSQLDatabase 184 dim f as FolderItem = GetFolderItem("fsicsdb") 185 fsicsdb.DatabaseFile = f 186 187 return f.Exists 188 End Function 189 #tag EndMethod 190 191 #tag Method, Flags = &h21 192 Private Sub createDB() 193 //Create a new database 194 195 196 //make sure we can create the file 197 if fsicsdb.CreateDatabaseFile() then 198 if fsicsdb.Connect() then 199 dim query as string 200 query = "CREATE TABLE carprofiles (id INTEGER PRIMARY KEY, name VARCHAR, cartype VARCHAR, byte01 VARCHAR, byte02 VARCHAR, byte03 VARCHAR, byte04 VARCHAR, byte05 VARCHAR, byte06 VARCHAR"+_ 201 ", byte07 VARCHAR, byte08 VARCHAR, byte09 VARCHAR, byte10 VARCHAR, byte11 VARCHAR, byte12 VARCHAR, byte13 VARCHAR, byte14 VARCHAR, byte15 VARCHAR, byte16 VARCHAR, byte17 VARCHAR"+_ 202 ", byte18 VARCHAR, UNIQUE(name))" 203 fsicsdb.SQLExecute(query) 204 if fsicsdb.Error then 205 MsgBox "Database Error (carprofiles):" + fsicsdb.ErrorMessage 206 end if 207 208 209 else 210 MsgBox "Failed to connect to new database file" 211 end if 212 else 213 //Failed to create database file 214 MsgBox "Failed to create database file" 215 end if 113 216 End Sub 114 217 #tag EndMethod … … 126 229 dNaNo 127 230 ASF 128 AD129 231 #tag EndNote 130 232 … … 204 306 #tag Property, Flags = &h0 205 307 carType As String = "MR-03" 308 #tag EndProperty 309 310 #tag Property, Flags = &h0 311 fsicsdb As REALSQLDatabase 206 312 #tag EndProperty 207 313 -
trunk/desktop/mainWindow.rbfrm
r9 r10 2630 2630 2631 2631 #tag WindowCode 2632 #tag Method, Flags = &h 02633 Sub disableControls()2632 #tag Method, Flags = &h21 2633 Private Sub disableControls() 2634 2634 select case ICSSerialPort1.carType 2635 2635 … … 2678 2678 #tag EndMethod 2679 2679 2680 #tag Method, Flags = &h 02681 Sub updateCarScreen()2680 #tag Method, Flags = &h21 2681 Private Sub updateCarScreen() 2682 2682 //Use this method to update the car screen 2683 2683 … … 2857 2857 #tag EndMethod 2858 2858 2859 #tag Method, Flags = &h 02860 Sub updateAdvancedScreen()2859 #tag Method, Flags = &h21 2860 Private Sub updateAdvancedScreen() 2861 2861 //Update the fields on the advanced screen to match current values 2862 2862 EditField_Byte1.Text = str(asc(ICSSerialPort1.byte01)) … … 2880 2880 End Sub 2881 2881 #tag EndMethod 2882 2883 #tag Method, Flags = &h21 2884 Private Sub readPreferences() 2885 dim filePreference as FolderItem = GetFolderItem("icspref.xml") 2886 dim xdoc as XmlDocument 2887 dim root as XmlNode 2888 dim i as Integer 2889 dim count as integer 2890 dim item as string 2891 2892 //Read the settings from the preferences file 2893 if filePreference <> Nil then 2894 xdoc = New XmlDocument(filePreference) 2895 2896 count = xdoc.DocumentElement.ChildCount 2897 2898 for i = 0 to count - 1 2899 root = xdoc.DocumentElement.Child(i) 2900 2901 item = root.FirstChild.Value 2902 2903 select case root.Name 2904 case "comPort" 2905 comPort = item 2906 end select 2907 next 2908 2909 else 2910 //Do nothing 2911 2912 end if 2913 End Sub 2914 #tag EndMethod 2915 2916 #tag Method, Flags = &h21 2917 Private Sub savePreferences() 2918 dim xml as XmlDocument 2919 dim root as XMLNode 2920 dim comPortXML as XmlNode 2921 dim f as FolderItem 2922 2923 //Save the preferences 2924 2925 f = GetFolderItem("icspref.xml") 2926 2927 if f <> Nil then 2928 //Create a new XML document 2929 xml = New XmlDocument 2930 root = xml.AppendChild(xml.CreateElement("icspref")) 2931 2932 //Add elements 2933 comPortXML = root.AppendChild(xml.CreateElement("comPort")) 2934 comPortXML.AppendChild(xml.CreateTextNode(comPort)) 2935 2936 //Save the output 2937 xml.SaveXml(f) 2938 end if 2939 2940 End Sub 2941 #tag EndMethod 2942 2943 2944 #tag Property, Flags = &h0 2945 comPort As string 2946 #tag EndProperty 2882 2947 2883 2948
Note: See TracChangeset
for help on using the changeset viewer.