Skip to content

Commit c3a4a6e

Browse files
committed
update doc
1 parent 65c8c9d commit c3a4a6e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

docs/um/script.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ you can get the build error info in `Message` window if there is any error in th
2121
You can open the `API` window to get the API info.
2222
![alt text](image-2.png)
2323

24+
or check this online documentation [API](https://app.whyengineer.com/scriptApi/index.html)
25+
2426
## Script Usage
2527

2628
### Node.js Ability
@@ -93,3 +95,58 @@ Util.On('Can.DiagRequest.send', (msg) => {
9395
//receive diag request
9496
})
9597
```
98+
99+
100+
## Example
101+
102+
::: details Send 10 CAN messages on script initialization, then send one more message after 30s delay {open}
103+
104+
```typescript
105+
async function sendCanMessage(msgId: number, targetId: number, dataPattern: string) {
106+
console.log(`sendCanMessage called with msgId: ${msgId}, targetId: ${targetId}`);
107+
108+
const dataBytes = Buffer.from(dataPattern.repeat(8), 'hex');
109+
console.log("Total Length:", dataBytes.length);
110+
111+
const fdMsg: CanMessage = {
112+
id: targetId,
113+
dir: 'OUT',
114+
data: dataBytes,
115+
msgType: {
116+
idType: CAN_ID_TYPE.STANDARD,
117+
brs: true,
118+
canfd: true,
119+
remote: false,
120+
}
121+
};
122+
123+
try {
124+
await output(fdMsg);
125+
} catch (error) {
126+
console.error(`CAN FD 发送失败 (ID: ${msgId}):`, error);
127+
}
128+
129+
}
130+
131+
Util.Init(async () => {
132+
console.log("Init");
133+
// 循环 10 次,定义不同的消息 ID 和数据内容
134+
for (let i = 0; i < 10; i++) {
135+
const msgId = 0x510 + i;
136+
const targetId = 0x520 + i;
137+
const dataPattern = i % 2 === 0 ? '1234567890ABCDEF' : 'FFAABBCCDDEE5599';
138+
await sendCanMessage(msgId, targetId, dataPattern);
139+
}
140+
141+
setTimeout(() => {
142+
console.log("Timeout triggered, preparing to send CAN message...");
143+
const msgId = 0x510 + 10;
144+
const targetId = 0x520 + 10;
145+
const dataPattern = 'DEADBEEFCAFEBABE';
146+
147+
sendCanMessage(msgId, targetId, dataPattern);
148+
}, 30000); // 延时 30 秒
149+
})
150+
```
151+
:::
152+

0 commit comments

Comments
 (0)