Changeset 10 for trunk/desktop/ICSSerialPort.rbbas
- Timestamp:
- 04/07/10 15:26:04 (15 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.