顯示具有 ecu simulator 標籤的文章。 顯示所有文章
顯示具有 ecu simulator 標籤的文章。 顯示所有文章

2025年8月5日 星期二

PeakCAN 與 ECU Simulator 通訊利用OpenAI 來找尋DTC 的解釋

在這一篇文章中PeakCAN Bus 與 ECU Simulator 通訊 擷取 DTC Data
得到DTC錯誤代碼但是有太多的錯誤代碼, 本來想說在本機建立一個database來搜尋, 靈機一動想說現在萬物都OpenAI, 於是就在得到DTC時把OpenAI API的功能寫進去來尋找 DTC的意義!
錯誤碼=>所有常見的 OBD2 錯誤代碼:解讀 P、B、C、U 程式碼
在Microsoft Visual Studio中利用NuGet 安裝OpenAI

using OpenAI;
using OpenAI.Chat;

private async void button3_Click(object sender, EventArgs e)
{
    //string dtcCode = txtDTC.Text.Trim();
    string dtcCode = "P0218".Trim();

    if (string.IsNullOrEmpty(dtcCode))
    {
        MessageBox.Show("請輸入 DTC 代碼,例如 P0202");
        return;
    }

    button3.Enabled = false;
    //txtResult.Text = "查詢中,請稍候...";
    CommonData.WriteMessage("查詢中,請稍候...", "", Color.Blue, Color.Red);

    string myApiKey = "your key";

    ChatClient client = new(
        model: "gpt-4.1",  //gpt-4
        apiKey: myApiKey
    );

    try
    {
        var prompt = $"請解釋 OBD2 故障碼 {dtcCode} 的意思,用繁體中文回答";
        
        ChatCompletion completion = await client.CompleteChatAsync(prompt);   
        CommonData.WriteMessage("查詢結果...", completion.Content[0].Text.ToString(), Color.Blue, Color.Red);
    }
    catch (Exception ex)
    {
        //txtResult.Text = "錯誤:" + ex.Message;
    }
    finally
    {
        button3.Enabled = true;
    }
}


還真的可以用!真是方便!!

2025年7月31日 星期四

PeakCAN 與 ECU Simulator 通訊 擷取 DTC Data

讀取 ECU Simulator 診斷故障碼 (Diagnostic Trouble Code, DTC)
利用PeakCAN Tools抓取的資料

送出以下 Flow Control(FC)封包,才會收到後面的連續幀:
CAN ID: 0x7E0(ECU 接收 ID)
DATA:   30 00 00 00 00 00 00 00
                
                └─ 0x30 = Flow Control (CTS: Continue To Send)

第一幀:
CAN ID: 7E8  
Data:    10 10 43 02 01 68 03 03
DTC 解碼規則:
Byte  位置     說明
0    10        First Frame (FF) 標誌(高4位元=1),表示這是多幀資料起始幀
1    10        剩餘資料長度 = 0x10 = 16 bytes(不含前2個控制位元)
2    43        服務ID:0x43,代表回應「Mode 03(讀取 DTC)」請求(0x03 + 0x40)
3    02        DTC 數量 = 2(總共兩筆故障碼)
4~5  01 68  第1筆 DTC
6~7  03 03  第2筆 DTC

每個 DTC 為 2 bytes,使用下列方式轉為代碼(5 碼):
高 2 bits(byte1) → 類型代碼(P, C, B, U):
00 = P(Powertrain)
01 = C(Chassis)
10 = B(Body)
11 = U(Network)
第一筆:01 68
0x0168 = 00000001 01101000
高兩位是 00 → P
剩下:168 → P0168
說明:燃油溫度過高(Fuel Temperature Too High)
第二筆:03 03
0x0303 = 00000011 00000011
高兩位是 00 → P
剩下:303 → P0303
說明:汽缸 3 點火失敗(Cylinder 3 Misfire Detected)
第二幀:
21 00 00 00 00 00 00 00 00   ← Consecutive Frame #1
第三幀:
22 00 00 00 00 00 00 00 00   ← Consecutive Frame #2

PeakCAN 與 ECU Simulator 通訊 擷取 VIN Data

在這篇文章 ECU Simulator CAN Bus Data with ESP32+MCP2515
當要去讀取 VIN (Vehicle Identification Number) Mode $09 - Vehicle Information 
始終都是只有得到
CAN ID: 0x7E8  
DATA:   10 14 49 02 01 31 46 54  
                │  │
                │  └─ 0x14 = 20 bytes 要回傳(包含 service, pid, vin 等)
                └─ 0x10 = First Frame(多幀傳輸)
找了許多資料知道有些ECU 需要 Flow Control Frame
所以送出以下 Flow Control(FC)封包,才會收到後面的連續幀:
CAN ID: 0x7E0(ECU 接收 ID)
DATA:   30 00 00 00 00 00 00 00
                
                └─ 0x30 = Flow Control (CTS: Continue To Send)
利用之前寫的PeakCAN Tool送出command frame:

終於得到完整的datas
第一幀 
10 14 49 02 01 31 46 54
│  │
│  └─ 0x14 = 20 bytes 資料總長
└──── 0x10 = First Frame

49 02 = 回應 Mode 0x09 + PID 0x02(VIN)
01 = 回傳資料塊 ID = 第 1 組 VIN 塊
31 46 54 = '1FT'(ASCII)
第二幀
21 4C 52 34 46 45 58 42
│ └────────────── 'LR4FEXB'
└─ 0x21 = Consecutive Frame index 1
第三幀
22 50 41 39 38 39 39 34
│ └────────────── 'PA98994'
└─ 0x22 = Consecutive Frame index 2

完整 VIN 字串共 17 個字元,已完全符合 OBD-II 規範
VIN: 1FTLR4FEXBPA98994


2023年11月23日 星期四

Understand diagnostic trouble codes of your car

Purpose:
本專題利用ESP32+MCP2515 CAN Bus module搭配CANHacker軟體和Torque APP去分析接收到ECU Simulator的診斷錯誤碼的PID資料.
This topic uses the ESP32+MCP2515 CAN Bus module with CANHacker software and Torque APP to analyze the PID data of the diagnostic trouble codes received from the ECU Simulator.

Fundamental:
Reference https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_03
Diagnostic Trouble Codes (DTC) or Fault Codes
Under OBDII / EOBD systems, all manufacturers must use a universal 5 digits code system.
These universal 5 digits codes are made up of:
• The 1st character in the DTC indicates a letter which identifies the “main
system” where the fault occurred (Power train, Body, Chassis or
Network)
• The 2nd character is a numerical digit which identifies “Generic or
Manufacturer Specific”
• The 3rd character is also a numerical digit which identifies the specific
systems or sub-systems where the problem is located.
• The 4th and 5th characters are also numerical digits which identifies the
section of the system that is malfunctioning.

CAN Hacker module (ESP32+MCP2515)
Reference the previous article link on blog:
ECU Simulator
模擬器提供下列模式:
系統狀態、即時資料:MODE 01
故障診斷:MODE 03,07,0A
故障清除:MODE 04
凍結資料:MODE 02
氧感測器測試:MODE 05
監測結果:MODE 06
車輛資訊:MODE 09 
模擬器提供六組模擬訊號調整旋鈕。由左至右編號為1~6。
預設模擬訊號源為:空氣流量、冷卻液溫度、轉速、車速、進氣溫度、節氣門位置
Reference the previous article link on blog:

YouTube Demo:



ECU fault code analysis
Understand diagnostic trouble code of your car
Car DTC analysis via ESP32 CAN Bus module


2023年11月16日 星期四

ESP32+MCP2515 CAN Bus Scanner with ELM327 and ECU simulator

Purpose:
In this project it will be demonstrated that the ELM327 (Bluetooth interface), ECU emulator and ESP32 + MCP2515 module communicate with each other through the Controller Area Network (CAN) bus in the car's OBD-II (On-Board Diagnostics 2) connector.
在這個專案中將展示ELM327(藍牙介面)、ECU模擬器和ESP32 + MCP2515模組透過汽車的 OBD-II(車載診斷 2)連接器中的控制器區域網路 (CAN ) 匯流排相互通訊。

Fundamental:
ELM327 Bluetooth Automotive Code Readers
The ELM327 is a multi-protocol adapter that allows a pc or other device to communicate with a car's OBD-II engine management system through the Controller Area Network (CAN) bus. The ELM327 OBD2 interface is a great tool for any car owner, and it will help you keep on top of any issues that may arise with your vehicle.
reference https://en.wikipedia.org/wiki/ELM327

The previous article link on blog:
CAN BUS 通訊研究

Circuit:

YouTube Demo: