做个记录。
首先我们需要进行 UDS 诊断配置。
然后,在 CAPL 中,我们要例化一些已经定义的请求:
diagRequest BasicDiagnosticsEcu.ReadDimmConfigData DiagReadDimmingFactor; diagRequest BasicDiagnosticsEcu.WriteDimmConfigData DiagWriteDimmingFactor;
对于发送诊断读,比如 0x22,我们可以直接发送请求就可以,比如,我们通过一个 env 来触发这个发送:
on envVar envVar_BtnReadDimmingFator { if(getValue(this) == 1) diagSendRequest( DiagReadDimmingFactor); }
对于发送诊断写,比如 0x2E, 我们需要先设置数据:
... sendData[0] = (theFactor>>8) & 0xFF; sendData[1] = theFactor & 0xFF; diagResize(DiagWriteDimmingFactor, 8); DiagWriteDimmingFactor.SetPrimitiveByte(3, index); DiagWriteDimmingFactor.SetPrimitiveByte(4, 0x00); DiagWriteDimmingFactor.SetPrimitiveByte(5, 0x00); DiagWriteDimmingFactor.SetPrimitiveByte(6, sendData[0]); DiagWriteDimmingFactor.SetPrimitiveByte(7, sendData[1]); Write("Write dimming Factor: 0x2E 0x41 0x0B 0x%02X 0x00 0x00 0x%02X 0x%02X", index, sendData[0], sendData[1]); diagSendRequest(DiagWriteDimmingFactor); diagResize(DiagWriteDimmingFactor, 4); DiagWriteDimmingFactor.SetPrimitiveByte(3, 0x0FF); diagSendRequest(DiagWriteDimmingFactor);
对于 Response 的处理,我们可以这样全部收过来之后再处理:
on diagResponse * { int size; byte data[128]; size= this.GetPrimitiveSize(); this.GetPrimitiveData(data, elcount(data)); if((data[0] == 0x62) && (data[1] == 0x41) && (data[2] == 0x0B)) { ... } }
另外,记录一个小技巧,不用每次都改那个判断里的 env 变量名称:
on envVar envVar_BtnDimmingFator00 { if(getValue(this) == 1) doUpdateDimmingFactor(0); }
标签:UDS,sendData,DiagWriteDimmingFactor,0x00,诊断,CPAL,SetPrimitiveByte,envVar,data From: https://www.cnblogs.com/pied/p/17083819.html