Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

GZIP compress/uncompress of string using .NET

Overview

This example's functions will compress and decompress a LabVIEW string using the .NET framework.

 

 

Description

The inputs and outputs are strings, there is no file I/O involved. Applications include large strings transfer over slow connections or storing large strings (XML) in a database BLOB.

For the compression VI:

1. Call the constructor of the MemoryStream Class located in mscorlib 2.0.0.0 >> System.IO >> MemoryStream to create a stream whose backing store is memory
2. Call the constructor of GZipStream Class that provides methods and properties used to compress and decompress streams.
3. Use the GZipStream Invoke methods to write the data to be compressed
4. Use the MemoryStream Invoke Method to retrieve the compressed data

 

For the decompression VI

1. Call the constructor of the MemoryStream Class located in mscorlib 2.0.0.0 >> System.IO >> MemoryStream to create a stream whose backing store is memory
2. Call the constructor of GZipStream Class that provides methods and properties used to compress and decompress streams in Decompress mode
3. Use the GZipStream Invoke methods to read the decompressed data

 

 

Requirements

LabVIEW 2012 (or compatible)

.Net Framework 3.5 (or compatible)

 

 

 

Steps to Implement or Execute Code

1. Download the folder "dotNet Compress&Decompress Strings_LV2012_NI Verified"

2. Open the VI "dotNET Compress String"

3. Run the VI

4. Note the compressed string and copy it

5. Open the VI "dotNET Decompress String"

6. Paste the compressed string in GZIP Compressed String

7. Run the VI and note the decompressed string

 

 

Additional Information or References

4/1/2015 - Added LV2014 Versions that use .NET 4.0 Assemblies

 

Block Diagram of Compression VI

BD Compression.PNG

Front Panel of compression VI

FP Compression.PNG

 

Block Diagram of decompression VI

BD Decompression.PNG

 

Front Panel of decompression VI

FP Decompression.PNG

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Comments
Active Participant Neil.Pate
Active Participant

Nice, another one for the toolbox

nrp
CLA
Member Cardinal1664
Member

It seems that the GZIP isn't working with dotnet 4.0.

I have installed Labview 2014 SP 1 with dotnet 4.0 and in the decompressing VI it get this Error:

Invoke Node System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht.

          Inner Exception: System.InvalidOperationException: Das Lesen aus dem Komprimierungsstrom wird nicht unterstützt. <append><b>System.InvalidOperationException</b> in Global_Library.lvlib:gZip Decompress String.vi

Does anyone have a Solution for this Error?

Solved:

With the LV2014 VI's it works!!

Thanks

Member NoName1771
Member

The Decompress process doesn't work with LV2014.

The Error is: code 1172

source:

Invoke Node System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht.

(A call aim has caused a special mistake.)


    Inner Exception: System.InvalidOperationException: Das Lesen aus dem Komprimierungsstrom wird nicht unterstützt. <append><b>System.InvalidOperationException</b> in dotNET Decompress String.vi->test.vi

(The reading from the compression stream is not supported.)

Does anyone have a Solution for this Error?

System: I use LavVIEW 2014 SP1 64bit in the 14.0.1 Verison

Active Participant PhillipBrooks
Active Participant

If you are having a problem with .NET 4.0, please see this forum entry. At the bottom is a DLL wrapper than can help with decompress.

There is an CAR (#493662) for this problem.

http://forums.ni.com/t5/LabVIEW/Weird-behaviour-with-NET-constructor-node-and-GZipStream/m-p/2900906...


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Member NoName1771
Member

I downloaded the GZip_compress_decompress.vi from Sev_K (Message 26 from 27 from the link of comment 4) but now I am getting the Error 1386 :

Error 1386 occurred at Constructor Node in GZip_compress_decompress.vi

LabVIEW: The specified .NET classis not available in LabVIEW.

SOLUTION: The GZip_Lib.dll file was missing, so LabVIEW didn't know where to look.

Member samsharp99
Member

If you are looking for a solution that doesn't require .NET and/or works on RT targets - I have written a couple of VIs which you can find here.