Code: Select all
Sub automationTest2() 'Automation for bus 1
Dim msg, msg1
' Initialize the CAN message
For i = 0 To 1
Set msg = TransmitMessages.Add
With msg
If Connections.Count > 0 Then _
Set .Connection = Connections(1)
.ID = &Hxxxxxxxxx 'ID transmit
.DataLength = 8
'(DATA)
msg.CycleTime = 500 'Cycle time
msg.IsPaused = False
End With
Set msg1 = TransmitMessages.Add
With msg1
If Connections.Count > 0 Then _
Set .Connection = Connections(2)
.ID = &Hxxxxxxxx 'ID transmit
.DataLength = 8
'(DATA)
msg1.CycleTime = 500 'Cycle time
msg1.IsPaused = False
End With
Wait 25000
With msg
If Connections.Count > 0 Then _
Set .Connection = Connections(1)
.ID = &Hxxxxxxxx 'ID transmit
.DataLength = 8
'(DATA)
msg.CycleTime = 500 'Cycle time
msg.IsPaused = False
End With
With msg1
If Connections.Count > 0 Then _
Set .Connection = Connections(2)
.ID = &Hxxxxxxxx 'ID transmit
'(DATA)
msg1.CycleTime = 500 'Cycle time
msg1.IsPaused = False
End With
Wait 25000
Next
msg.IsPaused = True 'Stops cycle
msg1.IsPaused = True
End Sub
During the second "for" cycle, the script re-sends the instructions with data, and in the PCAN receive/transmit section, I see the previous two frames (still running) along with the current two frames. In the last cycle, it repeats again, queuing the same two frames repeatedly like this:
```
frame 1 bus 1 (running)
frame 2 bus 2 (running)
frame 1 bus 1 (running)
frame 2 bus 2 (running)
frame 1 bus 1 (running)
frame 2 bus 2 (running)
```
How can I solve this problem? What am I doing wrong? i am still inexperienced with macros and I need each "for" cycle to only modify the first two frames, and not add the same two instructions again, maintaining the previous ones as active.
I hope I've explained well. I'm available for additional information. Thanks.