@@ -21,6 +21,8 @@ you can get the build error info in `Message` window if there is any error in th
21
21
You can open the ` API ` window to get the API info.
22
22
![ alt text] ( image-2.png )
23
23
24
+ or check this online documentation [ API] ( https://app.whyengineer.com/scriptApi/index.html )
25
+
24
26
## Script Usage
25
27
26
28
### Node.js Ability
@@ -93,3 +95,58 @@ Util.On('Can.DiagRequest.send', (msg) => {
93
95
// receive diag request
94
96
})
95
97
```
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