Hello everyone,
I need help understanding how to write this script in PCAN-Explorer 6:
Basically I need to send two different CAN messages, one for communicate with a board every 250ms and one to pilot a load every 4 seconds.
Something like this:
for x times:
Message 1
ID 1
(data)
wait 250
Message 2
ID 2
(data)
wait 4000
These two messages need to be sent in the same macro, in "parallel".
I'm new in writing macros so I was thinking on how to do it without getting stuck in the "wait" statement of the one that last 4s.
Any ideas? Can I create two different sub in the same macro and then a third that call the two with their specific timing?
I hope my request is clear,
I'm available for more information,
thank you in advance for your response.
Sending CAN messages with different timing in the same script
-
- Posts: 4
- Joined: Mon 24. Jun 2024, 15:01
-
- Support
- Posts: 11
- Joined: Tue 31. Aug 2010, 12:42
Re: Sending CAN messages with different timing in the same script
Hello,
That's not possible in a standard Macro,
you could use a VBS Macro and use a rudimentary timer implementation:
Instead of just printing to Output you could send your messages at these checks..
BR
Marvin
That's not possible in a standard Macro,
you could use a VBS Macro and use a rudimentary timer implementation:
Code: Select all
Sub TimerInstance()
Dim startTime, currentTime, elapsedTime
startTime = Now() ' Store the starting time
Do
currentTime = Now() ' Get the current time
elapsedTime = DateDiff("s", startTime, currentTime) ' Calculate the elapsed time in seconds
' Perform actions based on elapsed time
If elapsedTime = 2 Then
PrintToOutputWindow "Performing Action A (2 seconds)"
ElseIf elapsedTime = 4 Then
PrintToOutputWindow "Performing Action B (4 seconds)"
ElseIf elapsedTime = 8 Then
PrintToOutputWindow "Performing Action C (8 seconds)"
End If
' Stop the loop after 8 seconds
If elapsedTime >= 8 Then Exit Do
Wait 500 ' Sleep for 500 milliseconds to avoid using 100% CPU
Loop
End Sub
Instead of just printing to Output you could send your messages at these checks..
BR
Marvin
-
- Posts: 4
- Joined: Mon 24. Jun 2024, 15:01
Re: Sending CAN messages with different timing in the same script
Thank you for your reply,
I will try this method
Riccardo
I will try this method
Riccardo