Help creating Macro
Help creating Macro
Hello,
I'm new to the software and I'm trying to create a simple macro that send back the received data from the CAN bus.
Do you already have an example or tutorial on how to write a macro and run it ?
Thank you
I'm new to the software and I'm trying to create a simple macro that send back the received data from the CAN bus.
Do you already have an example or tutorial on how to write a macro and run it ?
Thank you
Re: Help creating Macro
Hi,
please have a look in the help of PCAN-Explorer 6. See Refernce->Standardmacros for examples on the use of Standard Macros. With a Standard Macro you have very simple commands like send, wait or waitid etc. with which you should be able to handle your task. If you like to get some sample for VBmacros, please send us an email to our support email address with your license ID of your PCAN-Explorer 6 license. We will than send you some examples for VB Macros by email.
regards
Michael
please have a look in the help of PCAN-Explorer 6. See Refernce->Standardmacros for examples on the use of Standard Macros. With a Standard Macro you have very simple commands like send, wait or waitid etc. with which you should be able to handle your task. If you like to get some sample for VBmacros, please send us an email to our support email address with your license ID of your PCAN-Explorer 6 license. We will than send you some examples for VB Macros by email.
regards
Michael
Re: Help creating Macro
Thank you for the reply.
It has helped me understand a lot more.
But I couldn't see a way to "save" received data to send them back. I can check the data but can I store them ? (with a .mcr file)
Thank you
It has helped me understand a lot more.
But I couldn't see a way to "save" received data to send them back. I can check the data but can I store them ? (with a .mcr file)
Thank you
Re: Help creating Macro
Hi,
with a standard macro (*.mcr) you cannot handle a storage of data. For this purpose please use the VBmacros.
regards
Michael.
with a standard macro (*.mcr) you cannot handle a storage of data. For this purpose please use the VBmacros.
regards
Michael.
Re: Help creating Macro
Thank you.
I'm trying now to send back the received values. Should I use AutoTransmit function or put the data in the TransmitMessages.
I used one of your code that you posted in another topic:
Both of the methods won't work. Isn't the data put in TransmitMessages automaticcly transmitted ?
The goal here is to send back the data from msg with another ID.
Thank you for the help
I'm trying now to send back the received values. Should I use AutoTransmit function or put the data in the TransmitMessages.
I used one of your code that you posted in another topic:
Code: Select all
'------------------------------------------------------------------------------
'FILE DESCRIPTION:
'------------------------------------------------------------------------------
Option Explicit
SUB Check_ID_By_ReceiveList()
PrintToOutputWindow("START")
Dim send_msg, msg, OldCount, str, i
Set send_msg = TransmitMessages.Add
OldCount = 0
While TRUE
For Each msg In Connections.ReceiveMessages
If msg.ID = 2030 AND (msg.EventCount <> OldCount)Then ' ID and Counter is changed...
For i = 0 To msg.DataLength-1
str = str & Hex(msg.Data(i)) & " "
Next
PrintToOutputWindow("Counter: " & msg.EventCount & " ID= " & Hex(msg.ID) & " Data= " & str)
OldCount = msg.EventCount ' Save for the next loop
With send_msg
If Connections.Count > 0 Then _
Set .Connection = Connections(1)
'.BeginUpdate
.ID = &h755
.Data(0) = msg.Data(0)
.Data(1) = msg.Data(1)
.Data(2) = msg.Data(2)
.Data(3) = msg.Data(3)
.Data(4) = msg.Data(4)
.Data(5) = msg.Data(5)
.Data(6) = msg.Data(6)
.Data(7) = msg.Data(7)
End With
End if
str=Null
Next
Wend
End Sub
The goal here is to send back the data from msg with another ID.
Thank you for the help
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Help creating Macro
Hello,
In this case you have created a new message object and allocated
values to its variables, however you'll need to explicitly send the message object.
Auto transmit only works signal based, so if you change data in a newly created message
object, it will have no influence on the signal data, therefore no auto-transmit will occur.
How you proceed is up to your personal preference, if you want to specifically change a certain signal
upon reception of a message, you should work signal based. Changing the signal value is quite easy,
you only need to obtain the signal from the Signals collection and assign a new value to it, if auto-transmit
is enabled this will send the message that the singal is used in with the updated signal data, example:
Alternatively you could proceed with your code and rewrite the message bytes manually,
you will however have to send the message by using the function "Write":
So in that case you would have to append this to your macro:
Best Regards
Marvin
In this case you have created a new message object and allocated
values to its variables, however you'll need to explicitly send the message object.
Auto transmit only works signal based, so if you change data in a newly created message
object, it will have no influence on the signal data, therefore no auto-transmit will occur.
How you proceed is up to your personal preference, if you want to specifically change a certain signal
upon reception of a message, you should work signal based. Changing the signal value is quite easy,
you only need to obtain the signal from the Signals collection and assign a new value to it, if auto-transmit
is enabled this will send the message that the singal is used in with the updated signal data, example:
Code: Select all
Sub ChangeSignalValue()
Dim Signal
'Get signal form the Signals collection.
Set Signal = Signals("MySignal")
'Value is changed, auto-transmit will send message.
Signal.Value = 2
End Sub
Alternatively you could proceed with your code and rewrite the message bytes manually,
you will however have to send the message by using the function "Write":
So in that case you would have to append this to your macro:
Code: Select all
'------------------------------------------------------------------------------
'FILE DESCRIPTION:
'------------------------------------------------------------------------------
Option Explicit
SUB Check_ID_By_ReceiveList()
PrintToOutputWindow("START")
Dim send_msg, msg, OldCount, str, i
Set send_msg = TransmitMessages.Add
OldCount = 0
While TRUE
For Each msg In Connections.ReceiveMessages
If msg.ID = 2030 AND (msg.EventCount <> OldCount)Then ' ID and Counter is changed...
For i = 0 To msg.DataLength-1
str = str & Hex(msg.Data(i)) & " "
Next
PrintToOutputWindow("Counter: " & msg.EventCount & " ID= " & Hex(msg.ID) & " Data= " & str)
OldCount = msg.EventCount ' Save for the next loop
With send_msg
If Connections.Count > 0 Then _
Set .Connection = Connections(1)
'.BeginUpdate
.ID = &h755
.Data(0) = msg.Data(0)
.Data(1) = msg.Data(1)
.Data(2) = msg.Data(2)
.Data(3) = msg.Data(3)
.Data(4) = msg.Data(4)
.Data(5) = msg.Data(5)
.Data(6) = msg.Data(6)
.Data(7) = msg.Data(7)
.Write 0
End With
End if
str=Null
Next
Wend
End Sub
Best Regards
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
Re: Help creating Macro
Thank you for your help, this is what I needed.
Now I understand how to develop macros.
Now I understand how to develop macros.