GithubHelp home page GithubHelp logo

borisgerretzen / zs2decode Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 55 KB

Decoder for ZwickRoell zs2 files

License: GNU Lesser General Public License v2.1

C# 100.00%
xml csharp zwick zwickroell zs2 file-conversion

zs2decode's Introduction

Zs2Decode

Build Status

This is an implementation of a decoder for ZwickRoell .zs2 files built in C#. Currently the project supports converting .zs2 files to .xml, and getting the sensor data from a .zs2 file. As for decoding the .zs2 file, not all elements are correctly decoded, all elements starting with QS_, except QS_TextPar and QS_ValPar, currently have the bytes from the binary as value.

I would not have been able to make this without Chris Petrich's great documentation, thanks Chris!

How to install

To install using Nuget, run Install-Package Zs2Decode in the package manager console. The Nuget page can be found here.

How to use

These examples can also be found working in the Demo project included in the repository.

Export to xml

using System.Xml.Serialization;
using Zs2Decode;

// Files
var inputFile = "./input.zs2";
var outputFile = "./output.xml";

// Get data
var reader = new DataReaderZs2(inputFile);
var rootChunk = reader.ReadData();

// Write data to xml
var writer = new XmlSerializer(typeof(Chunk));
var file = File.OpenWrite(outputFile);
writer.Serialize(file, rootChunk);
file.Close();

Get sensor data

using System.Xml.Serialization;
using Zs2Decode;

// Files
var inputFile = "./input.zs2";
var outputFile = "./output.xml";

// Get data
var reader = new DataReaderZs2(inputFile);
var rootChunk = reader.ReadData();

// Sensors are stored in Sensors variable
var sensors = rootChunk.Sensors;

zs2decode's People

Stargazers

 avatar

Watchers

 avatar

Forkers

jespernjessen

zs2decode's Issues

StartPosition is wrong

Currently the StartPosition variable in the Chunk class is being set to the wrong number.

Different Encoding

The value encoding is just in ASCII, so values of some language didn´t look very nice. Can you add the choice of different encodings?
Like this:

In Zs2Decode.cs (Add a RootChunk methode with encoding parameter)

public RootChunk ReadData(Encoding encoding)
    {
        var bytes = GetStream().ToArray();

        var firstFour = bytes.Take(4).ToArray();
        if (!firstFour.SequenceEqual(new byte[] {
                0xAF, 0xBE, 0xAD, 0xDE
            }))
        {
            throw new FormatException("Did not find correct header bytes in file");
        }
        var fac = new ChunkFactory(bytes.Skip(4).ToArray(), encoding);
        var output = fac.GenerateChunks();
        return output;
    }

In ChunkFactory.cs (Add this constructur)

public ChunkFactory(byte[] bytes, Encoding encoding)
    {
        data = new DataHolder(bytes, encoding);
    }

In DataHolder.cs

      private Encoding _encoding= Encoding.ASCII; //Default ASCII
	...
      public DataHolder(IEnumerable<byte> collection, Encoding encoding) : base(collection) 
      { 
          _encoding = encoding;
      }
	
      public string GetString(int len, bool remove0x00 = false) 
      {
          var mult = remove0x00 ? 2 : 1;
          var bytes = DequeueChunk(len * mult).Where(b => b != 0x00).ToArray();
          //return Encoding.ASCII.GetString(bytes);
          return _encoding.GetString(bytes);
       }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.