顯示具有 CANBUS通訊 標籤的文章。 顯示所有文章
顯示具有 CANBUS通訊 標籤的文章。 顯示所有文章

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


2025年7月25日 星期五

CAN Bus 測距通訊軟件開發

Purpose:
基於Radar, UWB等可以量測距離的產品, 開發出一套可以解析CAN bus上接收到的資料, 繪製成360度的GUI顯示出來距離跟角度.
構成要件:
接收介面:
PeakCAN接收的GUI 參閱之前的文章 
PeakCAN Windows GUI Application - Two Channel
解析介面:
CAN bus 通訊的UWB產品
由Initiator跟responder通訊後經由responder解析收到的資料後送至顯示介面顯示.
顯示介面:
360度距離角度GUI
接收解析後的距離跟角度的資料後, 繪製GUI顯示.
影像介面:
經由WEBCAM由responder視角看出, 顯示目前時間跟中心位置cross焦點.

2025年5月9日 星期五

PeakCAN Windows GUI Application - Two Channel

Purpose:
利用兩台PeakCAN撰寫一個利用c#寫的MDI(Mutliple Document Interface)來擷取CAN Bus上面的資料, 可應用於CAN Bus介面上的產品分析, 或是配合OBD2的介面的接線來接收車子的CAN Bus上的資料.

介面設計:
利用PeakCAN給的範例架構在MDI的GUI上面

另外在撰寫一個transmit的介面, 可同時連續傳送或是傳送一次勾選的ID內容
GUI上半部可同時監看兩台PeakCAN的接收與傳送的資料


2024年7月1日 星期一

CAN Bus Sniffer by PeakCAN windows software GUI

Purpose:
經由這篇文章PeakCAN windows software for CAN Bus message後, 再次利用PeakCAN的 PCANBasic API for C#的sample修改為自己的CAN Bus Sniffer擷取在CAN BUS介面上的資料!
特點
1. 增加monitor功能 
所有的CAN Bus上的資料 Tx and Rx 都可以即時監控.
2. 增加可同時多個Tx 傳送的CAN Bus資料依據個別定義的時序傳送
After reading this article PeakCAN windows software for CAN Bus message, I once again used the sample of PeakCAN's PCANBasic API for C# to modify it into my own CAN Bus Sniffer to capture the data on the CAN BUS interface!
Features
1. Add monitor function
All data Tx and Rx on the CAN Bus can be monitored in real time.
2. Added CAN Bus data that can be transmitted by multiple Tx at the same time according to individually defined timings.
利用自己製作的ESP32 CAN module搭配CAN Hacker software去做驗證!

YouTubeDemo:


2024年4月29日 星期一

PeakCAN windows software for CAN Bus message

Purpose:
利用PeakCAN提供的PCANBasic API for C#的sample去修改成自己適用的專案程式.

PCAN-Basic API
PCAN DB9 Connector

PCAN-Basic API for C#


Architectures:
利用ESP32_MCP2515 module 去驗證 PCAN_Basic API
YouTube Demo:



2023年12月22日 星期五

24G Radar TX Verify

Purpose:
如何去驗證一台24G radar的TX path是否功能正常. 我利用了 C#寫了一個介面程式可以控制到頻譜分析儀, 去抓去DUT TX路徑所打出的能量再去判斷能量值是否正常!
在這個專題上, 利用ESP32+MCP2515 CAN Bus模組對一台CAN Bus介面的雷達下CW Mode的指令, 並且使用頻譜分析儀去抓取雷達發送出的能量波來驗證雷達TX path的好壞!
How to verify whether the TX path of a 24G radar is functioning properly.
Architectures:
Need materials:
1. A 24G Radar with CAN Bus interface
2. ESP32+MCP2515 module(Send command to Radar)

3. A Spectrum analyzer above 24GHz
4. A Horn Antenna covering 24G
5. DUT holder and turn table
Reference the previous article link on blog:
Rohde&Schwarz FSV Signal Analyzer control by C#

YouTubeDemo:
C# GUI to control Spectrum analyzer for remote control.


2023年12月6日 星期三

雷達產品的CAN Bus測試

Purpose:
CAN Bus test of radar products
在雷達產品的測試上, 為了驗證產品上的CAN Bus Function是否正常. 因此在測試的環境中, 用最便宜跟能夠搭配產測程式的方案(Mega2560+MCP2515+RelayBoard).
並且利用ESP32+MCP2515 module和 PCAN-USB-FD去做驗證.
In the test of radar products, in order to verify whether the CAN Bus Function on the product is normal. Therefore, in the test environment, the cheapest solution that can be matched with the production test program (Mega2560+MCP2515+RelayBoard) is used.
And use ESP32+MCP2515 module and PCAN-USB-FD for verification.
Architectures:


Fundamental:
PCAN-USB-FD
The PCAN-USB FD interface enables simple connection to CAN FD and CAN networks. Its compact plastic casing makes it suitable for mobile applications. A galvanic isolation of up to 500 Volts decouples the PC from the CAN bus.


Reference the previous article link on blog:
ESP32 + MCP2515 use CanHacker on CAN Bus system

YouTube Demo:




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月20日 星期一

Catch your vehicle Data via cheap CAN bus Tool

Purpose:
這個專案是利用便宜的方案去抓取你的車子CANBUS的資料.
This project uses a cheap solution to capture your car’s actionable information of CANBUS data.

Architectures:
利用OBD2接頭延長線連接汽車, ELM327 and CAN Hacker module (ESP32+MCP2515).
再使用手機TORQUE APP 讀取車子的資訊並且利用PC的CANHACKER software接收資料並儲存以利後續分析PID資料.
Use the OBD2 connector extension cable to connect the car, ELM327 and CAN Hacker module (ESP32+MCP2515).
Then use the TORQUE APP on your mobile phone to read the car's information and use the PC's CANHACKER software to receive the data and store it for subsequent analysis of the PID data.

BOM(Bill of Material) Cost:  682NT

Fundamental:
CAN Hacker module (ESP32+MCP2515)
Reference the previous article link on blog:
ESP32 + MCP2515 use CanHacker on CAN Bus system 

OBD2(On-Board Diagnostics 2)
OBD-II systems provide access to health information and access to numerous parameters and sensors from the Electronic Control Units (ECUs). Thus, the OBDII system offers valuable information, including diagnostic trouble codes when troubleshooting problems.
if your car was manufactured after 1996, it features a Diagnostic Link Connector (DLC) or OBD2 port.

ELM327(Bluetooth interface)


ELM327 device acts as a bridge between the computer/mobile and the car. The OBD adapter is attached to the car's physical 16-pin OBD connector plug (OBD2 port), typically located near the dashboard below the steering wheel.
There are different types of interfaces that the ELM327 adapters can have, for example, Bluetooth, WiFi, USB, or serial port. For the best option for your needs.

Torque APP is for Android phones to use it with the ELM327 devices.
Reference https://wiki.torque-bhp.com/view/Main_Page

Torque is an OBD2 performance and diagnostic tool for any device that runs the Android operating system. It will allow you to access the many sensors within your vehicles Engine Management System, as well as allow you to view and clear trouble codes.


YouTube Demo:





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:



2023年9月14日 星期四

ECU Simulator CAN Bus Data with ESP32+MCP2515

Purpose:

依據之前的文章 ESP32 + MCP2515 use CanHacker on CAN Bus system和CAN BUS 通訊研究, 重新把ECU simulator跟 ESP32 Canhacker的CAN Bus通訊結果作整理. 

Based on the previous article ESP32 + MCP2515 use CanHacker on CAN Bus system and CAN BUS communication research, the CAN Bus communication results between ECU simulator and ESP32 Canhacker are reorganized.


模擬器提供下列模式:

系統狀態、即時資料:MODE 01
故障診斷:MODE 03,07,0A
故障清除:MODE 04
凍結資料:MODE 02
氧感測器測試:MODE 05
監測結果:MODE 06
車輛資訊:MODE 09 

模擬器提供六組模擬訊號調整旋鈕。由左至右編號為1~6。
預設模擬訊號源為:空氣流量、冷卻液溫度、轉速、車速、進氣溫度、節氣門位置

詢問汽車功能的CAN匯流排節點識別碼0x7DF , 接收汽車OBD資料要將Acceptance
Filter設為0x7E8,都是依據ISO 15765-4文件所定規範。
If ( CANIsTxReady ( ) )
{ TX_Data_Buf2[0] = 0x02 ;
TX_Data_Buf2[1] = 0x01 ;
TX_Data_Buf2[2] = PID_code;
TX_Data_Buf2[3] = 0x00 ;
TX_Data_Buf2[4] = 0x00 ;
TX_Data_Buf2[5] = 0x00 ;
TX_Data_Buf2[6] = 0x00 ;
TX_Data_Buf2[7] = 0x00 ;
CANSendMessage ( 0x7DF , TX_Data_Buf2 ,
8,CAN_TX_PRIORITY_1&
CAN_TX_STD_FRAME&
CAN_TX_NO_RTR_FRAME ) ;
}

if ( CANIsRxReady ( ) )
{
CANReceiveMessage( &RX_ID1 ,
RX_Data_Buf1 , &RX_Data_Len1 ,
&RX1_Message_Flag ) ;
if (RX_ID1==0x7E8)
{ Engine RPM = ((A*256)+B)/4 ; }
}

Reference https://en.wikipedia.org/wiki/OBD-II_PIDs





Circuit:
YouTube Demo: