Handle diagnostics projects with VBA

<< Click to Display Table of Contents >>

Navigation:  Diagnostics with CanEasy >

Handle diagnostics projects with VBA

 

With the implementation of the BSKD7 in CanEasy also a corresponding COM interface was added, to handle the BSKD7 via VBA or an external software components (C#, VB.Net,...).

 
BSKD7 projects can be managed and executed via the COM interface. Furthermore it is possible to execute commands and macros and read-out buffers (like TInD or TOutD) or return values. The command or macro execution can occur synchronous or asynchronous (event triggered). So diagnostic functions can be realized e.g. through the integrated VBA development environment. The terminal window of the BSKD7 can be suppressed via the COM interface, so the controlling of the whole diagnostics services can be realized with e.g. a VBA application.

 

Diagnostic communication with a control unit via a VBA application.  If the BSK terminal window is not needed, it can be suppressed.

Diagnostic communication with a control unit via a VBA application.
If the BSK terminal window is not needed, it can be suppressed.

 

The interface to the BSKD7 is available via the BSKDApp object. To use this object a reference to the type library "BSKD 1.0 Typbibliothek" (BSKDTerminal.plu) is needed. After the installation of CanEasy the reference is already set.

 

 

 

Usage of the read-out buffers

 

Amongst other things, it is also possible to test the diagnostics communication with BSKD7. The whole diagnostics communication works with the global read-out buffers TIn/TInD and Tout/TOutD. With these buffer around 1kB payload can be assimilated. The following graphic shows the possible lines of communication and the usage of the buffers.

 

BSKD_Schema

 

TIn and TOut consist of the following parts:
 

Length of the telegrams (16 bit, low byte, high byte).

Telegram header

Telegram data (control byte respectively service identifier and corresponding data/parameters)

Checksum

 

The are synonyms für the access to the telegram data (TInD/TOutD), because the header is only used for testing the diagnostics communication, but not for the normal usage of the diagnostics.

 

Hinweis Note:
TInD and TOutD are no real buffers, but something like pointers to the corresponding position in TIn/TOut.

 

Exaple: ID 0xFF on serial BSK diagnostics 7:

 
Request:

Telegram length

ECU address

Length

Control byte

Data

Checksum

05  00

AB

05

49

FF

18

 

Response:

Telegram length

ECU address

Length

Control byte

Data

Checksum

08  00

AB

08

49

12 34 56 78

E2

 

In this case the header consists of two bytes, ecu address and length and TInD[0] and TOutD[0] which are containing the control byte (="KB" or "SI" for "service identifier"; Address of TInD[0] = address of TIn[4]). For the access to the first data byte after the control byte via TIn/TOut instead of TInD/TOutD the symbol TD1Pos can be used, which has the value 5 in this case (address of TInD[1] = address of TIn[TD1Pos]). Transmitted are in this case exact this five bytes: 0xAB, 0x05, 0x49, 0xFF, 0x18

 

 

Example for the usage of the buffers via COM interface

 

These buffers are available via the COM interface. The following VBA example show e.g. how to read data out of buffer TInD after execution of a diagnostics command:

 

Private Sub FirstBSKDMacro()

 

'Define object for BSKD7

Dim oBskd As BSKDApp

'Return value of synchron execution

Dim oBSKDResult As BSKDExecutionResult

'Define variable for buffer content

Dim vDaten as Variant

'Constant for diagnostics timeout
Const cTimeoutDiagAnswer = 1000

 

'Create new diagnostics object

Set oBskd = New BSKDApp

'Execute command synchronous (read five bytes from EEPROM address 123h on)

Set oBSKDResult = oBskd.ExecuteAndWait("kr $123,,5", cTimeoutDiagAnswer)

'read TInD buffer data into variable

vDaten = oBSKDResult.TInD

 

End Sub

 

On synchronous execution the VBA macro is waiting until the BSKD7 command execution has ended or the defined timeout (in milliseconds) is exceeded. Afterwards the data can be read out of the buffers (like done in the example) of are available via the return value BSKDExecutionResult of ExecuteAndWait.

 
The buffer data can also be obtained event-driven. For this the user has register this event with oBSKD.ExecutedEvents = True. If a BSKD7 command or macro is now executed with the method oBSKD.Execute, the VBA macro execution continues directly. The event oBSKD_OnExecuted is raised immediately after the execution of the BSKD7 command or macro has finished. As parameter of the event the buffers are available as BSKDExecutionResult.

 

'Define object for BSKD7 (with events)

Public WithEvents oBskd As BSKDApp

 

'function for asynchronous execution of a diagnostics command

Private Sub SecondBSKDMakro()

 

'Create new diagnostics object

Set oBskd = New BSKDApp

'Execute command asynchronous (read five bytes from EEPROM address 123h on)

oBskd.Execute "kr $123,,5"

 

End Sub

 

'This function is being executed as event after execution of the diagnostics command

Private Sub oBskd_OnExecuted(ByVal arg As CanEasyBSKD.BSKDExecutionResult)

 

    'Define variable for buffer

Dim vDaten as Variant

 

'Read data from buffer
vDaten = arg.TInD

 

End Sub

 

 

Hinweis Note:
Assumption of these examples is a running BSKD7 project.

 

 

VBA events of BSKD7

 

If the asynchronous command execution is used, the following events are available:

OnDiagTransmission (ByVal arg As CanEasyBSKD.BSKDDiagTransmissionResult)
This event is called on every diagnostics request and response.

OnExecuted (ByVal arg As CanEasyBSKD.BSKDExecutionResult)
This event is called if the execution of a diagnostics command or macro is completely fulfilled and the terminal is ready for a new input.

 

Both events can be enabled independent of each other via the following properties:

TransmissionEvents = True

ExecutedEvents = True

 

The named events will also be called (if they are active), if a command was entered directly in the terminal window. The event OnExecuted  contains the property arg.IsOwnCommand which can be used to differ between the events. So it can be decided, if the event happens in case of a own VBA execution or another execution like e.g. the direct execution of a command in the terminal window.

 

Both events have corresponding results as structure in a parameter available (like TInD/TOutD and state of the execution).

 

If both events are set to active, the are called in the following order in case of an execution of a diagnostics service or macro:

 

BSKD_Events