| 1 | #tag Class |
---|
| 2 | Protected Class ICSSerialPort |
---|
| 3 | Inherits serial |
---|
| 4 | #tag Method, Flags = &h0 |
---|
| 5 | Sub resetCar() |
---|
| 6 | //This sends the command to reset the car back to a default configuration |
---|
| 7 | //Defaults are different for each car type |
---|
| 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 |
---|
| 18 | |
---|
| 19 | select case carType |
---|
| 20 | |
---|
| 21 | case "MR-03" |
---|
| 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) |
---|
| 40 | |
---|
| 41 | case "dNaNo" |
---|
| 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) |
---|
| 60 | |
---|
| 61 | case "ASF" |
---|
| 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) |
---|
| 80 | |
---|
| 81 | else |
---|
| 82 | //default thing to do |
---|
| 83 | MsgBox "Error invalid car type" |
---|
| 84 | return |
---|
| 85 | end select |
---|
| 86 | |
---|
| 87 | //trigger the event definition so main program knows the values changed |
---|
| 88 | valuesChanged() |
---|
| 89 | End Sub |
---|
| 90 | #tag EndMethod |
---|
| 91 | |
---|
| 92 | #tag Method, Flags = &h0 |
---|
| 93 | Sub setCarType(value as string) |
---|
| 94 | //When setting car type we must reconfigure the serial port |
---|
| 95 | //Some car types have a different baud rate |
---|
| 96 | |
---|
| 97 | select case value |
---|
| 98 | |
---|
| 99 | case "MR-03" |
---|
| 100 | carType = value |
---|
| 101 | case "dNaNo" |
---|
| 102 | carType = value |
---|
| 103 | case "AD" |
---|
| 104 | carType = value |
---|
| 105 | case "ASF" |
---|
| 106 | carType = value |
---|
| 107 | else |
---|
| 108 | MsgBox "Error setting Car Type" |
---|
| 109 | end select |
---|
| 110 | End Sub |
---|
| 111 | #tag EndMethod |
---|
| 112 | |
---|
| 113 | #tag Method, Flags = &h0 |
---|
| 114 | Sub writeCar() |
---|
| 115 | //Send set bytes to the car |
---|
| 116 | |
---|
| 117 | dim sendstring as string |
---|
| 118 | |
---|
| 119 | calculateChecksum() |
---|
| 120 | |
---|
| 121 | sendstring = byte01 + byte02 + byte03 + byte04 + byte05 + byte06 + byte07 + byte08 + byte09 + byte10 + byte11 + byte12 + byte13 + byte14 + byte15 + byte16 + byte17 + byte18 |
---|
| 122 | |
---|
| 123 | me.Write(sendstring) |
---|
| 124 | End Sub |
---|
| 125 | #tag EndMethod |
---|
| 126 | |
---|
| 127 | #tag Method, Flags = &h0 |
---|
| 128 | Sub calculateChecksum() |
---|
| 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) |
---|
| 151 | |
---|
| 152 | valuesChanged() |
---|
| 153 | End Sub |
---|
| 154 | #tag EndMethod |
---|
| 155 | |
---|
| 156 | #tag Method, Flags = &h0 |
---|
| 157 | Sub readCar() |
---|
| 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 |
---|
| 216 | End Sub |
---|
| 217 | #tag EndMethod |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | #tag Hook, Flags = &h0 |
---|
| 221 | Event valuesChanged() |
---|
| 222 | #tag EndHook |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | #tag Note, Name = General |
---|
| 226 | Car type must be set for this to operate |
---|
| 227 | Car types supported by this application are |
---|
| 228 | MR-03 |
---|
| 229 | dNaNo |
---|
| 230 | ASF |
---|
| 231 | #tag EndNote |
---|
| 232 | |
---|
| 233 | |
---|
| 234 | #tag Property, Flags = &h0 |
---|
| 235 | byte01 As String = "&hFF" |
---|
| 236 | #tag EndProperty |
---|
| 237 | |
---|
| 238 | #tag Property, Flags = &h0 |
---|
| 239 | byte11 As String |
---|
| 240 | #tag EndProperty |
---|
| 241 | |
---|
| 242 | #tag Property, Flags = &h0 |
---|
| 243 | byte12 As String |
---|
| 244 | #tag EndProperty |
---|
| 245 | |
---|
| 246 | #tag Property, Flags = &h0 |
---|
| 247 | byte13 As String |
---|
| 248 | #tag EndProperty |
---|
| 249 | |
---|
| 250 | #tag Property, Flags = &h0 |
---|
| 251 | byte14 As String |
---|
| 252 | #tag EndProperty |
---|
| 253 | |
---|
| 254 | #tag Property, Flags = &h0 |
---|
| 255 | byte15 As String |
---|
| 256 | #tag EndProperty |
---|
| 257 | |
---|
| 258 | #tag Property, Flags = &h0 |
---|
| 259 | byte16 As String |
---|
| 260 | #tag EndProperty |
---|
| 261 | |
---|
| 262 | #tag Property, Flags = &h0 |
---|
| 263 | byte17 As String |
---|
| 264 | #tag EndProperty |
---|
| 265 | |
---|
| 266 | #tag Property, Flags = &h0 |
---|
| 267 | byte18 As String |
---|
| 268 | #tag EndProperty |
---|
| 269 | |
---|
| 270 | #tag Property, Flags = &h0 |
---|
| 271 | byte02 As String |
---|
| 272 | #tag EndProperty |
---|
| 273 | |
---|
| 274 | #tag Property, Flags = &h0 |
---|
| 275 | byte03 As String |
---|
| 276 | #tag EndProperty |
---|
| 277 | |
---|
| 278 | #tag Property, Flags = &h0 |
---|
| 279 | byte04 As String |
---|
| 280 | #tag EndProperty |
---|
| 281 | |
---|
| 282 | #tag Property, Flags = &h0 |
---|
| 283 | byte05 As String |
---|
| 284 | #tag EndProperty |
---|
| 285 | |
---|
| 286 | #tag Property, Flags = &h0 |
---|
| 287 | byte06 As String |
---|
| 288 | #tag EndProperty |
---|
| 289 | |
---|
| 290 | #tag Property, Flags = &h0 |
---|
| 291 | byte07 As String |
---|
| 292 | #tag EndProperty |
---|
| 293 | |
---|
| 294 | #tag Property, Flags = &h0 |
---|
| 295 | byte08 As String |
---|
| 296 | #tag EndProperty |
---|
| 297 | |
---|
| 298 | #tag Property, Flags = &h0 |
---|
| 299 | byte09 As String |
---|
| 300 | #tag EndProperty |
---|
| 301 | |
---|
| 302 | #tag Property, Flags = &h0 |
---|
| 303 | byte10 As String |
---|
| 304 | #tag EndProperty |
---|
| 305 | |
---|
| 306 | #tag Property, Flags = &h0 |
---|
| 307 | carType As String = "MR-03" |
---|
| 308 | #tag EndProperty |
---|
| 309 | |
---|
| 310 | #tag Property, Flags = &h0 |
---|
| 311 | fsicsdb As REALSQLDatabase |
---|
| 312 | #tag EndProperty |
---|
| 313 | |
---|
| 314 | |
---|
| 315 | #tag ViewBehavior |
---|
| 316 | #tag ViewProperty |
---|
| 317 | Name="Name" |
---|
| 318 | Visible=true |
---|
| 319 | Group="ID" |
---|
| 320 | InheritedFrom="serial" |
---|
| 321 | #tag EndViewProperty |
---|
| 322 | #tag ViewProperty |
---|
| 323 | Name="Index" |
---|
| 324 | Visible=true |
---|
| 325 | Group="ID" |
---|
| 326 | Type="Integer" |
---|
| 327 | InheritedFrom="serial" |
---|
| 328 | #tag EndViewProperty |
---|
| 329 | #tag ViewProperty |
---|
| 330 | Name="Super" |
---|
| 331 | Visible=true |
---|
| 332 | Group="ID" |
---|
| 333 | InheritedFrom="serial" |
---|
| 334 | #tag EndViewProperty |
---|
| 335 | #tag ViewProperty |
---|
| 336 | Name="Left" |
---|
| 337 | Visible=true |
---|
| 338 | Group="Position" |
---|
| 339 | InheritedFrom="serial" |
---|
| 340 | #tag EndViewProperty |
---|
| 341 | #tag ViewProperty |
---|
| 342 | Name="Top" |
---|
| 343 | Visible=true |
---|
| 344 | Group="Position" |
---|
| 345 | InheritedFrom="serial" |
---|
| 346 | #tag EndViewProperty |
---|
| 347 | #tag ViewProperty |
---|
| 348 | Name="Baud" |
---|
| 349 | Visible=true |
---|
| 350 | Group="Behavior" |
---|
| 351 | InitialValue="13" |
---|
| 352 | Type="Integer" |
---|
| 353 | EditorType="Enum" |
---|
| 354 | InheritedFrom="serial" |
---|
| 355 | #tag EnumValues |
---|
| 356 | "0 - 300" |
---|
| 357 | "1 - 600" |
---|
| 358 | "2 - 1200" |
---|
| 359 | "3 - 1800" |
---|
| 360 | "4 - 2400" |
---|
| 361 | "5 - 3600" |
---|
| 362 | "6 - 4800" |
---|
| 363 | "7 - 7200" |
---|
| 364 | "8 - 9600" |
---|
| 365 | "9 - 14400" |
---|
| 366 | "10 - 19200" |
---|
| 367 | "11 - 28800" |
---|
| 368 | "12 - 38400" |
---|
| 369 | "13 - 57600" |
---|
| 370 | "14 - 115200" |
---|
| 371 | "15 - 230400" |
---|
| 372 | #tag EndEnumValues |
---|
| 373 | #tag EndViewProperty |
---|
| 374 | #tag ViewProperty |
---|
| 375 | Name="Bits" |
---|
| 376 | Visible=true |
---|
| 377 | Group="Behavior" |
---|
| 378 | InitialValue="3" |
---|
| 379 | Type="Integer" |
---|
| 380 | EditorType="Enum" |
---|
| 381 | InheritedFrom="serial" |
---|
| 382 | #tag EnumValues |
---|
| 383 | "0 - 5 Data Bits" |
---|
| 384 | "1 - 6 Data Bits" |
---|
| 385 | "2 - 7 Data Bits" |
---|
| 386 | "3 - 8 Data bits" |
---|
| 387 | #tag EndEnumValues |
---|
| 388 | #tag EndViewProperty |
---|
| 389 | #tag ViewProperty |
---|
| 390 | Name="Parity" |
---|
| 391 | Visible=true |
---|
| 392 | Group="Behavior" |
---|
| 393 | InitialValue="0" |
---|
| 394 | Type="Integer" |
---|
| 395 | EditorType="Enum" |
---|
| 396 | InheritedFrom="serial" |
---|
| 397 | #tag EnumValues |
---|
| 398 | "0 - No Parity" |
---|
| 399 | "1 - Odd Parity" |
---|
| 400 | "2 - EvenParity" |
---|
| 401 | #tag EndEnumValues |
---|
| 402 | #tag EndViewProperty |
---|
| 403 | #tag ViewProperty |
---|
| 404 | Name="Stop" |
---|
| 405 | Visible=true |
---|
| 406 | Group="Behavior" |
---|
| 407 | InitialValue="0" |
---|
| 408 | Type="Integer" |
---|
| 409 | EditorType="Enum" |
---|
| 410 | InheritedFrom="serial" |
---|
| 411 | #tag EnumValues |
---|
| 412 | "0 - 1 Stop Bit" |
---|
| 413 | "1 - 1.5 Stop Bits" |
---|
| 414 | "2 - 2 Stop Bits" |
---|
| 415 | #tag EndEnumValues |
---|
| 416 | #tag EndViewProperty |
---|
| 417 | #tag ViewProperty |
---|
| 418 | Name="XON" |
---|
| 419 | Visible=true |
---|
| 420 | Group="Behavior" |
---|
| 421 | Type="Boolean" |
---|
| 422 | InheritedFrom="serial" |
---|
| 423 | #tag EndViewProperty |
---|
| 424 | #tag ViewProperty |
---|
| 425 | Name="CTS" |
---|
| 426 | Visible=true |
---|
| 427 | Group="Behavior" |
---|
| 428 | Type="Boolean" |
---|
| 429 | InheritedFrom="serial" |
---|
| 430 | #tag EndViewProperty |
---|
| 431 | #tag ViewProperty |
---|
| 432 | Name="DTR" |
---|
| 433 | Visible=true |
---|
| 434 | Group="Behavior" |
---|
| 435 | Type="Boolean" |
---|
| 436 | InheritedFrom="serial" |
---|
| 437 | #tag EndViewProperty |
---|
| 438 | #tag ViewProperty |
---|
| 439 | Name="byte01" |
---|
| 440 | Group="Behavior" |
---|
| 441 | InitialValue="&hFF" |
---|
| 442 | Type="String" |
---|
| 443 | #tag EndViewProperty |
---|
| 444 | #tag ViewProperty |
---|
| 445 | Name="byte11" |
---|
| 446 | Group="Behavior" |
---|
| 447 | Type="String" |
---|
| 448 | #tag EndViewProperty |
---|
| 449 | #tag ViewProperty |
---|
| 450 | Name="byte12" |
---|
| 451 | Group="Behavior" |
---|
| 452 | Type="String" |
---|
| 453 | #tag EndViewProperty |
---|
| 454 | #tag ViewProperty |
---|
| 455 | Name="byte13" |
---|
| 456 | Group="Behavior" |
---|
| 457 | Type="String" |
---|
| 458 | #tag EndViewProperty |
---|
| 459 | #tag ViewProperty |
---|
| 460 | Name="byte14" |
---|
| 461 | Group="Behavior" |
---|
| 462 | Type="String" |
---|
| 463 | #tag EndViewProperty |
---|
| 464 | #tag ViewProperty |
---|
| 465 | Name="byte15" |
---|
| 466 | Group="Behavior" |
---|
| 467 | Type="String" |
---|
| 468 | #tag EndViewProperty |
---|
| 469 | #tag ViewProperty |
---|
| 470 | Name="byte16" |
---|
| 471 | Group="Behavior" |
---|
| 472 | Type="String" |
---|
| 473 | #tag EndViewProperty |
---|
| 474 | #tag ViewProperty |
---|
| 475 | Name="byte17" |
---|
| 476 | Group="Behavior" |
---|
| 477 | Type="String" |
---|
| 478 | #tag EndViewProperty |
---|
| 479 | #tag ViewProperty |
---|
| 480 | Name="byte18" |
---|
| 481 | Group="Behavior" |
---|
| 482 | Type="String" |
---|
| 483 | #tag EndViewProperty |
---|
| 484 | #tag ViewProperty |
---|
| 485 | Name="byte02" |
---|
| 486 | Group="Behavior" |
---|
| 487 | Type="String" |
---|
| 488 | #tag EndViewProperty |
---|
| 489 | #tag ViewProperty |
---|
| 490 | Name="byte03" |
---|
| 491 | Group="Behavior" |
---|
| 492 | Type="String" |
---|
| 493 | #tag EndViewProperty |
---|
| 494 | #tag ViewProperty |
---|
| 495 | Name="byte04" |
---|
| 496 | Group="Behavior" |
---|
| 497 | Type="String" |
---|
| 498 | #tag EndViewProperty |
---|
| 499 | #tag ViewProperty |
---|
| 500 | Name="byte05" |
---|
| 501 | Group="Behavior" |
---|
| 502 | Type="String" |
---|
| 503 | #tag EndViewProperty |
---|
| 504 | #tag ViewProperty |
---|
| 505 | Name="byte06" |
---|
| 506 | Group="Behavior" |
---|
| 507 | Type="String" |
---|
| 508 | #tag EndViewProperty |
---|
| 509 | #tag ViewProperty |
---|
| 510 | Name="byte07" |
---|
| 511 | Group="Behavior" |
---|
| 512 | Type="String" |
---|
| 513 | #tag EndViewProperty |
---|
| 514 | #tag ViewProperty |
---|
| 515 | Name="byte08" |
---|
| 516 | Group="Behavior" |
---|
| 517 | Type="String" |
---|
| 518 | #tag EndViewProperty |
---|
| 519 | #tag ViewProperty |
---|
| 520 | Name="byte09" |
---|
| 521 | Group="Behavior" |
---|
| 522 | Type="String" |
---|
| 523 | #tag EndViewProperty |
---|
| 524 | #tag ViewProperty |
---|
| 525 | Name="byte10" |
---|
| 526 | Group="Behavior" |
---|
| 527 | Type="String" |
---|
| 528 | #tag EndViewProperty |
---|
| 529 | #tag EndViewBehavior |
---|
| 530 | End Class |
---|
| 531 | #tag EndClass |
---|