DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve Integer values from a Binary/Hex file

Hi,
I have 15 .bin files , currently I am using notepad++ extension to view in hex.
In order to be precise , I have explained by problem in depth.
My purpose is to Retrieved Number of Packets and Parameters within each file. 

 

1) Packet Information

  1. In each binary file multiple packets of data is stored which is identified by length of packet which is 128 bytes.
    For Eg: After 128 bytes of data in ( Packet 1), 129th byte is 1st Word of (Packet 2).
    Each file contains multiple packet.
  2. Each packet contains data of similar parameters.
    For Eg: 1st Word (2 Bytes) ,2nd Word ,3 Word are 1st values of Parameter 1 , Parameter2 and Parameter3 respectively.
    Similary: 129th Word, 130th Word, 131st Word are 2nd values of Parameter 1 , Parameter2 and Parameter3 respectively. 

  3. In each packet 32bits form 1 Word (2 bytes each) and after each Word next 32 bits of new parameter is stored.

      For Eg: If a file has following value: ( If the a file is viewed in Hex in Notepad++)

0A27 B704 etc..

 

  • 0A27 is value of 1st variable which I want to retrieve in INT32 variable , after retrieving the value , complex mathematical calculations are to be applied like Fixed Pont Conversion , Calibration etc.
  • B704 is value of parameter 2 which I want to store in INT32 variable, after which different mathematical caluclation will be applied.

Questions

 

  1. Is it possible to use Diadem to form a Graph in which Parameter-1 information is displayed and organized for all packets in a binary file.
    For Eg: if file has 100 Packets => Length of the file will be => 2 bytes (1 word) x 64 Words X 100 => 12800 bytes
    There will be total 64 Parameters with each parameter having 100 values.
  2. My purpose is to plot graph of each of the parameters and name them individually and create a GUI , where user can select which parameter to view.

My challange

The files are large 400mB and even larger, I had written a routine in Labview using array to store the information its working but it gives memory full error if files are large.

  1. If the above doesn't my next approach will be to create a TDMS file may be, but I am not sure.
  2. Is there anybody who can guide in this scenario ?
    Thanks and Regards


    Data Viewed in HEX
    divgup1986_0-1658587965871.png

     

0 Kudos
Message 1 of 7
(1,498 Views)

A person stuck in similar problem, this has given motivation to choosed try Diadem once.

https://mathematica.stackexchange.com/questions/171892/how-to-read-this-dataset-with-dat-and-r64-fil...

0 Kudos
Message 2 of 7
(1,457 Views)

Sorry, I am a "LabVIEW guy" (where the solution would be absolutely trivial! 😄 ) and don't know DIADEM, but there are a few issues I would like to point out so others understand the problem better.

 


@divgup1986 wrote:
Subject: "Retrieve Integer values from a Binary/Hex file"

It's a plain binary file! Just looking at it in hexadecimal format using some tool does not make it HEX. (Hex is a format (displaying binary data using characters 0..F), not a datatype)

 


@divgup1986 wrote:

The files are large 400mB and even larger, I had written a routine in Labview using array to store the information its working but it gives memory full error if files are large.

400mB (millibytes) is 0.4Bytes, so this is really, really (really!!!!) small! 😄 If it is actually 400MB, you probably want to use LabVIEW 64bit if you desire to process and display all of it at once, but it seems you only want to process a subset. Done right, you will not run out of memory, but we of course have no idea what you actually did. (You need to limit data-copies, indicators, detours, memory thrashing, etc. The code needs to be elegant!). Maybe you want to revisit your LabVIEW approach. Feel free to post in the LabVIEW forum and we will try to help. If possible, attach a small version of one of your files, e.g. with only a couple dozens of 128byte records.

 

0 Kudos
Message 3 of 7
(1,447 Views)

Hi divgup1986,

 

To import data in DIAdem you can use a DataPlugin. On www.ni.com/dataplugins you find lots of common DataPlugins. If your file format is not supported there, you can create your own DataPlugin. In this case you need an exact description of the file format and some test files. Your description is good so far, but for me it is not clear what the exact data type the value in the binary file have.

 

Greetings

Walter

0 Kudos
Message 4 of 7
(1,418 Views)

 Maybe you want to revisit your LabVIEW approach. Feel free to post in the LabVIEW forum and we will try to help. If possible, attach a small version of one of your files, e.g. with only a couple dozens of 128byte records.

 


Hi, 
Thanks , I will shortly get back with the code, you are correct that I may not have written the code in the best way possible. I will provide as much data possible.

Thanks

0 Kudos
Message 5 of 7
(1,401 Views)

Hi,
I followed an internal example given in Diadem help for binary files, which says read the files as blocks.
Here is the attached code .

Option Explicit

Sub ReadStore(File)
Dim Block : Set Block = File.GetBinaryBlock()
Dim ChannelGroup : Set ChannelGroup = Root.Channelgroups.Add("MyChannelGroup")

Dim Channel1 : Set Channel1 = Block.Channels.Add("Channel1", eI16)
Dim Channel2 : Set Channel2 = Block.Channels.Add("Channel2", eI16)
Dim Channel3 : Set Channel3 = Block.Channels.Add("Channel3", eI16)
Dim Channel4 : Set Channel4 = Block.Channels.Add("Channel4", eI16)

ChannelGroup.Channels.AddDirectAccessChannel(Channel1)
ChannelGroup.Channels.AddDirectAccessChannel(Channel2)
ChannelGroup.Channels.AddDirectAccessChannel(Channel3)
ChannelGroup.Channels.AddDirectAccessChannel(Channel4)


End Sub


Using above script is given in example: 3, and it does following

divgup1986_2-1658910326679.png



Using above example, I am able see the values, as per required format : i.e First 16 bytes to Channel 1( value 1), next 16 Bytes to channel 2 ( value 1) as given in the example.

divgup1986_3-1658914377751.png

 


Next Step - 1
Now , I am stuck at finding a code to create a particular number of channels in a loop ( for eg: 64 channels) as given in above code using

Set Channel1 = Block.Channels.Add("Channel1", eI16

 and add those channels to File using following command.

ChannelGroup.Channels.AddDirectAccessChannel(Channel1)

Next Step - 2

Once , the given number of channels will be created, I have to make algorithms to convert binary value to in each channel with the corresponding Mathematical Algorithm.

Is there any way possible to store different mathematical algorithms ( for Eg: we have 64 channels, so 64 mathematical algortihms).
While the Step-1 script will be running , while assigning the values to channels , corresponding algoithm will be selected and applied to that channel from a data base of algortihms.


Next-3
As type of algorithms are fixed, For: Eg scale by 90 , left shift by 4 and then scale by 120 etc..

My next step would be to create a GUI , where user can select algorithms against each channel and then , when a binary file is loaded , it will be converted directly into readings and can be viewed on reports.

Thanks for your reply.

0 Kudos
Message 6 of 7
(1,395 Views)

Hi,
I have created a post in Labview Forum , as there the approach is different.
Kindly have a look , I have also shared, snippets, VI and two sample files.

https://forums.ni.com/t5/LabVIEW/Contenating-BIN-files-similar-to-R16-format-to-Graph/m-p/4245556/hi...

Thanks

0 Kudos
Message 7 of 7
(1,388 Views)