Project Description
Hart Communication Protocol Lite is a small and simple project to communicate with field devices via HART protocol. It's developed in C# with .NET Framework 2.0.
You can use this library for simple HART communication with field devices.
The Hart Communication Protocol Lite libary runs on Microsoft .NET Framework 2.0 or under Mono 2.6 or higher (even Linux & Mac).
Small console application spike could look like this:
using System; using System.Collections.Generic; using Finaltec.Communication.HartLite; class Programm { public void Main() { HartCommunicationLite hartCommunicationLite = new HartCommunicationLite("COM1"); OpenResult openResult = hartCommunicationLite.Open(); if(openResult != OpenResult.Opened) return; hartCommunicationLite.PreambleLength = 10; hartCommunicationLite.Receive += ReceiveValueHandle; hartCommunicationLite.SendingCommand += SendingValueHandle; while(true) { //input should be in format like "17:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0" //this is the command 17 with 24 bytes with 0 value string input = Console.ReadLine(); if(input == "exit") break; //this part works only if the input is correct string[] values = input.Split(new[] { ':' }); List<byte> databytes = new List<byte>(); for(int i = 1; i < values.Count(); i++) { //Error if some data not in a byte format! databytes.Add((byte)values[i]); } hartCommunicationLite.SendAsync(values[0], databytes.ToArray()); } hartCommunicationLite.Receive -= ReceiveValueHandle; hartCommunicationLite.SendingCommand -= SendingValueHandle; } private void SendingValueHandle(object sender, CommandRequest args) { Console.WriteLine(string.Format("Sended: {0} {1} {2} {3} {4} {5}", args.PreambleLength, args.Delimiter, BitConverter.ToString(args.Address), args.CommandNumber, args.Data, args.Checksum)); } private void ReceiveValueHandle(object sender, CommandResult args) { Console.WriteLine(string.Format("Received: {0} {1} {2} {3} {4} {5} {6}", args.PreambleLength, args.Delimiter, BitConverter.ToString(args.Address), args.CommandNumber, args.Data,
BitConverter.ToString(new[] { args.ResponseCode.FirstByte, args.ResponseCode.SecondByte }),
args.Checksum)); } }
Additional HART informations:
HART Communication Protocol - Wikipedia
Features
» Simple communication with field devices.
History
In the last few years our software company develop a complex communication framework for field devices. This library is designed for object orientated patterns. We represent field devices as a complex DeviceModel to communicate with them. For small and simple
applications this could be to much work. Now, for this use case, we develop a simple HART communication framework.
Projektbeschreibung
Hart Communication Protocol Lite ist ein kleines einfaches Projekt für Feldgeräte Kommunikation mit dem HART Protokol. Entwickelt wurde es in C# mit .NET Framework 2.0.
Diese Bibiliotek kann für einfache HART Kommunikation mit Feldgeräten verwendet werden.
Die Hart Communication Protocol Lite Bibiliothek läuft unter Microsoft .NET Framework 2.0 sowie auch unter Mono 2.6 oder neuer (für Linux und Mac).
Ein kleiner Konsolen Anwendungs Spike könnte wie folgt aussehen:
using System; using System.Collections.Generic; using Finaltec.Communication.HartLite; class Programm { public void Main() { HartCommunicationLite hartCommunicationLite = new HartCommunicationLite("COM1"); OpenResult openResult = hartCommunicationLite.Open(); if(openResult != OpenResult.Opened) return; hartCommunicationLite.PreambleLength = 10; hartCommunicationLite.Receive += ReceiveValueHandle; hartCommunicationLite.SendingCommand += SendingValueHandle; while(true) { //die eingabe sollte in einem Format wie hier sein: "17:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0" //hier dar gestellt ist das Kommando 17 mit 24 Bytes die jeweils den Wert 0 ausweisen string input = Console.ReadLine(); if(input == "exit") break; //dieser Teil Funktioniert nur wenn die Eingabe korrekt ist string[] values = input.Split(new[] { ':' }); List<byte> databytes = new List<byte>(); for(int i = 1; i < values.Count(); i++) { //Fehler wenn einige eingaben nicht im Byte Format sind! databytes.Add((byte)values[i]); } hartCommunicationLite.SendAsync(values[0], databytes.ToArray()); } hartCommunicationLite.Receive -= ReceiveValueHandle; hartCommunicationLite.SendingCommand -= SendingValueHandle; } private void SendingValueHandle(object sender, CommandRequest args) { Console.WriteLine(string.Format("Sended: {0} {1} {2} {3} {4} {5}", args.PreambleLength, args.Delimiter, BitConverter.ToString(args.Address), args.CommandNumber, args.Data, args.Checksum)); } private void ReceiveValueHandle(object sender, CommandResult args) { Console.WriteLine(string.Format("Received: {0} {1} {2} {3} {4} {5} {6}", args.PreambleLength, args.Delimiter, BitConverter.ToString(args.Address), args.CommandNumber, args.Data,
BitConverter.ToString(new[] { args.ResponseCode.FirstByte, args.ResponseCode.SecondByte }),
args.Checksum)); } }
Weitere Informationen zu HART:
HART Kommunikations Protokoll - Wikipedia
Funktion
» Einfache Kommunikation mit Feldgeräten.
History
In den letzten Jahren entwickelte unsere Software Firma ein komplexes Kommunikationsframework für Feldgeräte. Diese Bibiliothek ist für den objektorientierten Ansatz optimiert. Wir stellen die Feldgeräte als komplexe DeviceModel's dar um
mit diesen zu kommunizieren. Für kleine und einfache Anwendungen ist dies oft mit zu viel Aufwand verbunden. Genau aus diesem Grund haben wir dieses HART Kommunikationsframework entwickelt.