hartdll 7borst-automation.com › manuals › ba-hart-dll-7.4.1.pdf · harttools hartdll 7.4.1 /...

62
HartTools HartDLL 7.4 Software Documentation Revision: 7.4.1 Date: 14.02.2014 Real Time WINAPI Software Solutions for the Hart Instrument Development and Automation with Windows Borst Automation Neue Reihe 33 DE-27474 Cuxhaven GERMANY Fon: +49 (0)4741 6985100 Fax: +49 (0)6432 6985102 http://borst-automation.com [email protected] Copyright © 1998-2014 Borst Automation, Walter Borst, Cuxhaven, GERMANY Hart ® is a registered trademark of the Hart Communication Foundation Windows ® is a registered trademark of Microsoft Corporation

Upload: others

Post on 28-Jun-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4

Software Documentation

Revision: 7.4.1

Date: 14.02.2014

Real Time

WINAPI Software Solutions for the

Hart Instrument Development

and Automation with Windows

Borst Automation

Neue Reihe 33

DE-27474 Cuxhaven

GERMANY

Fon: +49 (0)4741 6985100

Fax: +49 (0)6432 6985102

http://borst-automation.com

[email protected]

Copyright© 1998-2014 Borst Automation, Walter Borst, Cuxhaven, GERMANY

Hart® is a registered trademark of the Hart Communication Foundation

Windows® is a registered trademark of Microsoft Corporation

Page 2: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Contents ���� i

Contents

Overview.................................................................................. 2

Getting Started ................................................................................ 2

64 Bit Platforms .......................................................................... 2

32 Bit Platforms .......................................................................... 2

Distribution of Applications.............................................................. 3

Typical Service Processing Program Flow ........................................ 3

Architecture ..................................................................................... 6

Functions Overview ......................................................................... 7

Examples Overview .......................................................................... 8

Directory Structure .......................................................................... 9

Examples ............................................................................... 10

C/C++ ........................................................................................... 10

BaHartDrvCpp .......................................................................... 10

C# .................................................................................................. 11

RdWrRangeAndTag (Worker Thread) ........................................... 11

ConnectAndRead ....................................................................... 13

GetCyclicData ........................................................................... 13

GetUnIDbyTag .......................................................................... 16

RunAsSlave .............................................................................. 17

Visual Basic .............................................................................. 21

SendExtCommand ..................................................................... 21

Microsoft Office .............................................................................. 21

UsingExcel ............................................................................... 21

Functional Description ........................................................... 22

Functions ....................................................................................... 22

Operation ................................................................................. 22

Master Services ........................................................................ 25

Encoding .................................................................................. 32

Decoding ................................................................................. 38

Slave Emulation ........................................................................ 41

Receiving Cyclic Data ................................................................ 45

Structures ...................................................................................... 48

Master Services ........................................................................ 48

Slave Emulation ........................................................................ 51

Cyclic Data ............................................................................... 52

Constants ....................................................................................... 53

Hart at a Glance ..................................................................... 54

Frame Coding ................................................................................. 54

Commonly Used Commands ........................................................... 55

Response Codes ............................................................................. 60

Appendix ................................................................................ 61

Abbreviations ................................................................................. 61

Page 3: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Overview����2

Overview

The Hart Driver DLL is implementing the Hart communication

protocol by resolving the real time requirements.

The DLL is not (!) using any framework like MFC. It does not

use the Windows Registry and is not depending on any other

DLL except the standard Windows system DLLs. The DLL itself is

using standard Windows API calls and is therefore compatible to

all Versions of Windows with the 32 bit and 64 bit API.

The implementation of the Hart Protocol does not contain any

restriction to frame lengths like in Hart 5.x (e.g.). Therefore the

all communication functions can be used for devices supporting

Hart 5, Hart 6 or Hart 7.

Before using the communication the application software has to

register for a com port of the PC. This can be any com port from

1 to 255 including virtual com ports as they are used for USB

like the hart modems of MACTek® or Microflex.

Getting Started

Install the package into a directory of your choice. Open one of

the solutions provided in the example paths.

Note: The projects were generated with Visual Studio 2010.

Trying the examples with an earlier Version of Visual Studio will

not work.

It is recommended to provide a copy of BaHartDrv74.dll on the

windows system path to allow the access of the DLL from any

directory and to allow the execution of software compiled for

any cpu.

64 Bit Platforms

The 64 Bit DLLs located in x64 should be copied to the Windows

system path for 64 bit DLLs (e.g. C:\Windows\System32). For

compatibility reasons the path is still named System32 even it

contains exclusively 64 bit DLLs.

The 32 Bit DLLs located in x86 should be copied to the 'Windows

over Windows 64' path (e.g. C:\Windows\SysWOW64).

32 Bit Platforms

On 32 bit platforms only the 32 bit DLL from x86 should be

copied to the Windows system path (e.g.

C:\Windows\System32).

Page 4: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Overview����3

Distribution of Applications

The only thing you have to provide with your application is a

copy of the DLL (BaHartDrv74.dll). The best way is to provide a

copy of the 32 bit DLL (x86) as well as a copy of the 64 bit DLL

(x64). The files should be copied to the Windows system paths

for 32 and 64 bit DLLs.

Note: Be sure that the first call of your application is a call of

the validation function of the DLL (BHDrv_ValidateLicense)

passing a valid license code and the correct user name to the

DLL.

Typical Service Processing Program Flow

Figure 1: Polling for Service Completion

BHDrv_OpenChannel Register at a com port

BHDrv_ConnectByAddr Get the unique identifier of the device

BHDrv_DoCommand

BHDrv_IsServiceCompleted

BHDrv_FetchConfirmation

Poll for service completion

Get the resulting data

Send next command

BHDrv_CloseChannel

Page 5: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Overview����4

Because command 0 is the only command in Hart which is working with the short address

(0..15/0..63) the unique identifier has to be fetched from the device to use it for the other

commands. The unique identifier can be read by the commands 0, 11 and 21.

There are three ways to wait for the completion of a service. Picture 1 is showing the no wait

mode. In the no wait mode the client program has to poll the DLL by calling

BHDrv_IsServiceCompleted.

Figure 2: Using the Wait Mode of the DLL

When a service is processed using the function

BHDrv_DoCommand with the option flag DRV_WAIT the

program is returning when the service is totally completed even

if there are errors or if the device is not responding.

Waiting for a service results in a small delay of approximately

250 ms.

Note: If a device is not responding, the function delay for a

multiple of the number of retries which had been configured by

the function BHDrv_SetConfiguration.

BHDrv_OpenChannel Register at a com port

BHDrv_ConnectByAddr Get the unique identifier of the device

BHDrv_DoCommand

BHDrv_FetchConfirmation Get the resulting data

Send next command

BHDrv_CloseChannel

Page 6: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Overview����5

The third method is to register a callback function from the

application software. In this case the DLL will call back as soon

as any service of that application is completed.

Figure 3: Using the a Callback Function for the DLL

The time between the call of the callback function and the

execution of the invoked function is not determined because it is

given by the Windows messaging system. But usually this time

is short if the application is not busy in another event

procedure.

BHDrv_OpenChannel Register at a com port

BHDrv_ConnectByAddr Get the unique identifier of the device

BHDrv_DoCommand

BHDrv_FetchConfirmation Get the resulting data Send next command

BHDrv_CloseChannel

BHDrv_RegisterEventCallback Register a callback function

UserServiceCallback (BeginInvoke)

UserServiceCallback (Invoked)

UserServiceCallback (BeginInvoke)

UserServiceCallback (Invoked)

Close the channel at the end of the session

BHDrv_FetchConnection Get the unique ID

Page 7: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Overview����6

Architecture

Figure 4: The Internal Structure of the DLL

The figure above shows that the DLL is using is using its own

thread for the real time application. Thus the calling thread may

be of any kind. Even if the DLL is waiting for the completion of

the service it is taking the calling thread into sleep mode.

Figure 5: The DLL can be used by different Threads

The DLL may be called from several threads. The functions and

communication services are thread safe. Each thread should

register explicitly to get its own handle.

User Application

DLL Interface Functions

Service Handler

Hart Protocol Thread

PC Com Port

Done?

Start Service

No

Yes

Sleep 10 ms

Real time

functionality

HART MODEM

BaHartDrv74.dll

BaHartDrv74.dll(1)

User Application

Thread 1 Thread 2 Thread 3

BaHartDrv74.dll(2)

BaHartDrv74.dll(3)

Page 8: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Overview����7

Functions Overview

Name Description

Operation

BHDrv_ValidateLicense The first call into the DLL should be a call to this function passing the correct license key and the user name to the software. The user name and the licensee code is provided by the User License Certificate.

BHDrv_OpenChannel The function allocates the selected com port if possible and starts its own working thread for accessing Hart services. The value which is returned is a handle which has to be passed to all functions which are requesting a service.

BHDrv_CloseChannel It is required to call this function at least when the application is terminating.

BHDrv_GetConfiguration The function copies the configuration data to a data structure provided by the caller.

BHDrv_SetConfiguration The function is setting all details required for the configuration. The data is passed in a structure provided by the caller.

BHDrv_GetRunTimeInfo Return some information about the communication channel (e.g. if the use of a FIFO at the UART was detected.

BHDrv_RegisterEventCallback Register a function which is called when any requested service is completed. The service handle of the service is passed to the called CB function.

BHDrv_ClearEventCallback Deletes a previously registered callback.

Coding

Pick/PutIntX Gets or sets the value of an integer of 8, 16, 24 or 32 bit size. The coding is supporting MSB_FIRST(standard) or LSB_FIRST.

Pick/PutFloat Gets or sets a single precision floating point number. The coding is supporting MSB_FIRST(standard) or LSB_FIRST.

Pick/PutDouble Gets or sets a single precision floating point number. The coding is supporting MSB_FIRST(standard) or LSB_FIRST.

Pick/PutPackedASCII The packed ASCII Format uses 6 Bit to encode a character. Therefore 4 characters in the original string require 3 octets in the resulting data. It is recommended to provide strings always as a multiple ordinal of 4 characters.

Pick/PutString Gets or sets a stream of characters.

Pick/PutOctets Gets or sets a stream of octets (bytes).

Master Services

BHDrv_ConnectByAddr Use command 0 with short address to get the connection information.

BHDrv_ConnectByUniqueID Use command 0 with long address to get the connection information.

BHDrv_ConnectByShortTag Use command 11 with broad cast address and the short tag name to get the connection information.

BHDrv_ConnectByLongTag Use command 21 with broad cast address and the long tag name to get the connection information.

BHDrv_FetchConnection Fills a structure provided by the caller with the connection information.

BHDrv_IsSendClear The function returns B_TRUE, if no more service is pending.

BHDrv_SendAnyData Send any octet stream via the connected com port.

BHDrv_DoCommand Send a command in the range 0..255.

BHDrv_DoExtCmd Send a command in the range 0..65535.

BHDrv_DoBurstCommand Send a burst command (cyclic service) in the range of 0..255.

BHDrv_IsServiceCompleted Returns B_TRUE if the service was completed.

BHDrv_FetchConfirmation Fills a structure provided by the caller with the service results information such as the response codes and the response data (if any).

Table 1: General and Master Services

Page 9: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Overview����8

Name Description

Cyclic Data Services

BHDrv_CycSrvStart The function is enabling the reception of incoming burst messages.

BHDrv_CycSrvStop After the call of this function the reception of burst messages is halted. Messages already in the queue may be read by BHDrv_CycSrvGetData.

BHDrv_CycSrvGetData Read cyclic data from the queue in the HartDLL.

BHDrv_CycSrvRegisterCB For asynchronous reading of cyclic data a callback function may be registered at the DLL.

BHDrv_CycSrvUnregister After this function was called no more callbacks will be done.

Slave Services

BHDrv_Slave_SetDLL Sets the name of the DLL which should be used as slave simulation. Developers which licensed the Hart Slave source code could run their own slave simulation at the HartDLL interface.

BHDrv_Slave_Start In this function the slave DLL is loaded and the simulation(emulation) is started.

BHDrv_Slave_Terminate Stops the slave emulation and unloads the slave library.

BHDrv_Slave_IsActive Returns T_TRUE if the slave is running.

BHDrv_Slave_GetParameter Reads a parameter from the slave database.

BHDrv_Slave_SetParameter Writes a parameter in the slave database.

BHDrv_Slave_GetConfig Gets the communication configuration of the slave emulation.

BHDrv_Slave_SetConfig Sets the communication configuration of the slave emulation.

Table 2: Cyclic Data and Slave Interface Functions

Examples Overview

Example Subject Description

C/C++

BaHartDrvCpp BaHartDrv74.h A little console application interfacing to the DLL.

C#

RdWrRangeAndTag Coding Read/Write

The example is demonstrating two features of the driver DLL. The first is thread safety the second is the way how to encode and decode data.

ConnectAndRead Connection Device Info

The Example demonstrates the usage of the connection information and the BHDrv_IsServiceCompleted method.

GetCyclicData Cyclic Data Callback

The example is showing how cyclic data is collected from the HartDLL.

GetUnIDbyTag Data Link Service

The example demonstrates the usage of the function BHDrv_ConnectByTagName of the HartDLL.

RunAsSlave Slave Emulation

Demonstrates the usage of the slave emulation interface on the HartDLL side.

SendExt Command Hart 7 Service Callback

Sends a command in the range 0..65535 and demonstrates the use of the service callback for service completion.

Visual Basic

VbRdWrRangeAndTag VB Language Sets the name of the DLL which should be used as slave simulation. Developers which licensed the Hart Slave source code could run their own slave simulation at the HartDLL interface.

Microsoft Office

UsingExcel VBA Macros Excel can be used to collect data from a Hart Network.

.NET 4.0

UsingHartX .NET Object

Demonstrates how to use Hart as a .NET object. HartX was used a lot of times with e.g. LabView.

Table 3: Examples for the HartDLL and HartX

Page 10: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Overview����9

Directory Structure

After installing the Borst Automation Package the following

directory structure was generated in the application path.

Figure 6: Directory Structure after Setup

To allow debugging in 32 bit as well as in 64 bit a Dual(Triple)

Development Set is provided, which is seen in the directory

structure above.

User’s Path

Hart Tools 7.4

CommonC

x64

Cpp

HartDLL

C#

Visual Basic

All 64 Bit DLLs and

Executables go here

Interfaces to the DLL

GetCyclicData

ConnectAndRead

RdWrRangeAndTag

RunAsSlave

GetUniqueIDbyTag

HartX

C#

Visual Basic

x86

CommonC#

CommonVb

Documentation

Examples

All 32 Bit DLLs and

Executables go here

Release applications built for any cpu go here

xAnyCPU Debug examples

compiled for any cpu go

here

Page 11: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����10

Examples

There are several examples provided to demonstrate the access

of the DLL in C/C++, C#, Visual Basic and VBA1.

All examples have a similar functionality. Firstly a com port is

opened and a connection is established. Then some Hart data is

accessed.

C/C++

BaHartDrvCpp

The solution is placed in the paths

.\Examples\HartDLL\Cpp\UsingBaHartDrv.sln

The example is a little console application written in straight C.

The interface is defined in BaHartDrv74.h.

The first call of the DLL is used for setting the license key.

/* Set the License in the DLL */ BHDrv_ValidateLicense( "30-Days-Trial-User-License" , "ZUEjdhuI-tz45-klER-fgTT-JkHfuIzEwr7u" );

Code Snippet 1: Calling ValidateLicense

The user name and license code here has to be replaced by your

user name and the license code which is provided to you by the

user license certificate after purchasing the full version.

1 VBA = Visual Basic for Applications (used in Excel)

Page 12: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����11

C#

RdWrRangeAndTag (Worker Thread)

The solution is placed in the paths

.\Examples\HartDLL\C#\RdWrRangeAndTag\CsRdWrRangeAn dTag.sln

The example is based on a dialog form.

The interface to HartDrv74 is declared in the module

BaHartDrv74_Iface.cs which located in the directory

CommonC#.

The example is demonstrating two features of the driver DLL.

The first is thread safety the second is the way how to encode

and decode data.

The first call into the DLL is implemented in the constructor of

the class CCom, which is implemented in the module

Communication.cs.

HartDLL.BHDrv_ValidateLicense( new StringBuilder( "30-Days-Trial-User-License" ), new StringBuilder( "ZUEjdhuI-tz45-klER-fgTT-JkHfuIzEwr7u" ));

Code Snippet 2: Calling ValidateLicense

The StringBuilder class, which is used here, is referenced in the

namespace System.Text.

The thread safety of the DLL is demonstrated by providing a

separate thread for each service thus running more than one

thread at a time requesting Hart services.

It has to be taken into account that for the connection of the

worker threads and the application, which is a Windows form,

the method BeginInvoke() is used.

Page 13: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����12

Let’s have a look to the code for reading cyclically refreshed

variables (cyclic data). This is started either in the Click event of

the button butReadPVs or the RunWorkerCompleted event of

the worker thread wrkReadPVs. Both events are calling the

method RunWorkerAsync of this worker thread. The event

DoWork of the said thread is calling the method

ReadPVsInWrkThread of the CCom class.

The thread is performing two Hart services for reading the

current the percentage value and the primary variable.

public void ReadPVsInWrkThread( frmMain frm) { float fCurrent = 0.0f; float fPercent = 0.0f; float fPv1 = 0.0f; if (HandleCommand(2, m_abyData, 0, 8)) { fCurrent = HartDLL .BHDrv_PickFloat(0, ref m_strConfirmation.aby_Data[0], HartDLL .MSB_FIRST); fPercent = HartDLL .BHDrv_PickFloat(4, ref m_strConfirmation.aby_Data[0], HartDLL .MSB_FIRST); } if (HandleCommand(1, m_abyData, 0, 5)) { fPv1 = HartDLL .BHDrv_PickFloat(1, ref m_strConfirmation.aby_Data[0], HartDLL .MSB_FIRST); } delPVsResult dPVsResult = new delPVsResult (frm.GetPVsResult); frm.BeginInvoke(dPVsResult, new Object [] {fCurrent, fPercent, fPv1}); }

Code Snippet 3: Reading the Dynamic Values

Because a thread must not access the controls of the main form

a function provided by the parent (main form) is invoked. It is

important to recognize that BeginInvoke is used. The reason is,

that the BeginInvoke method is using the PostMessage function

of Windows, thus not blocking the calling thread.

public void GetPVsResult( float fCurrent, float fPercent, float fPv1) { txtCurrent.Text = fCurrent.ToString( "0.0###" ); txtPercent.Text = fPercent.ToString( "0.0###" ); txtPV1.Text = fPv1.ToString( "0.0###" ); HandleLastError(); if (!chkCyclic.Checked) { butReadPVs.Enabled = true ; } }

Code Snippet 4: Displaying the Dynamic Values

Page 14: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����13

ConnectAndRead

The Example demonstrates the usage of the connection

information and the BHDrv_IsServiceCompleted method.

The solution is located in the following path.

.\Examples\HartDLL\C#\ConnectAndRead\ConnectAndRead .sln

GetCyclicData

The solution is stored in the subdirectory:

.\Examples\HartDLL\C#\GetCyclicData\CsGetCyclicData .sln

It is a new feature of HartDLL 7.4 to allow receiving burst

messages from the Hart protocol. There are two ways to get the

messages. One is to call the function BHDrv_CycSrvGetData to

read eventual received burst frames. The other way is to

register a call back which is called when a burst message

arrived. As most programmers should be pretty much familiar

with the polling method, the callback is not very common at

least by C# users. Therefore a more detailed description is

given in this section.

Page 15: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����14

The callback function for fetching burst data of a device is

implemented in the class CCom in the module

Communication.cs.

private delegate void delDisplayCyclicData ( HartDLL . T_strCyclicData strCyclicData); private void SubscribeCyclicData( ref HartDLL . T_strCyclicData rstrCyclicData) { m_strCyclicData = rstrCyclicData; try { m_frmParent.BeginInvoke( new delDisplayCyclicData (DisplayCyclicData), new Object [] {m_strCyclicData}); } catch { } }

Code Snippet 5: The Callback Function and the Invocation Delegate

The called function takes a local copy of the data and invokes a

function which is accessing the controls of the client form. The

function which is invoked is DisplayCyclicData.

This function displays the data carried within the structure

strCyclicData.

private void DisplayCyclicData( HartDLL . T_strCyclicData strCyclicData) { string [] s; ListViewItem Item = m_lstCyclicData.Items.Add(m_lstCyclicData.Ite ms.Count.ToString( "0" )); Item.SubItems.Add(strCyclicData.ulTimeStamp.ToStr ing( "0" )); Item.SubItems.Add(strCyclicData.byCmd.ToString( "0" )); Item.SubItems.Add(strCyclicData.byRsp1.ToString( "0" )); Item.SubItems.Add( CHelpers .GetBin(strCyclicData.byRsp2)); if (strCyclicData.byDataLen > 0) { s = CHelpers .simpleHexDump(strCyclicData.aby_Data, m_strCyclicData.byDa taLen,200); } else { s = new string [1] { "No Data" }; } Item.SubItems.Add(s[0]); Item.EnsureVisible();

}

Code Snippet 6: Displaying the Burst Data in a ListView Control

The delegate for passing the callback to the HartDLL is declared

in the private data region of CCom (Communication.cs).

HartDLL . delSubscribeCyclicData m_dlCallback;

Code Snippet 7: Declaration of the Delegate for the Callback

Page 16: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����15

In the constructor of CCom the function is inserted into the

delegate object.

public CCom(fr mMain frm, ListView lst) { //Insert arrays into structures m_strConnection.abyUniqueID = new byte [5]; m_strConfirmation.aby_Data = new byte [64]; m_strCyclicData.aby_Data = new byte [64]; m_dlCallback = new HartDLL . delSubscribeCyclicData (SubscribeCyclicData); m_lstCyclicData = lst; m_frmParent = frm; }

Code Snippet 8: Constructor of the CCom Class

Finally the callback is registered at the HartDLL in the method

RegisterCallback of the CCom class.

public void RegisterCallback() { if (m_hDrv != HartDLL .INVALID_DRV_HANDLE) { HartDLL .BHDrv_CycSrvRegisterCB(m_hDrv, m_dlCallback); } }

Code Snippet 9: Registering the Callback at the HartDLL

Precautions

If structures are used which are containing one or more arrays

these arrays must be instantiated before accessing them (see

Code Snippet 8).

For not blocking the thread which is performing the callback use

BeginInvoke for the call of the function in the parent

environment (see Code Snippet 5).

Page 17: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����16

GetUnIDbyTag

The solution of this example is stored at the following places.

. \ Examples \ HartDLL \ C#\ GetUnIDbyTag \ GetUnIDbyTag.sln

The example demonstrates the usage of the function

BHDrv_ConnectByTagName of the HartDLL.

private void butConnect_Click( object sender, System. EventArgs e) { StringBuilder sb = new StringBuilder ( " " ); butConnect.Enabled = false ; butEnd.Enabled = false ; txtResult.Text = "Trying to connect..." ; if (m_hChannel != HartDLL .INVALID_DRV_HANDLE) { this .Refresh(); txtUnId0.Text = "" ; txtUnId1.Text = "" ; txtUnId2.Text = "" ; txtUnId3.Text = "" ; txtUnId4.Text = "" ; HartDLL .BHDrv_GetConfiguration(m_hChannel, ref m_strConfiguration); sb.Insert(0, txtTagName.Text); HartDLL .BHDrv_PutPackedASCII(sb, 8, 0, ref this .abyData[0]); m_hService = HartDLL .BHDrv_ConnectByTagName( m_hChannel, ref this .abyData[0], HartDLL .DRV_WAIT, 2); HartDLL .BHDrv_FetchConnection(m_hService, ref m_strConnection); if ( m_strConnection.byError == HartDLL .SRV_SUCCESSFUL ) { txtResult.Text = "Connected!" ; txtUnId0.Text = "0x" + m_strConnection.abyUniqueID[0].ToString( "X02" ); txtUnId1.Text = "0x" + m_strConnection.abyUniqueID[1].ToString( "X02" ); txtUnId2.Text = "0x" + m_strConnection.abyUniqueID[2].ToString( "X02" ); txtUnId3.Text = "0x" + m_strConnection.abyUniqueID[3].ToString( "X02" ); txtUnId4.Text = "0x" + m_strConnection.abyUniqueID[4].ToString( "X02" ); } else { txtResult.Text = "Connection failed!" ; } } else { txtResult.Text = "Invalid com port?" ; } butConnect.Enabled = true ; butEnd.Enabled = true ; }

Code Snippet 10: Connecting by Tag Name

Page 18: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����17

RunAsSlave

The example can be found in the paths:

. \ Examples \ HartDLL \ C#\ RunAsSlave \ RunHartSlave.sln

The example is demonstrating that an application can be used

(together with the HartDLL) to run a slave simulation which is

also a DLL, loaded by the HartDLL framework.

If you are using a virtual pair of com ports you can conduct this

session on one computer. Otherwise you need two machines or

two cross-connected com ports.

Running the Hart Slave

1. Open RunHartSlave.sln with Visual Studio 2010, build the

solution and start debugging.

2. Select a com port. If the com port could be opened its state

is reported as 'Com Port O.K.'.

3. Check 'Slave Activated'. Now you see a simulated measured

value counting up and down.

Usually the greyed textboxes are showing the values from the

slave. However, if one of the edit checks is clicked you can

modify a value in the slave.

Page 19: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����18

Running the Hart Master

1. Open ConnectAndRead.sln with Visual Studio 2010, build the

solution and start debugging.

2. Select the other com port. If the com port could be opened

the state will be reported as 'COM O.K.'.

3. Click the button 'Connect' to force the application to send

command 0 for getting the unique identifier of the Hart Slave.

4. Check 'Cyclic Read PVs'. Now the simulated measured value

will be read by the master as fast as possible (which is slower

than the local update of the slave because of the delay

introduced by the Hart communication).

A Closer Look to the Hart Slave

1. Close the Master application (Example for the Hart DLL).

2. Start FrameAlyst.

3. Select the other com port.

4. Be sure the Slave is not checked and master is checked.

Page 20: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����19

5. Send command 0 using the commands tab of FrameAlyst.

6. Send command 13 to read tag, descriptor and date.

7. Check decoded data in the start tab.

8. Click 'Edit User Cmd' in the commands tab and enter a

specification for command 17 as it follows.

9. Send command 17.

Page 21: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����20

If you look at the form of the Hart Slave simulation you will see

that the FloatVar parameter is set to the requested value.

10. Modify command 17.

The IntegerVar parameter is now set to 1111.

This example is also showing how the universal message

parameter of Hart can be used to modify any data in the Hart

device.

Page 22: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Examples����21

Visual Basic

There is one Visual Basic example available in the following

paths.

. \ Examples \ HartDLL \ Visual Basic \ RdWrRangeAndTag\ VbRdWrRangeAndTag.sln

The example in Visual Basic is exactly the same as for C#. For

functional details please refer to the C# example

RdWrRangeAndTag.

The interface is declared in the module BaHartDrv74_Iface.vb.

For using the StringBuilder object in the following statement

HartDLL .BHDrv_ValidateLicense( New StringBuilder ( " 30- Days- Trial - User - License " ), New StringBuilder ( " ZUEjdhuI-tz45-klER-fgTT-JkHfuIzEwr7u " ))

it is required to import the namespace System.Text.

Imports System.Text

SendExtCommand

The documentation will be available in the next revision.

Microsoft Office

UsingExcel

The documentation will be available in the next revision.

Page 23: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����22

Functional Description

Functions

All functions of the DLL are thread safe. The interface for the

functions calls is the same as the WINAPI functions. Thus the

DLL may be used by all applications which support calls to the

WINAPI functions.

Operation

ValidateLicense

void BHDrv_ValidateLicense( const char * pcUserName, const char * pcLicenseCode);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

pcUserName In Pointer to a text containing a valid user name.

pcLicenseCode In Pointer to a text containing a val id license code.

Usage

BHDrv_ValidateLicense( " 30- Days- Trial - User - License " , " ZUEjdhuI - tz45 - klER - fgTT - JkHfuIzEwr7u " );

The first call into the DLL should be a call to this function

passing the correct license key and the user name to the

software. The user name and the licensee code is provided by

the User License Certificate.

OpenChannel

unsigned int BHDrv_OpenChannel( unsigned short usComPort);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

usComPort In Number of the PC com port (1..255)

Returns

INVALID_DRV_HANDLE: Com port could not be registere d Any other value: Registration successful

Usage

m_hDrv = HartDLL .BHDrv_OpenChannel( Convert .ToUInt16(m_iComPort));

The function allocates the selected com port if possible and

starts its own working thread for accessing Hart services. The

value which is returned is a handle which has to be passed to all

functions which are requesting a service.

Page 24: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����23

CloseChannel

void BHDrv_CloseChannel( unsigned int hDrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

Usage

HartDLL .BHDrv_CloseChannel(m_hDrv);

It is required to call this function at least when the application is

terminating.

GetConfiguration

void BHDrv_GetConfiguration( unsigned int hDrv, T_strConfiguration * pstrConfiguration);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

pstrConfiguration Out The function copies the configuration to the st ructure pointed to.

Usage

BHDrv_GetConfiguration(hDrv, &strConfiguration);

SetConfiguration

void BHDrv_SetConfiguration( unsigned int hDrv, T_strConfiguration * pstrConfiguration);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

pstrConfiguration In The function uses the value of the given structu re to configure the driver. In case of a parameter error the function defaults to the minimum respectively maximum value of the parameter .

Usage

strConfiguration.ucInitialMasterRole = 1; BHDrv_SetConfiguration(hDrv, &strConfiguration);

If the function is not called after loading the DLL the driver is

using the default values.

Page 25: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����24

GetRunTimeInfo

void BHDrv_GetRunTimeInfo( unsigned int hDrv, T_strRunTimeInfo * pstrRunTimeInfo);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

pstrRunTimeInfo In See documentation of the structure.

Usage

HartDLL .BHDrv_GetRunTimeInfo( CTestClient .hChannel, ref CTestClient .strRunTimeInfo); if ( CTestClient .strRunTimeInfo.byActualMaster == 1 ) { return true ; } return false ;

Return some information about the communication channel

(e.g. if the use of a FIFO at the UART was detected.

RegisterEventCallback

void BHDrv_RegisterEventCallback ( unsigned int hDrv, void ( __stdcall * HandleServiceEvent)( unsigned int hDrv, unsigned short usEvent, unsigned int hService, unsigned int uiData);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

HandleServiceEvent In Pointer to the callback function

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

usEvent In NONE, CONFIRMATION, BURST_INDICATION

hService In Service handle

uiData In Not yet defined

Usage

HartDLL .BHDrv_RegisterEventCallback( CTestClient .hChannel, pfnc_ServiceHandler);

The function is used to pass a function pointer for a service

completion callback to the HartDLL.

Among others the callback function accepts hDrv as one

parameter thus allowing the application to support more than

one channel at a time.

Page 26: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����25

ClearEventCallback

void BHDrv_RegisterEventCallback( unsigned int hDrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

After a call of this function no more callbacks to

HandleServiceEvent will occur.

Master Services

Connect by Address

unsigned int BHDrv_ConnectByAddr( unsigned int hDrv, unsigned char ucAddr, unsigned char ucQOS, unsigned char ucNumRetries);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

ucAddr In Hart device address (0..63)

ucQOS In Quality of service

DRV_WAIT Return if the service is completed

DRV_NO_WAIT Return immediately, user will poll for completion

ucNumRetries In Number of retries to repeat the service in case of a communication error respectively missing response

Returns

INVALID_SRV_HANDLE: No resource available, service could not be started Any other value: Service handle which is used to ac cess the service results

Usage

m_hService = HartDLL .BHDrv_ConnectByAddr(m_hDrv, m_byAddress, HartDLL .DRV_WAIT, 2);

The service is using the short address to perform Hart command

0 to get the unique identifier.

Page 27: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����26

Connect by Unique ID

unsigned int BHDrv_ConnectByUniqueID( unsigned int hDrv, unsigned char * pucUniqueID, unsigned char ucQOS, unsigned char ucNumRetries);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

pucUniqueID In Pointer to a five octet array with the unique id entifier

ucQOS In Quality of service

DRV_WAIT Return if the service is completed

DRV_NO_WAIT Return immediately, user will poll for completion

ucNumRetries In Number of retries to repeat the service in case of a communication error respectively missing response

Returns

INVALID_SRV_HANDLE: No resource available, service could not be started Any other value: Service handle which is used to ac cess the service results

The function is using the unique identifier. It can be used on a

multidrop network even if all devices have the same short

address. However using this function makes only sense if the

unique identifier of each device is known.

Connect by Short Tag

unsigned int BHDrv_ConnectByShortTag( unsigned int hDrv, unsigned char * pucTagName, unsigned char ucQOS, unsigned char ucNumRetries);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

pucTagName In Pointer to the octet array of a length of 6 pack ed ASCII bytes

ucQOS In Quality of service

DRV_WAIT Return if the service is completed

DRV_NO_WAIT Return immediately, user will poll for completion

ucNumRetries In Number of retries to repeat the service in case of a communication error respectively a missing response

Returns

INVALID_SRV_HANDLE: No resource available, service could not be started Any other value: Service handle which is used to ac cess the service results

Usage

StringBuilder sb = new StringBuilder ( " " ); sb.Insert(0, txtTagName.Text); BaHartDrv74. HartDLL .BHDrv_PutPackedASCII(sb, 8, 0, ref this .abyData[0]); m_hService = BaHartDrv74. HartDLL .BHDrv_ConnectByTagName( m_hChann el, ref this .abyData[0], BaHartDrv74. HartDLL .DRV_WAIT, 2 );

The function uses the short tag name of the device and Hart

command 11 to retrieve the unique identifier. Typically this

function is used in multidrop networks.

Page 28: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����27

Connect by Long Tag

unsigned int BHDrv_ConnectByShortTag( unsigned int hDrv, unsigned char * pucTagName, unsigned char ucQOS, unsigned char ucNumRetries);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

pucTagName In Pointer to the 32 byte ISO Latin 1 string with t he long tag name

ucQOS In Quality of service

DRV_WAIT Return if the service is completed

DRV_NO_WAIT Return immediately, user will poll for completion

ucNumRetries In Number of retries to repeat the service in case of a communication error respectively missing response

Returns

INVALID_SRV_HANDLE: No resource available, service could not be started Any other value: Service handle which is used to ac cess the service results

Usage

StringBuilder sb = new StringBuilder (32); sb.Insert(0, CSettings .TagNameLong); FillWithZero(sb, 32); BaHartDrv74. HartDLL .BHDrv_PutString(sb, 32, 0, ref abyData[0]); hServiceConnect = BaHartDrv74. HartDLL .BHDrv_ConnectByLongTag( hCha nnel, ref abyData[0], BaHartDrv74. HartDLL .DRV_NO_WAIT, CSettings .NumRetries);

The function uses the long tag name of the device and Hart

command 21 to retrieve the unique identifier. Typically this

function is used in multidrop networks.

FetchConnection

void BHDrv_FetchConnection( unsigned int hDrv, T_strConnection * pstrConnection);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hSrv In The service handle which was returned by the ser vice request for connecting to a device

pstrConnection Out The function assigns the connection details (de vice information) to the structure pointed to. In case o f a communication error only the error variable is set (see service completion codes).

Usage

HartDLL .BHDrv_FetchConnection(m_hService, ref m_strConnection); if (m_strConnection.byError != HartDLL .SRV_SUCCESSFUL) { m_iLastError = ERR_CONNECTION_FAILED; } else { m_iComPortStatus = COM_CONNECTED; }

Note: After a call of this function the driver is deleting the

service. hService is no longer valid after calling FetchConnection

once.

Page 29: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����28

Is Send Clear

unsigned char BHDrv_IsSendClear( unsigned int hDrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

Returns

T_FALSE: some service still pending or ongoing data link layer activity (waiting for something) in progress T_TRUE: no service pending

The function is checking if the protocol activities would allow to

send any frame.

Note: It is not necessary to call IsSendClear before requesting a

service. The HartDLL accepts the request of 1000 services at a

time. The function is mainly used by FrameAlyst for some

special situations.

Send any Data

unsigned int BHDrv_SendAnyData( unsigned int hDrv, unsigned char * pucData unsigned char ucLen);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

pucData In Pointer to s tream of octets (bytes)

ucLen In Number of bytes to be send

Returns

INVALID_SRV_HANDLE No resource available, service could not be started

Any other value Service handle which is used to access the service results

Usage

if ( HartDLL .BHDrv_IsSendClear( CTestClient .hChannel) != 0) { CTestClient .hServiceDoCmd = HartDLL .BHDrv_SendAnyData( CTestClient .hChannel, ref CTestClient .abyData[0], byLen); }

The function is provided for debugging purposes allowing to

send any stream of data through the serial interface.

Note: It is very important to acknowledge this service by calling

the function FetchConfirmation after completion. Only with this

call the service handle is deleted.

Page 30: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����29

Do Command

unsigned int BHDrv_DoCommand( unsigned int hDrv, unsigned char ucCommand, unsigned char ucQOS, unsigned char * pucReqData, unsigned char ucReqDataLen, unsigned long dwAppKey, unsigned char * pucUniqueID );

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

ucCommand In Hart command ( 0..255 ) to be sent with the request

ucQOS In Quality of service

DRV_WAIT Return if the service is completed

DRV_NO_WAIT Return immediately, user will poll for completion

pucReqData In Request data: octet stream to be sent with the c ommand

ucReqDataLen In Length of the request data stream (number of oct ets/bytes)

dwAppKey In Any value. The value which the user is setting h ere is returned by the confirmation as is.

pucUniqueID In Unique identifier of the addressed device

Returns

INVALID_SRV_HANDLE No resource available, service could not be started

Any other value Service handle which is used to access the service results

Usage

int hService = HartDLL .BHDrv_DoCommand( m_hDrv, byCmd, HartDLL .DRV_WAIT, ref m_abyData[0], byReqLen, 0, ref m_strConnection.abyUniqueID[0]); if (hService != HartDLL .INVALID_SRV_HANDLE) { HartDLL .BHDrv_FetchConfirmation(hService, ref m_strConfirmation); if (m_strConfirmation.byError == HartDLL .SRV_SUCCESSFUL) { etc...

Do command can be used for the support of most of the Hart

services including all user specific commands.

Note: It is not(!) recommended to pass a function pointer

through dwAppKey. This will cause problems with 64 bit

applications!

Page 31: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����30

Do Extended Command

unsigned int BHDrv_DoCommand( unsigned int hDrv, unsigned short usCommand, unsigned char ucQOS, unsigned char * pucReqData, unsigned char ucReqDataLen, unsigned long dwAppKey, unsigned char * pucUniqueID );

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

usCommand In Extended Hart command ( 0..65535 ) to be sent with the request

ucQOS In Quality of service

DRV_WAIT Return if the service is completed

DRV_NO_WAIT Return immediately, user will poll for completion

pucReqData In Request data: octet stream to be sent with the c ommand

ucReqDataLen In Length of the request data stream (number of oct ets/bytes)

dwAppKey In Any value. The value which the user is setting h ere is returned by the confirmation as is.

pucUniqueID In Unique identifier of the addressed device

Returns

INVALID_SRV_HANDLE No resource available, service could not be started

Any other value Service handle which is used to access the service results

Usage

CTestClient .hServiceDoCmd = HartDLL .BHDrv_DoExtCmd( CTestClient .hChannel, CSettings .ExtCmd, HartDLL .DRV_NO_WAIT, ref CTestClient .abyData[0], byLen, 0, ref CTestClient .abyUniqueID[0]);

The extended command in Hart 6/7 is an extension which is

using the byte command 31 to carry a larger command within

the data area. Therefore this function was introduced more or

less for the convenience of the HartDLL user. The function is

automatically taking care of the correct usage of command 31.

Note: It is not(!) recommended to pass a function pointer

through dwAppKey. This will cause problems with 64 bit

applications!

Page 32: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����31

Do Burst Command

unsigned int BHDrv_DoCommand( unsigned int hDrv, unsigned short usCommand, unsigned char ucQOS, unsigned char * pucReqData, unsigned char ucReqDataLen, unsigned long dwAppKey, unsigned char * pucUniqueID, unsigned char bInvertMaster );

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

usCommand In Hart command ( 0..255 ) to be sent with the burst. These commands are usually the commands 1, 2, 3, 9, 33 or 48.

ucQOS In Quality of service

DRV_WAIT Return if the service is completed

DRV_NO_WAIT Return immediately, user will poll for completion

pucReqData In Response data: octet stream to be sent with the command

ucReqDataLen In Length of the response data stream (number of oc tets/bytes)

dwAppKey In Any value. The value which the user is setting h ere is returned by the confirmation as is.

pucUniqueID In Unique identifier of the addressed device

bInvertMaster In Invert the primary master to secondary and vice versa when sending the burst frame

Returns

INVALID_SRV_HANDLE No resource available, service could not be started

Any other value Service handle which is used to access the service results

Usage

CTestClient .hServiceDoCmd = HartDLL .BHDrv_DoBurstCommand( CTestClient .hChannel, CSettings .BurstCmd, ref CTestClient .abyData[0], byLen, 0, ref CTestClient .abyUniqueID[0], byInvMaster);

To send a burst command may be helpful for device developers

or for debugging a network.

Note: Even if the burst command is only sent and no response

is received, it is very important to acknowledge this service by

calling the function FetchConfirmation after completion. Only

with this call the service handle is deleted.

Page 33: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����32

Is Service Completed

unsigned char BHDrv_IsServiceCompleted( unsigned int hSrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hSrv In The service handle which was returned by the con nect request or do command function

Returns

T_TRUE(1) Service is completed

T_FALSE(0) Service is still processing

Usage

if (pCSampler.hService != HartDLL .INVALID_SRV_HANDLE) { if ( HartDLL .BHDrv_IsServiceCompleted(pCSampler.hService) == HartDLL .T_TRUE) { etc...

The function may be used in implementations which use to

initiate several services in parallel.

Fetch Confirmation

void BHDrv_FetchConfirmation( unsigned int hSrv, T_strConfirmation * pstrConfirmation);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hSrv In The service handle which was returned by the do command function

pstrConfirmation Out Points to a structure to assign the result of a service to

Usage

HartDLL .BHDrv_FetchConfirmation(hService, ref m_strConfirmation); if (m_strConfirmation.byError == HartDLL .SRV_SUCCESSFUL) { etc...

Encoding

Int8

void BHDrv_PutInt8( unsigned char ucData, unsigned char ucOffset, unsigned char * pucStream);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

ucData In 8 bit value to be inserted into the stream

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to insert the encoded value into

Page 34: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����33

Int16

void BHDrv_PutInt16( unsigned short usData, unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

usData In 16 bit value to be inserted into the stream

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to insert the encoded value into

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

To allow a flexible byte order is interesting for vendor specific

commands, which are sometimes not following the Hart

standard. MSB stand for Most Significant Byte and LSB for Least

Significant Byte.

Int24

void BHDrv_PutInt24( unsigned long ulData, unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

ulData In 24 bit value to be inserted into the stream

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to insert the encoded value into

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

Int32

void BHDrv_PutInt32( unsigned long ulData, unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

ulData In 32 bit value to be inserted into the stream

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to insert the encoded value into

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

Page 35: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����34

Float

void BHDrv_PutFloat( float fData, unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

fData In Float value (single precision) to be inserted in to the stream

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to insert the encoded value into

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

Usage

HartDLL .BHDrv_PutFloat(m_fNewUpperRange, 1, ref m_abyData[0], HartDLL .MSB_FIRST);

The following summarizes the IEEE 754 and recommends that

standards are referred to for implementation.

The floating point values passed by the protocol are based on

the IEEE 754 single precision floating point standard.

Data Byte #0 #1 #2 #3

SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM

S - Sign of the mantissa; 1 = negative E - Exponent; Biased by 127 decimal in two's comple ment format M - Mantissa; 23 least significant bits, fractional portion

The value of the floating point number described above is

obtained by multiplying 2, raised to the power of the unbiased

exponent, by the 24-bit mantissa. The 24-bit mantissa is

composed of an assumed most significant bit of 1, a decimal

point following the 1, and the 23 bits of the mantissa.

( )1272.1 −⋅ EMS

The floating point parameters not used by a device will be filled

with 7F A0 00 00: Not-a-Number.

Page 36: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����35

Double

void BHDrv_PutDouble( double dData, unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

dData In Double value (double precision) to be inserted i nto the stream

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to insert the encoded value into

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

The following summarizes the IEEE 754 and recommends that

standards are referred to for implementation.

The floating point values passed by the protocol are based on

the IEEE 754 single precision floating point standard.

Data Byte #0 #1 #2 #3

SEEEEEEE EEEEMMMM MMMMMMMM MMMMMMMM

Data Byte #4 #5 #6 #7

MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM

S - Sign of the mantissa; 1 = negative E - Exponent; Biased by 1023 decimal in two's compl ement format M - Mantissa; 52 least significant bits, fractional portion

The value of the floating point number described above is

obtained by multiplying 2, raised to the power of the unbiased

exponent, by the 53-bit mantissa. The 53-bit mantissa is

composed of an assumed most significant bit of 1, a decimal

point following the 1, and the 52 bits of the mantissa.

( )10232.1 −⋅ EMS

Page 37: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����36

Packed ASCII

void BHDrv_PutPackedASCII( unsigned char * pucString, unsigned char ucStringLen, unsigned char ucOffset, unsigned char * pucStream);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

pucString In Pointer to an octet stream of 8-bit visible char acters

ucStringLen In Length of the visible string (number of characte rs)

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to insert the encoded value into

Usage

StringBuilder sb = new StringBuilder (m_sNewTagName); //Put the new tag name into the frame

HartDLL .BHDrv_PutPackedASCII(sb, 8, 0, ref m_abyData[0]);

Packed ASCII Coding

The packed ASCII Format uses 6 Bit to encode a character.

Therefore 4 characters in the original string require 3 octets in

the resulting data. It is recommended to provide strings always

as a multiple ordinal of 4 characters

Construction of Packed-ASCII characters:

a) Truncate Bit #6 and #7 of each ASCII character.

b) Pack four, 6 bit-ASCII characters into three bytes.

Reconstruction of ASCII characters:

a) Unpack the four, 6-bit ASCII characters.

b) Place the complement of Bit #5 of each unpacked, 6-bit

ASCII character into Bit #6.

c) Set Bit #7 of each of the unpacked ASCII characters to zero.

Page 38: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����37

The Packed ASCII code (hexadecimal) allows the representation

of the following characters.

CHAR CODE CHAR CODE CHAR CODE CHAR CODE @ 00 P 10 Space 20 0 30 A 01 Q 11 ! 21 1 31 B 02 R 12 " 22 2 32 C 03 S 13 # 23 3 33 D 04 T 14 $ 24 4 34 E 05 U 15 % 25 5 35 F 06 V 16 & 26 6 36 G 07 W 17 ' 27 7 37 H 08 X 18 ( 28 8 38 I 09 Y 19 ) 29 9 39 J 0A Z 1A * 2A : 3A K 0B [ 1B + 2B ; 3B L 0C \ 1C , 2C < 3C M 0D ] 1D - 2D = 3D N 0E ^ 1E . 2E > 3E O 0F _ 1F / 2F ? 3F

Note: The implementation of the function is assuming that the

packed ascii string should be an ordinal multiple of 3. If the

length of the passed string is not an ordinal multiple of 4 the

missing packed ascii characters are replaced by spaces.

Octet(Bytes)

void BHDrv_PutOctets( unsigned char * pucBytes, unsigned char ucNumberOfBytes, unsigned char ucOffset, unsigned char * pucStream);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

pucBytes In Pointer to a stream of bytes

ucNumberOfBytes In Length of the stream (number of bytes)

ucOffset In Offset to the first octet (byte) of the target s tream

pucStream In Pointer to the byte stream to insert the encoded value into

String

void BHDrv_PutString( unsigned char * pucString, unsigned char ucStringLen, unsigned char ucOffset, unsigned char * pucStream);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

pucString In Pointer to an octet stream of 8-bit visible char acters (ISO Latin 1)

ucStringLen In Length of the visible string (number of characte rs)

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to insert the encoded value into

The function inserts the visible string as it is.

Page 39: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����38

Decoding

Int8

unsigned char BHDrv_PickInt8( unsigned char ucOffset, unsigned char * pucStream);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

ucOffset In The handle which was returned by the OpenChannel function

pucStream In Offset to the first octet (byte) of the stream

Returns

8 bit unsigned integer value

Usage

'Copy the response to the request

For e = 0 To 17

byReqData(e) = BHDrv_PickInt8(e, ByVal strConfirmation.sData)

Next e

The example was taken from a VBA program.

Int16

unsigned int BHDrv_PickInt16( unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

ucOffset In The handle which was returned by the OpenChannel function

pucStream In Offset to the first octet (byte) of the stream

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

Returns

16 bit unsigned integer value

Note: In VBA the return value can only be interpreted as signed

integer.

Page 40: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����39

Int24

unsigned long BHDrv_PickInt24( unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

ucOffset In The handle which was returned by the OpenChannel function

pucStream In Offset to the first octet (byte) of the stream

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

Returns

Unsigned long representing a 24 bit integer value.

Int32

unsigned long BHDrv_PickInt32( unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

ucOffset In The handle which was returned by the OpenChannel function

pucStream In Offset to the first octet (byte) of the stream

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

Returns

32 bit unsigned integer value.

Float

float BHDrv_PickFloat( unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

ucOffset In The handle which was returned by the OpenChannel function

pucStream In Offset to the first octet (byte) of the stream

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

Returns

Single precision floating point value.

Usage

fLower = HartDLL .BHDrv_PickFloat(5, ref m_strConfirmation.aby_Data[0], HartDLL .MSB_FIRST);

Page 41: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����40

Double

double BHDrv_PickDouble( unsigned char ucOffset, unsigned char * pucStream, unsigned char ucEndian);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

ucOffset In The handle which was returned by the OpenChannel function

pucStream In Offset to the first octet (byte) of the stream

ucEndian In Byte order

MSB_FIRST(0) Big Endian (Hart standard)

LSB_FIRST(1) Little Endian

Returns

Double precision floating point value.

Packed ASCII

unsigned char BHDrv_PickPackedASCII( unsigned char * pucString unsigned char ucStringLen unsigned char ucOffset, unsigned char * pucStream);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

pucString Out Pointer to an octet stream for the 8-bit visibl e characters

ucStringLen In Length of the resulting string. It should be an ordinal multiple of 4.

String length Packed ASCI length

4 3

8 6

12 12

and so on...

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to get the data from

Returns

Single precision floating point value.

Usage

StringBuilder sb = new StringBuilder (8);

HartDLL .BHDrv_PickPackedASCII(sb, 8, 0, ref m_strConfirmation.aby_Data[0]);

sTag = sb.ToString();

Page 42: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����41

Octet(Bytes)

void BHDrv_PickOctets( unsigned char * pucBytes, unsigned char ucNumberOfBytes, unsigned char ucOffset, unsigned char * pucStream);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

pucBytes Out Pointer to copy the bytes to

ucNumberOfBytes In Length of the stream (number of bytes)

ucOffset In Offset to the first octet (byte) of the target s tream

pucStream In Pointer to the byte stream to insert the encoded value into

String

void BHDrv_PickString( unsigned char * pucString, unsigned char ucStringLen, unsigned char ucOffset, unsigned char * pucStream);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

pucString Out Pointer to an octet stream of 8-bit visible cha racters to copy the string to

ucStringLen In Length of the visible string (number of characte rs)

ucOffset In Offset to the first octet (byte) of the stream

pucStream In Pointer to the byte stream to insert the encoded value into

Slave Emulation

The driver can be used to emulate a HART slave. If the slave

mode is enabled the driver takes active control of its role.

In slave mode the driver is automatically responding to

connection establishment commands of Hart such as command

0 and command 11. If the driver is in slave mode it passes

eventual received requests to the slave control unit if an answer

of the application is needed.

The slave is realized by a simulation (emulation) DLL which is

loaded by HartDLL. The slave may use its own com port or

share the com port with the master in the DLL.

Slave DLL

void BHDrv_Slave_SetDLL( unsigned int hDrv, unsigned char * psz_DLLpathAndName);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

psz_DLLpathAndName In Full path of the slave simulation DLL to be load ed

Usage

HartDLL .BHDrv_Slave_SetDLL( s_hChannel, new StringBuilder ( CSettings .SlaveDLLname));

Page 43: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����42

Start Slave Simulation

void BHDrv_Slave_Start( unsigned int hDrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

Usage

HartDLL .BHDrv_Slave_Start(s_hChannel); BHDrv_Slave_RegDisplayIface(s_hChannel, ref s_strSlaveDisplayIface);

The functions loads the slave simulation DLL and starts the

emulation.

Terminate Slave Simulation

void BHDrv_Slave_Terminate( unsigned int hDrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

Usage

HartDLL .BHDrv_Slave_Terminate( s_hChannel); s_hChannel = HartDLL .INVALID_DRV_HANDLE;

The function stops the slave emulation and unloads the slave

simulation DLL.

Slave DLL Status

unsigned char BHDrv_Slave_IsActive( unsigned int hDrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

Returns

T_TRUE(1) Slave is active

T_FALSE(0) Slave not active

Usage

if ( HartDLL .BHDrv_Slave_IsActive(s_hChannel) != 0 ) { return true ; } return false ;

Get Slave Configuration

void BHDrv_Slave_GetConfiguration ( unsigned int hDrv, T_strSlaveConfiguration * pstrConfiguration);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

pstrConfiguration Out The function copies the configuration to the st ructure pointed to.

Page 44: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����43

Set Slave Configuration

void BHDrv_Slave_SetConfiguration ( unsigned int hDrv, T_strSlaveConfiguration * pstrConfiguration);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

pstrConfiguration In The function uses the value of the given structu re to configure the slave simulation DLL. In case of a parameter error the function defaults to the minimum respectively maximum value of the parameter .

Get Slave Parameter

unsigned char BHDrv_Slave_GetParameter( unsigned int hDrv, unsigned short usParaIdx, unsigned char * pucData, unsigned char * pucSize);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

usParaIdx In The parameter index identifies the content pucDa ta is pointing to

pucData In Pointer to the data bytes

pucSize In Out

In: Size of the buffer pucData is pointing to Out: Number of bytes copied to pucData

Returns

0 No error

Any other value Error

Set Slave Parameter

unsigned char BHDrv_Slave_SetParameter( unsigned int hDrv, unsigned short usParaIdx, const unsigned char * pucData, unsigned char ucSize);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

usParaIdx In The parameter index identifies the content pucDa ta is pointing to

pucData In Pointer to the data bytes

ucSize In Size of the data pucData is pointing to

Returns

0 No error

Any other value Error

Page 45: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����44

Get Slave Dynamic Values

void BHDrv_Slave_GetDynValues ( unsigned int hDrv, T_strSlaveDynamicValues * pstrDynamicValues);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

pstrDynamicValues Out The function copies the dynamic data to the str ucture pointed to.

Set Slave Dynamic Values

void BHDrv_Slave_SetDynValues ( unsigned int hDrv, T_strSlaveDynamicValues * pstrDynamicValues);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

pstrDynamicValues In The function uses the value of the given structu re to set the dynamic values of the slave simulation DLL.

Register Slave Display Callback

void BHDrv_Slave_RegDisplayIface( unsigned int hDrv, T_SLV_DISP_IFACE * pstrDisplayIface);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s, BaHartDrv74_Iface.vb

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

pstrDisplayIface In Pointer to a structure with the required callbac k ponters.

The function is used to register two callback functions at the

slave interface. There is one function for printing lines at a

console display and one function for clearing this display.

typedef struct t_slv_disp_iface { T_VOID ( __cdecl * Print)(T_CHR* Text, T_UCHR Row); T_VOID ( __cdecl * Clear)(T_VOID); } T_SLV_DISP_IFACE;

Page 46: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����45

Receiving Cyclic Data

In Hart devices cyclic data is sometimes propagated by burst

messages. These are special Hart protocol primitives which are

sent without any request from a master.

There are two ways to implement the access of burst messages.

One is to poll the driver for incoming data, the other way is to

register a callback function.

Burst Control

Start

void BHDrv_CycSrvStart( unsigned int hDrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

Usage

if (m_hDrv != HartDLL .INVALID_DRV_HANDLE) { HartDLL .BHDrv_CycSrvStart(m_hDrv); }

Note: If this function is called eventual existing messages in the

drivers queue are deleted, thus the reception of Hart burst

messages starts with an empty queue.

However, before BHDrv_CycSrcStart is called incoming burst

messages are discarded.

Stop

void BHDrv_CycSrvStop( unsigned int hDrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s

Parameter Type Description

hDrv In The handle which was returned by OpenChannel

Usage

if (m_hDrv != HartDLL .INVALID_DRV_HANDLE)

{

HartDLL .BHDrv_CycSrvStop(m_hDrv);

}

After the call of this function the reception of burst messages is

halted. Messages already in the queue may be read by

BHDrv_CycSrvGetData.

Page 47: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����46

Asynchronous Reading

unsigned char BHDrv_CycSrvGetData( unsigned int hDrv, T_strCyclicData * pstrCyclicData);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

pstrCyclicData In Pointer to a structure to copy the cyclic data t o.

Returns

CYCDAT_NO_DATA(1) No cyclic data available

CYCDAT_OK(0) Cyclic data was passed into the structure pointed t oo

Usage

ucResult = HartDLL .BHDrv_CycSrvGetData(m_hDrv, ref m_strCyclicData); if (ucResult == HartDLL .CYCDAT_OK) { DisplayCyclicData(m_strCyclicData); }

Using A Callback Function

It is also possible to use a callback function. For a detailed

description of this option please refer to chapter ‘GetCyclicData’

in the examples section.

Register

void BHDrv_CycSrvRegisterCB( unsigned int hDrv, void ( __stdcall * pfSubscribeCyclicData) ( unsigned int hDrv, T_strCyclicData * pstrCyclicData ) );

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

pfSubscribeCyclicData In Pointer to a function to be called when a burst message was received

Usage

if (m_hDrv != HartDLL .INVALID_DRV_HANDLE) { HartDLL .BHDrv_CycSrvRegisterCB(m_hDrv, m_dlCallback); }

Unregister

void BHDrv_CycSrvUnregister( unsigned int hDrv);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

Usage

if (m_hDrv != HartDLL .INVALID_DRV_HANDLE) { HartDLL .BHDrv_CycSrvUnregister(m_hDrv); }

The function deletes the pointer to the callback function.

Page 48: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����47

Callback Prototype

void __stdcall BHDrv_CycSrvSubscribeCB(unsigned int hDrv, T_strCyclicData * pstrCyclicData);

BaHartDrv74.h, BaHartDrv74.lib, BaHartDrv74_Iface.c s

Parameter Type Description

hDrv In The handle which was returned by the OpenChannel function

pstrCyclicData In Pointer to a structure to copy the cyclic data t o.

Page 49: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����48

Structures

Master Services

T_strConfiguration

Type Name Description

unsigned int uiBaudRate Baudrate as defined in winbase.h CBR_1200 CBR_9600 CBR_19200 CBR_38400 Default: CBR_1200

unsigned char ucNumPreambles Number of preambles used for a request (0..22) Default: 5

unsigned char ucNumRetries Number of retries if device response is erroneous (0..3) Default: 2

unsigned char ucRetryIfBusy 0: Do not retry if device is responding with busy code

1..255: Retry the command if device is responding with busy code. The number of retries is reflected in the confirmation as ucUsedRetries.

Default: 1

unsigned char ucInitialMasterRole 0: Primary master 1: Secondary master Default: 0

unsigned char uc Reserved Not used (former addressing mode)

unsigned char ucDoNotUseRtsDtr 0: Use handshake signals 1: Do not use handshake signals Default: 0

unsigned short usAddTimeOut Additional time out to wait for a slave response in ms. Typical 100, 200 etc. Default: 0

unsigned short usAddGapTime Additional time for gap between characters in ms. Typical 5, 10 etc. Default: 0

unsigned short usAddRtsOffDelay Additional delay before Rts is switched off (carrie r off) in ms. Typical 1, 2, 5, 10 etc. Default: 0

unsigned char bSendJabberOctet 0: Normal sending 1: Append ucJabberOctet to each frame Default: 0

unsigned char ucJabberOctet Value of the jabber octet

unsigned char bGenParityError Generate a parity error on a particular position

unsigned char ucParityErrorPos Number of the byte at which the error should be injected

unsigned char bHartEnabled 0: Hart not running 1: Hart protocol active

unsigned char bRecJabberOctet 0: Ignore jabber octets 1: Report jabber octets to the monitor

Page 50: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����49

T_strRunTimeInfo

Type Name Description

unsigned char bActualMaster 0: Primary Master 1: Secondary Master

unsigned char bFifoDetected >0: More than 3 characters are received at once

unsigned char uc BlockSize Number of characters received at once

unsigned char uc Reserved

T_strConnection

Type Name Description

unsigned char ucManId Manufacturer id as defined by the Hart Communicatio n Foundation

unsigned char ucDevId Vendor's device id

unsigned char ucNumPreambs Number of preambles defined by the device

unsigned char ucCmdRevNum Command set revision number as defined by Hart

unsigned char ucSpecRevCode Device specific revision code

unsigned char ucSwRev Software revision code (0..255)

unsigned char ucHwRev Hardware revision code

unsigned char ucHartFlags The flags as defined by Hart

unsigned char ucError Service completion code

SRV_EMPTY(0) Not active

SRV_NO_DEV_RESP(1) No device response

SRV_COMM_ERR(2) There was some error (too few data e.g.)

SRV_INVALID_HANDLE(3) Service handle is invalid

SRV_IN_PROGRESS(4) Service working

SRV_SUCCESSFUL(5) Service successfully completed

SRV_RESOURCE_ERROR(6) Out of memory

SRV_TOO_FEW_DATA_BYTES(7) Used for cmd 31

unsigned char ucRespCode1 Response code 1 as defined by the Hart specificatio n

unsigned char ucRespCode2 Response code 2 as defined by the Hart specificatio n

unsigned char ucUsedRetries Number of retries which were used for completion

unsigned char bDeviceInBurstMode 0: Normal mode 1: Device is in burst mode

unsigned char ucExtDevStatus Extended device status

unsigned short usCfgChCount Configuration changed counter

unsigned char ucMinNumPreambs Minimum number of preambles

unsigned char ucMaxNumDVs Maximum number of device variables

unsigned short usManuID Extended manufacturer ID

unsigned short usLabDistID Extended label distributor ID

unsigned char ucDevProfile Device profile

unsigned char ucReserved -/-

unsigned char aucUniqueID[5] Unique identifier

Page 51: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����50

T_strConfirmation

Type Name Description

unsigned char ucCmd Command which was executed

unsigned char ucRespCode1 Response code 1 as defined by the Hart specificatio n

unsigned char ucRespCode2 Response code 2 as defined by the Hart specificatio n

unsigned char ucError Service completion code

SRV_EMPTY(0) Not active

SRV_NO_DEV_RESP(1) No device response

SRV_COMM_ERR(2) There was some error (too few data e.g.)

SRV_INVALID_HANDLE(3) Service handle is invalid

SRV_IN_PROGRESS(4) Service working

SRV_SUCCESSFUL(5) Service successfully completed

SRV_RESOURCE_ERROR(6) Out of memory

SRV_TOO_FEW_DATA_BYTES(7) Used for cmd 31

unsigned char ucUsedRetries Number of retries which were used for completion

unsigned char bDeviceInBurstMode 0: Normal mode 1: Device is in burst mode

unsigned short usDuration Time for service execution in ms

unsigned long dwAppKey Is returned by the FetchConfirmation function as it was passed to the DoCommand function.

unsigned short usExtCmd Extended cmd number

unsigned char ucReserved Reserved for future use

unsigned char ucLen Number of response data bytes (octets)

unsigned char aucData [DATA_BUF_LEN]

Response data bytes (DATA_BUF_LEN = 255)

Page 52: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����51

Slave Emulation

T_strSlaveDynamicValues

Type Name Description

float fPercent Actual percent of range

float fCurrent Actual current value as ma

unsigned char ucUnitCodePV1 Hart unit code for PV1

unsigned char ucUnitCodePV2 Hart unit code for PV2

unsigned char ucUnitCodePV3 Hart unit code for PV3

unsigned char ucUnitCodePV4 Hart unit code for PV4

float fPV1 Value of PV1

float fPV2 Value of PV2

float fPV3 Value of PV3

float fPV4 Value of PV4

unsigned char bDeviceMalfunction Signals device mal function T_CLEAR(0)

T_SET(1)

unsigned char bCfgChangedPrimMaster Configuration change flag for primary master

T_CLEAR(0)

T_SET(1)

unsigned char bCfgChangedScndMaster Configuration change flag for primary master

T_CLEAR(0)

T_SET(1)

unsigned char bColdStartPrimMaster Cold start flag for primary master T_CLEAR(0)

T_SET(1)

unsigned char bColdStartScndMaster Cold start flag for secondary master

T_CLEAR(0)

T_SET(1)

unsigned char bMoreStatusAvail Flags more status available (see command 48)

T_CLEAR(0)

T_SET(1)

unsigned char bLoopCurrentFixed Signals fixed current mode active T_CLEAR(0)

T_SET(1)

unsigned char bLoopCurrentSaturated Signals current output saturated T_CLEAR(0)

T_SET(1)

unsigned char bNonPrimVarOutLimits Signals none primary variable out of limits

T_CLEAR(0)

T_SET(1)

unsigned char bPrimVarOutLimits Signals primary variable out of limits

T_CLEAR(0)

T_SET(1)

unsigned char bUseExtValues Indication to the slave simulation to use the values of this structure instead of its own.

unsigned char ucReserved1 Reserved for future use

Page 53: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����52

T_strSlaveConfiguration

Type Name Description

unsigned char ucManufacturerID Manufacturer’s identifier

unsigned char ucDeviceID Device identifier

unsigned char ucNumPreambles Number of preambles needed in a request (2..20, recommended: 2)

unsigned char ucCmdSetRevision Hart compatibility version (5..7, recommended: 5)

unsigned char ucTransmSpecRev Transmitter specific revision

unsigned char ucSoftwareRevision Software revision number

unsigned char ucHardwareRevision Hardware revision number

unsigned char ucReserved1 Reserved for future use

unsigned char ucDevNum1 Device number [LSB]

unsigned char ucDevNum2 Device number [LSB+1]

unsigned char ucDevNum3 Device number [LSB+2]

unsigned char ucReserved2 Reserved for future use

unsigned char auc Short Tag[ 12] Tag name, 8 characters (see 3.3.2.1 Packed ASCII Coding for possible characters)

unsigned char aucLongTag[3 6] Long tag name, 32 characters iso latin 1

unsigned char uc Poll Address Slave polling address

unsigned char ucNumberOfPVs Defines the number of variables to be sent with command 3

unsigned char ucReserved3 Reserved for future use

unsigned char ucReserved4 Reserved for future use

unsigned char aucMessage[36] Message, 32 characters coded in packed ASCII

unsigned char aucDescription[20] Description, 16 characters coded in packed ASCII

unsigned char ucDay Day of Hart date (1..31)

unsigned char ucMonth Month of Hart date (1..12)

unsigned short usYear Year of Hart date (1900..2155)

Cyclic Data

T_strCyclicData

Type Name Description

unsigned long ulTimeStamp Time in ms since recording of burst messages was started

unsigned char ucCmd Command of the received frame

unsigned char ucRsp1 Device response code 1

unsigned char ucRsp2 Device response code 2

unsigned char ucDataLen Number of bytes in productive data

unsigned char aucData[ 255 ] Productive data of the burst message

Page 54: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Functional Description����53

Constants

Name Value Description

Service Completion Codes

SRV_EMPTY 0x00 Service not active

SRV_NO_DEV_RESP 0x01 Device did not respond

SRV_COMM_ERR 0x02 There was a communication error (too few data e.g.)

SRV_INVALID_HANDLE 0x03 Service handle not valid

SRV_IN_PROGRESS 0x04 Service not yet completed

SRV_SUCCESSFUL 0x05 Service successfully completed

SRV_RESOURCE_ERROR 0x06 Out of memory

SRV_TOO_FEW_DATA_BYTES 0x07 Used with cmd 31

Handle Values

INVALID_DRV_HANDLE -1 Driver handle not valid

INVALID_SRV_HANDLE -1 Service handle not valid

Endian

MSB_FIRST 0x00 Big Endian (Hart standard): Most Significant B yte first

LSB_FIRST 0x01 Little Endian: Least Significant Byte first

Wait Options

DRV_NO_WAIT 0x00 User will poll for the completion of service

DRV_WAIT 0x01 The function returns if service is completed

Slave Modes

SLAVE_DISABLED 0x00 Slave emulation is not active

SLAVE_ENABLED 0x01 Slave emulation is active

Cyclic Data Handling

CYCDAT_OK 0x00 Cyclic data available

CYCDAT_NO_DATA 0x01 Cyclic data not (yet) available

Page 55: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Hart at a Glance����54

Hart at a Glance

Frame Coding

Figure 7: The Basic Coding of a Hart Frame

The figure above is giving an overview of the coding of a Hart

frame. Usually Hart services are composed of a request (stx) by

the master followed the response (ack) of a slave. Bursts (back)

are frames looking like a response (including response codes)

but sent by the slave without any request. The slave is sending

these frames in burst mode within defined time slots following

the rules of the protocol specification. In fact Hart is a token

passing protocol which allows also the slave to be a token

holder and send burst frames.

The following chapter is showing a list of Hart commands which

are used very often. The list is showing the major differences

between Hart 5.3, Hart 6 and Hart 7.4.

New items in Hart 6 are marked with yellow color while new

items of Hart 7.4 are marked by blue color.

However, the following is not replacing any specification and is

not showing the details which are needed for an

implementation. The details has to be taken from the Hart

specifications which are provided by the Hart Communication

Foundation (http://de.hartcomm.org/).

That the listed commands are most commonly used is not the

opinion of the HCF but the opinion of the author of this

document.

DEL ADDRESS ExpBytes CMD CNT DATA CHK

Short Address

6 Bit Polling Address

Field Device in Burst Mode

Master Address

0 Secondary Master 1 Primary Master

The Delimiter leads to the Byte Count

The Byte Count leads to the Check Byte

MAN DEV UNIQUE ID

Long Address

6 Least Significant Bits of Manufacturer ID

Field Device in Burst Mode

Master Address 0 Secondary Master 1 Primary Master

Delimiter

Frame Type

1 BACK (Burst Frame) 2 STX (Master to Field Device) 6 ACK (Field Device to Master)

Physical Layer Type 0 Asynchronous 1 Synchronous

Number of Expansion Bytes

0 Polling (1 Byte) Address 1 Unique (5 Byte) Address

Address Type

Reponse Data Normal: RSP1 RSP2 PAYLOAD

Reponse Data Cmd 31: RSP1 RSP2 PAYLOAD EXTCMD

N Bytes

2 Bytes N Bytes

5 Bytes

N (+2) (+2) Bytes

Data may contain response codes (ack, back) and/or the extended command (stx, ack, back).

0-3 Bytes

Note: In this figure the preambles (0xff), which are sent before the delimiter are not shown because the preambles are considered to be a part of the physical layer.

Number payload bytes + response bytes + extended command bytes

First Address Byte

Normally not used.

Device ID

Unique for 6 bit manufacturer ID and 8 bit device ID.

1 or 5 Bytes

Page 56: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Hart at a Glance����55

Commonly Used Commands

No Title Request Data Response Data

Universal

00 Read Unique Identifier

None 0 int8 254

1 Manufacturer ID

2 Short device ID

3 Number preambles request

4 Hart revision

5 Device revision

6 Software revision

7 Hw rev and signaling code

8 Flags

9 int24 DevUniqueID

12 int8 Number preambles response

13 Maximum number device variables

14 int16 Configuration change counter

16 int8 Extended device status

17 int16 Extended manufacturer code

19 Extended label distributor code

21 int8 Device profile

01 Read Primary Variable

None 0 int8 PV Units

1 float Primary variable

02 Read Current and Percent of Range

None 0 float Current

1 float Percent of range

03 Read Current and Dyn. Variables

None 0 float Current

4 int8 PV1 units code

5 float PV1 value

9 int8 PV2 units code

10 float PV2 value

14 int8 PV3 units code

15 float PV3 value

19 int8 PV4 units code

20 float PV4 value

06 Write Polling Address

0 int8 Polling Address 0 int8 PV Units

1 int8 Loop current mode 1 int8 Loop current mode

07 Read Loop Configuration

None 0 int8 Polling address

1 Loop current mode

08 Read Dyn. Vars Classification

None 0 int8 PV1 classification

1 PV2 classification

2 PV3 classification

3 PV4 classification

Page 57: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Hart at a Glance����56

No Title Request Data Response Data

Universal

09 Read Device Variables with Status

0 int8 Slot0: Device variable code 0 int8 Extended device status

1 Slot1: Device variable code 1 Slot0: Device variable properties

2 Slot2: Device variable code 1 int8 Device variable code

3 Slot3: Device variable code 2 Device variable classification

4 int8 Slot4: Device variable code 3 Device variable units code

5 Slot5: Device variable code 4 float Device variable value

6 Slot6: Device variable code 8 int8 Device variable status

7 Slot7: Device variable code 9 struct Slot1: Device variable properties

17 Slot2: Device variable properties

25 Slot3: Device variable properties

33 struct Slot4: Device variable properties

41 Slot5: Device variable properties

49 Slot6: Device variable properties

57 Slot7: Device variable properties

65 time Time stamp slot0

11 Read Unique ID by Short Tag

0 pac6 Tag name (packed ascii) 6 bytes = 8 characters

Same as command 0 read unique identifier

12 Read Message None 0 pac24 Message (packed ascii) 24 bytes = 32 characters

13 Read Tag, Descriptor, Date

None 0 pac6 Short tag (packed ascii) 6 bytes = 8 characters

6 pac12 Descriptor (packed ascii) 12 bytes = 16 characters

18 int8 Day

19 Month

20 Year (offset to 1900)

14 Read Primary Variable Transducer Information

None 0 int24 Transducer serial number

3 int8 Units code

4 float Upper transducer limit

8 Lower transducer limit

12 Minimum span

15 Read Device Information

None 0 int8 Alarm selection code

1 Transfer function code

2 Units code

3 float PV upper range value (for 20 mA)

7 PV lower range value (for 4 mA)

11 PV damping value

15 int8 Write protect code

16 Reserved, must be set to 250

17 PV analog channel flags

16 Read Ass. Num None 0 int24 Final assembly number

17 Write Message Same as response command 12 Same as response command 12

18 Write Tag, Descriptor, Date

Same as response command 13 Same as response command 13

19 Write Ass. Num Same as response command 16 Same as response command 16

20 Read Long Tag None 0 str32 Long tag: 32 ISO Latin-1 characters

21 Read Unique ID by Long Tag

0 str32 Long tag: 32 ISO Latin-1 characters Same as command 0 read unique identifier

22 Write Long Tag Same as response command 20 Same as response command 20

Page 58: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Hart at a Glance����57

No Title Request Data Response Data

Universal / Common Practice

38 Reset Config Changed Flag

None None

0 int16 Configuration change counter 0 int16 Configuration change counter

48 Read Additional Device Status

None

0 int8[5] Transmitter specific status 0 int8[5] Transmitter specific status

6 int8[2] Operating mode

6 int8 Extended device status 6 int8 Extended device status

7 Device operating mode 7 Device operating mode

8 int8[3] Analog output status

8 int8 Standard status 0 8 int8 Standard status 0

9 Standard status 1 9 Standard status 1

10 Analog channel saturated 10 Analog channel saturated

11 int8[3] Analog output fixed

11 int8 Standard status 2 11 int8 Standard status 2

12 Standard status 3 12 Standard status 3

13 Analog channel fixed 13 Analog channel fixed

14 int8[3] Transmitter specific status

14 int8[10] Transmitter specific status 14 int8[10] Transmitter specific status

Common Practice

33 Read Device Variables

0 int8 Slot0: Device variable code 0 Slot0: Device variable properties

1 Slot1: Device variable code 0 int8 Device variable code

2 Slot2: Device variable code 1 Device variable units code

3 Slot3: Device variable code 2 float Device variable value

6 struct Slot1: Device variable properties

12 Slot2: Device variable properties

18 Slot3: Device variable properties

34 Write Prim . Var . Damping

0 float PV 1 damping value 0 float PV 1 damping value

35 Write Prim. Var. Range Values

0 int8 Units code 0 int8 Units code

1 float Upper range value 1 float Upper range value

5 Lower range value 5 Lower range value

36 Set Prim. Var. Upper Range

None None

37 Set Prim. Var. Lower Range

None None

40 Enter/Exit Fixed Current

0 float Current value 0 float Actual current value

42 Device Reset None None

43 Set Primary Variable Zero

None None

44 Write Prim. Var. Units

0 int8 PV 1 units code 0 int8 PV 1 units code

45 Trim Prim. Var. Current Zero

0 float Measured current value 0 float Actual current value

46 Trim Prim. Var. Current Gain

0 float Measured current value 0 float Actual current value

50 Read Dynamic Variable Assignments

None 0 int8 PV 1 variable code

1 PV 2 variable code

2 PV 3 variable code

3 PV 4 variable code

Page 59: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Hart at a Glance����58

No Title Request Data Response Data

Common Practice

51 Write Dynamic Variable Assignments

0 int8 PV 1 variable code 0 int8 PV 1 variable code

1 PV 2 variable code 1 PV 2 variable code

2 PV 3 variable code 2 PV 3 variable code

3 PV 4 variable code 3 PV 4 variable code

54 Read Device Variable Information

0 int8 Device variable code 0 int8 Device variable code

1 int24 Sensor serial number

4 int8 Units code

5 float Variable upper limit

9 Variable lower limit

13 Variable damping

17 Variable minimum span

21 int8 Variable classification

22 Variable family

23 time Acquisition period

27 bin8 Variable properties

71 Lock Device 0 int8 Lock code 0 int8 Lock code

76 Read Lock State None 0 int8 Lock status

78 Read Aggregated Commands

0 int8 Number of commands requested 0 int8 Extended device status

1 str[] Array of command requests struct { int8 command int8 byteCount int8[] requestData }

1 int8 Number of commands requested

2 str[] Array of command responses struct { int8 command int8 byteCount int8 responseCode int8[] responseData }

792 Write Device Variable

0 int8 Device Variable Code 0 int8 Device Variable Code

1 DV command code 1 DV command code

2 DV units code 2 DV units code

3 float DV value 3 float DV value

7 int8 DV status 7 int8 DV status

103 Write Burst Period

0 int8 Burst message 0 int8 Burst message

1 time Update period 1 time Update period

5 Maximum update period 5 Maximum update period

104 Write Burst Trigger

0 int8 Burst message 0 int8 Burst message

1 Trigger mode selection code 1 Trigger mode selection code

2 Device variable classification for trigger level

2 Device variable classification for trigger level

3 Units code 3 Units code

4 float Trigger level 4 float Trigger level

2 Used to simulate the value of a device variable

Page 60: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Hart at a Glance����59

No Title Request Data Response Data

Common Practice

105 Read Burst Mode Configuration

None 0 int8 Burst mode control code

1 int8 Burst command number

2 int8 Burst command slot 0

3 int8 Burst command slot 1

4 int8 Burst command slot 2

5 int8 Burst command slot 3

0 int8 Burst message 0 int8 Burst mode control code

1 0x1f (31) command expansion

2 DV code slot0

3 DV code slot1

4 DV code slot2

5 DV code slot3

6 DV code slot4

7 DV code slot5

8 DV code slot6

9 DV code slot7

10 Burst message

11 Maximum number of burst messages

12 int16 Extended command number

14 time Update time

18 Maximum update time

22 int8 Burst trigger mode code

23 DV classification for trigger value

24 Units code

25 float trigger value

106 Flush Delayed Responses

None None

107 Write Burst Device Variables

0 int8 DV code slot 0 0 int8 DV code slot 0

1 DV code slot 1 1 DV code slot 1

2 DV code slot 2 2 DV code slot 2

3 DV code slot 3 3 DV code slot 3

4 int8 DV code slot 4 4 int8 DV code slot 4

5 DV code slot 5 5 DV code slot 5

6 DV code slot 6 6 DV code slot 6

7 DV code slot 7 7 DV code slot 7

8 Burst message 8 Burst message

108 Write Burst Mode Command

0 int8 Command number for the burst response

0 int8 Command number of the burst response

109 Burst Mode Control

0 int8 Burst mode control code 0 int8 Burst mode control code

113 Catch Device Variable

0 int8 Destination DV code 0 int8 Destination DV code

1 Capture mode code 1 Capture mode code

2 Source slave manufacturer ID 2 int8[5] Source slave address

3 Source slave device type

2 int16 Source slave expanded device type

4 int8[3] Source slave device ID

7 int8 Source command number 7 int8 Source command number

8 Source slot number 8 Source slot number

9 float Shed time for this mapping 9 float Shed time for this mapping

7 int8 0x1f (31) command expansion 7 int8 0x1f (31) command expansion

8 Source slot number 8 Source slot number

9 float Shed time for this mapping 9 float Shed time for this mapping

13 int16 Ext source command number 13 int16 Ext source command number

Page 61: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Hart at a Glance����60

No Title Request Data Response Data

Common Practice

114 Read Caught Device Variable

0 int8 Destination DV code 0 int8 Destination DV code

1 Capture mode code

2 int8[5] Source slave address

7 int8 Source command number

8 Source slot number

9 float Shed time for this mapping

7 int8 0x1f (31) command expansion

8 Source slot number

9 float Shed time for this mapping

13 int16 Ext source command number

523 Read Condensed Status Mapping Array

0 int8 Starting index status map 0 int8 Actual starting index

1 Number of entries to read 1 Number of entries returned

2 int4[] Status map codes array

524 Write Condensed Status Mapping Array

0 int8 Starting index status map 0 int8 Actual starting index

1 Number of entries to write 1 Number of entries returned

2 int4[] Status map codes array 2 int4[] Status map codes array

525 Reset Condensed Status Map

None None

526 Write Status Simulation Mode

0 int8 Status simulation mode 0 int8 Status simulation mode

527 Simulate Status Bit

0 int8 Status bit index 0 int8 Status bit index

1 Status bit value 1 Status bit value

Response Codes

As response code 1 is command specific it is documented

together with the command specifications. However response

code 2 is of general nature and contains 8 bit flags with the

following meaning.

Flag Number / Meaning Description

Bit #7 Field Device Malfunction The device has detected a hardware error or failure. Further information may be available through the Read Additional Transmitter Status Command, #48.

Bit #6 Configuration Changed A write or set command has been executed.

Bit #5 Cold Start Power has been removed and reapplied resulting in the reinstallations of the setup information. The first command to recognize this condition will automatically reset this flag. This flag may also be set following a Master Reset or a Self Test.

Bit #4 More Status Available More status information is available than can be returned in the Field Device Status. Command #48, Read Additional Status Information, will provide this additional status information.

Bit #3 Primary Variable Analog

Output Fixed

The analog and digital analog outputs for the Primary Variable are held at the requested value. They will not respond to the applied process.

Bit #2 Primary Variable Analog

Output Saturated

The analog and digital analog outputs for the Primary Variable are beyond their limits and no longer represent the true applied process.

Bit #1 Non Primary Variable Out of

Limits

The process applied to a sensor, other than that of the Primary Variable, is beyond the operating limits of the device. The Read Additional Transmitter Status Command, #48, may be required to identify the variable.

Bit #0 Primary Variable Out of

Limits

The process applied to the sensor for the Primary Variable is beyond the operating limits of the device.

Page 62: HartDLL 7borst-automation.com › manuals › Ba-Hart-DLL-7.4.1.pdf · HartTools HartDLL 7.4.1 / 14.02.2014 Overview 4 Because command 0 is the only command in Hart which is working

HartTools

HartDLL 7.4.1 / 14.02.2014 Appendix����61

Appendix

Abbreviations

Abbreviation Description

HCF Hart Communication Foundation

DLL Windows: Dynamic Link Library

OSI-ISO: Data Link Layer

HAL Hardware Abstraction Layer

HART Highway Addressable Remote Transducer See also:

http://en.wikipedia.org/wiki/Highway_Addressable_Remote_Transducer_Protocol

HMI Human Machine Interface

ISO International Standards Organisation

MODEM MOdulator DEModulator

NV-memory Non-Volatile memory

OSAL Operating System Abstraction Layer

OSI Open Systems Interconnection

UART Universal Asynchronous Receiver Transmitter