initSer(4,230400,8,0,1) -- ReadLine = readSer(4, 100) -- if ReadLine ~= nil then -- println(" "); -- println(ReadLine) -- end -- RCP Chan Sample Prec Min Max Units VirtualRPM = addChannel("RPM", 10, 0, 0, 13000, "x100") VirtualTP1 = addChannel("TP1", 25, 0, 0, 100, "%") VirtualIAP = addChannel("IAP", 10, 0, 0, 100, "kPa") VirtualECT = addChannel("ECT", 1, 0, 0, 250, "F") VirtualIAT = addChannel("IAT", 1, 0, 0, 250, "F") VirtualAAP = addChannel("AAP", 1, 0, 0, 100, "kPa") VirtualECUV = addChannel("ECUV", 10, 2, 0, 15, "V") VirtualO2S = addChannel("O2S", 10, 2, 0, 255) VirtualGear = addChannel("Gear", 1, 0, 0, 6, "Gear") VirtualTP2 = addChannel("TP2", 10, 1, 0, 255, "%") VirtualSTRT = addChannel("STRT", 1, 0, 0, 1, "On") VirtualCLUT = addChannel("CLUT", 1, 0, 0, 1, "In") setTickRate(25) PacketCounter = 0 function onTick() DataPacket = {} Header = false ByteReceived = readCSer(4,1) -- Read a byte -- print(ByteReceived) -- Error here while ByteReceived ~= nil do -- Look for header if no timeout if (ByteReceived == 0xFE) then DataPacket[1] = ByteReceived ByteReceived = readCSer(4,1) if ByteReceived == 0xAA then DataPacket[2] = ByteReceived Header = true end end if (Header == true) then -- Found the header Index = 3 ByteReceived = readCSer(4,2) while ByteReceived ~= nil do -- Read all the data bytes DataPacket[Index] = ByteReceived ByteReceived = readCSer(4,2) Index = Index + 1 if Index >= 64 then break end -- Too many bytes, something's wrong end if(Index==15) then -- If proper # bytes, update channels setChannel(VirtualRPM,DataPacket[3]) setChannel(VirtualTP1, DataPacket[4]) setChannel(VirtualIAP, DataPacket[5]) setChannel(VirtualECT, DataPacket[6]) setChannel(VirtualIAT, DataPacket[7]) setChannel(VirtualAAP, DataPacket[8]) setChannel(VirtualECUV, DataPacket[9]) setChannel(VirtualO2S, DataPacket[10]) setChannel(VirtualGear, DataPacket[11]) setChannel(VirtualTP2, DataPacket[12]) setChannel(VirtualSTRT, DataPacket[13]) setChannel(VirtualCLUT, DataPacket[14]) print(".") PacketCounter = PacketCounter + 1 if(PacketCounter >= 63) then println(" ") PacketCounter = 0 end if (DataPacket[3]>= 200) then startLogging() else stopLogging() end end -- updating virtual channels end -- processing this packet if(Header == false) then -- Else continue looking for header ByteReceived = readCSer(4,1) end end end