Hi
I am currently receiving some raw data from a bus CAN.
I would like to perform some post processing on those data before posting them with a "Value Indicator".
I assume that I need to use a "virtual varialbe" and a "visual basic Macro" but I did not find the way to do it.
Would you have any example explaining the way to do it.
With regards.
post processing of CAN data
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: post processing of CAN data
Here a simple sample of a VB-Script that use virtual Signals:
We have two real signals based on CAN Data using the ID 0x100.
The Voltage is an unsigend Interger using the first two Data Bytes, and the Ampere, also an unsigned Integer, using the Data Bytes 3 and 4. Inside the VBS Macro we use these two signals to calculate the power, and store the calculated value into a virtual Signal. This virtual Signal could than be used to send again on the CAN Bus, or could be used to show the calculated value inside the User Panel or the Watch Window.
Apply the Symbol file and start this Macro:
We have two real signals based on CAN Data using the ID 0x100.
The Voltage is an unsigend Interger using the first two Data Bytes, and the Ampere, also an unsigned Integer, using the Data Bytes 3 and 4. Inside the VBS Macro we use these two signals to calculate the power, and store the calculated value into a virtual Signal. This virtual Signal could than be used to send again on the CAN Bus, or could be used to show the calculated value inside the User Panel or the Watch Window.
Code: Select all
FormatVersion=5.0 // Do not edit!
Title="power"
{SENDRECEIVE}
[Symbol]
ID=100h
DLC=8
Var=Voltage unsigned 0,16 /u:Volt /max:10000
Var=Current unsigned 16,16 /u:Ampere /max:500
Code: Select all
Sub CalculatePower()
Dim voltage, current, power
Set voltage = Signals("Voltage")
Set current = Signals("Current")
Set power = Signals("Power")
If power Is Nothing Then
' Signal not found, create and initialize new one
Set power = Signals.Add("Power")
power.DataType = peDataTypeFloat
End If
While True
power.Value = voltage.Value * current.Value
Wait(10) ' Prevent 100% CPU load
Wend
End Sub
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------