#tag Class Protected Class ICSSerialPort Inherits serial #tag Method, Flags = &h0 Sub resetCar() //This sends the command to reset the car back to a default configuration //Defaults are different for each car type setDefaultValues //Send the default values to the car writeCar End Sub #tag EndMethod #tag Method, Flags = &h0 Sub setDefaultValues() //Set the defaults for the bytes sent to a car select case carType case "MR-03" byte01 = chrb(&hD5) byte02 = chrb(&h5A) byte03 = chrb(&h64) byte04 = chrb(&hFF) byte05 = chrb(&h02) byte06 = chrb(&h02) byte07 = chrb(&h01) byte08 = chrb(&hFF) byte09 = chrb(&hBC) byte10 = chrb(&h44) byte11 = chrb(&h88) byte12 = chrb(&h78) byte13 = chrb(&hFF) byte14 = chrb(&h2C) byte15 = chrb(&h05) byte16 = chrb(&h5A) byte17 = chrb(&h3C) byte18 = chrb(&h87) case "dNaNo" byte01 = chrb(&hD5) byte02 = chrb(&h5A) byte03 = chrb(&hFF) byte04 = chrb(&hFF) byte05 = chrb(&h0A) byte06 = chrb(&h03) byte07 = chrb(&h01) byte08 = chrb(&h40) byte09 = chrb(&hBC) byte10 = chrb(&h44) byte11 = chrb(&h88) byte12 = chrb(&h78) byte13 = chrb(&h03) byte14 = chrb(&hFF) byte15 = chrb(&hFF) byte16 = chrb(&h80) byte17 = chrb(&h80) byte18 = chrb(&hA7) case "ASF" byte01 = chrb(&hD5) byte02 = chrb(&h5A) byte03 = chrb(&hFF) byte04 = chrb(&hFF) byte05 = chrb(&h0A) byte06 = chrb(&h03) byte07 = chrb(&h01) byte08 = chrb(&h78) byte09 = chrb(&hBC) byte10 = chrb(&h44) byte11 = chrb(&h88) byte12 = chrb(&h78) byte13 = chrb(&h03) byte14 = chrb(&hFF) byte15 = chrb(&hFF) byte16 = chrb(&hFF) byte17 = chrb(&hFF) byte18 = chrb(&hDD) else //default thing to do MsgBox "Error invalid car type" return end select //trigger the event definition so main program knows the values changed valuesChanged() End Sub #tag EndMethod #tag Method, Flags = &h0 Sub setCarType(value as string) //When setting car type we must reconfigure the serial port //Some car types have a different baud rate select case value case "MR-03" carType = value case "dNaNo" carType = value case "AD" carType = value case "ASF" carType = value else MsgBox "Error setting Car Type" end select End Sub #tag EndMethod #tag Method, Flags = &h0 Sub writeCar() //Send set bytes to the car dim sendstring as string calculateChecksum() sendstring = byte01 + byte02 + byte03 + byte04 + byte05 + byte06 + byte07 + byte08 + byte09 + byte10 + byte11 + byte12 + byte13 + byte14 + byte15 + byte16 + byte17 + byte18 me.Write(sendstring) End Sub #tag EndMethod #tag Method, Flags = &h0 Sub calculateChecksum() //Use this to calculate byte 18, the checksum //The checksum is just adding bytes 2-17 together but rounded at each byte dim i as integer i = (asc(byte02) + asc(byte03)) mod &h100 i = (i + asc(byte04)) mod &h100 i = (i + asc(byte05)) mod &h100 i = (i + asc(byte06)) mod &h100 i = (i + asc(byte07)) mod &h100 i = (i + asc(byte08)) mod &h100 i = (i + asc(byte09)) mod &h100 i = (i + asc(byte10)) mod &h100 i = (i + asc(byte11)) mod &h100 i = (i + asc(byte12)) mod &h100 i = (i + asc(byte13)) mod &h100 i = (i + asc(byte14)) mod &h100 i = (i + asc(byte15)) mod &h100 i = (i + asc(byte16)) mod &h100 i = (i + asc(byte17)) mod &h100 byte18 = chrb(i) valuesChanged() End Sub #tag EndMethod #tag Method, Flags = &h0 Sub readCar() //Read values from the currently attached car End Sub #tag EndMethod #tag Method, Flags = &h0 Sub Constructor() //Make sure we have a database and if not create it dim exists as boolean exists = prepareDB() if exists = false then //No database available, create one createDB() else //Database exists, connect to it if fsicsdb.Connect = false then MsgBox "Database connection failed" end if end if End Sub #tag EndMethod #tag Method, Flags = &h21 Private Function prepareDB() As Boolean //Open the database file fsicsdb = new REALSQLDatabase dim f as FolderItem = GetFolderItem("fsicsdb") fsicsdb.DatabaseFile = f return f.Exists End Function #tag EndMethod #tag Method, Flags = &h21 Private Sub createDB() //Create a new database //make sure we can create the file if fsicsdb.CreateDatabaseFile() then if fsicsdb.Connect() then dim query as string query = "CREATE TABLE carprofiles (id INTEGER PRIMARY KEY, name VARCHAR, cartype VARCHAR, byte01 VARCHAR, byte02 VARCHAR, byte03 VARCHAR, byte04 VARCHAR, byte05 VARCHAR, byte06 VARCHAR"+_ ", byte07 VARCHAR, byte08 VARCHAR, byte09 VARCHAR, byte10 VARCHAR, byte11 VARCHAR, byte12 VARCHAR, byte13 VARCHAR, byte14 VARCHAR, byte15 VARCHAR, byte16 VARCHAR, byte17 VARCHAR"+_ ", byte18 VARCHAR, UNIQUE(name))" fsicsdb.SQLExecute(query) if fsicsdb.Error then MsgBox "Database Error (carprofiles):" + fsicsdb.ErrorMessage end if else MsgBox "Failed to connect to new database file" end if else //Failed to create database file MsgBox "Failed to create database file" end if End Sub #tag EndMethod #tag Hook, Flags = &h0 Event valuesChanged() #tag EndHook #tag Note, Name = General Car type must be set for this to operate Car types supported by this application are MR-03 dNaNo ASF #tag EndNote #tag Property, Flags = &h0 byte01 As String = "&hFF" #tag EndProperty #tag Property, Flags = &h0 byte11 As String #tag EndProperty #tag Property, Flags = &h0 byte12 As String #tag EndProperty #tag Property, Flags = &h0 byte13 As String #tag EndProperty #tag Property, Flags = &h0 byte14 As String #tag EndProperty #tag Property, Flags = &h0 byte15 As String #tag EndProperty #tag Property, Flags = &h0 byte16 As String #tag EndProperty #tag Property, Flags = &h0 byte17 As String #tag EndProperty #tag Property, Flags = &h0 byte18 As String #tag EndProperty #tag Property, Flags = &h0 byte02 As String #tag EndProperty #tag Property, Flags = &h0 byte03 As String #tag EndProperty #tag Property, Flags = &h0 byte04 As String #tag EndProperty #tag Property, Flags = &h0 byte05 As String #tag EndProperty #tag Property, Flags = &h0 byte06 As String #tag EndProperty #tag Property, Flags = &h0 byte07 As String #tag EndProperty #tag Property, Flags = &h0 byte08 As String #tag EndProperty #tag Property, Flags = &h0 byte09 As String #tag EndProperty #tag Property, Flags = &h0 byte10 As String #tag EndProperty #tag Property, Flags = &h0 carType As String = "MR-03" #tag EndProperty #tag Property, Flags = &h0 fsicsdb As REALSQLDatabase #tag EndProperty #tag ViewBehavior #tag ViewProperty Name="Name" Visible=true Group="ID" InheritedFrom="serial" #tag EndViewProperty #tag ViewProperty Name="Index" Visible=true Group="ID" Type="Integer" InheritedFrom="serial" #tag EndViewProperty #tag ViewProperty Name="Super" Visible=true Group="ID" InheritedFrom="serial" #tag EndViewProperty #tag ViewProperty Name="Left" Visible=true Group="Position" InheritedFrom="serial" #tag EndViewProperty #tag ViewProperty Name="Top" Visible=true Group="Position" InheritedFrom="serial" #tag EndViewProperty #tag ViewProperty Name="Baud" Visible=true Group="Behavior" InitialValue="13" Type="Integer" EditorType="Enum" InheritedFrom="serial" #tag EnumValues "0 - 300" "1 - 600" "2 - 1200" "3 - 1800" "4 - 2400" "5 - 3600" "6 - 4800" "7 - 7200" "8 - 9600" "9 - 14400" "10 - 19200" "11 - 28800" "12 - 38400" "13 - 57600" "14 - 115200" "15 - 230400" #tag EndEnumValues #tag EndViewProperty #tag ViewProperty Name="Bits" Visible=true Group="Behavior" InitialValue="3" Type="Integer" EditorType="Enum" InheritedFrom="serial" #tag EnumValues "0 - 5 Data Bits" "1 - 6 Data Bits" "2 - 7 Data Bits" "3 - 8 Data bits" #tag EndEnumValues #tag EndViewProperty #tag ViewProperty Name="Parity" Visible=true Group="Behavior" InitialValue="0" Type="Integer" EditorType="Enum" InheritedFrom="serial" #tag EnumValues "0 - No Parity" "1 - Odd Parity" "2 - EvenParity" #tag EndEnumValues #tag EndViewProperty #tag ViewProperty Name="Stop" Visible=true Group="Behavior" InitialValue="0" Type="Integer" EditorType="Enum" InheritedFrom="serial" #tag EnumValues "0 - 1 Stop Bit" "1 - 1.5 Stop Bits" "2 - 2 Stop Bits" #tag EndEnumValues #tag EndViewProperty #tag ViewProperty Name="XON" Visible=true Group="Behavior" Type="Boolean" InheritedFrom="serial" #tag EndViewProperty #tag ViewProperty Name="CTS" Visible=true Group="Behavior" Type="Boolean" InheritedFrom="serial" #tag EndViewProperty #tag ViewProperty Name="DTR" Visible=true Group="Behavior" Type="Boolean" InheritedFrom="serial" #tag EndViewProperty #tag ViewProperty Name="byte01" Group="Behavior" InitialValue="&hFF" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte11" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte12" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte13" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte14" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte15" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte16" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte17" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte18" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte02" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte03" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte04" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte05" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte06" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte07" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte08" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte09" Group="Behavior" Type="String" #tag EndViewProperty #tag ViewProperty Name="byte10" Group="Behavior" Type="String" #tag EndViewProperty #tag EndViewBehavior End Class #tag EndClass