0
$\begingroup$

Is there any way to at least read the text from the dat file. I have its corresponding mdf file hence I know what all data and columns are there in it. How do I figure out the contents in my dat file. Because all that I am getting currently is some gibberish even if I am opening it in binary mode.

from asammdf import MDF
dat_file = r"C:\Users\HPO2KOR\Desktop\Work\data1.dat"
mdf_file = r"C:\Users\HPO2KOR\Desktop\Work\data1.mdf"
df = mdf.to_dataframe()
mdf = MDF(mdf_file)
df.head()

which gives me enter image description here

How do I read the same data from the dat file, is there any library or code for the same?

And when I am opening the same in binary mode I am getting

data = open(dat_file, "rb")
data.readlines()

which is giving me

b'|CF,2,1,1;|CK,1,3,1,1;\r\n',
 b'|NO,1,7,1,0,,0,;\r\n',
 b'|NL,1,10,1252,0x407;\r\n',
 b'|CT,1,41,0,6,Bench#,24,Korrosionstest 15A046-01,0,;\r\n',
 b'|CT,1,30,0,11,StartOfTest,8,06/30/17,0,;\r\n',
 b'|CT,1,58,0,10,ResultPath,36,c:\\korrosionstest\\daten\\#170161-OR02,0,;\r\n',
 b'|CT,1,59,0,11,GraphicPath,36,c:\\korrosionstest\\daten\\#170161-OR02,0,;\r\n',
 b'|CT,1,31,0,15,GraphicBaseName,5,736_2,0,;\r\n',
 b'|CT,1,26,0,10,PartNumber,5,736_2,0,;\r\n',
 b'|CT,1,31,0,9,VA-Nr. GS,11,170161-OR02,0,;\r\n',
 b'|CT,1,62,0,9,VA-Nr. CC,42,TO_ENV_2017_G2_C1_Platform_CC-122164-03-08,0,;\r\n',
 b'|CT,1,24,0,6,Tester,8,Behrendt,0,;\r\n',
 b'|CT,1,32,0,15,Test Department,6,GS/ETR,0,;\r\n',
 b'|CG,1,5,1,1,1;\r\n',
 b'|CD,1,16,1E-2,1,1,s,0,0,0;\r\n',
 b'|NT,1,27,30, 6,2017,14,25,15.8050001;\r\n',
 b'|CC,1,3,1,1;\r\n',
 b'|CP,1,16,1,2,4,16,0,0,1,0;\r\n',
 b'|Cb,1,33,1,0,1,1,0,11718,0,11718,1,5E-3,0,;\r\n',
 b'|CR,1,30,1,6.103888176768602E-3,0,1,1,A;\r\n',
 b'|CN,1,28,0,0,0,16,ai_iB1_Strom_ECU,0,;\r\n',
 b'|CG,1,5,1,1,1;\r\n',
 b'|CD,1,16,1E-2,1,1,s,0,0,0;\r\n',
 b'|NT,1,27,30, 6,2017,14,25,15.8050001;\r\n',
 b'|CC,1,3,1,1;\r\n',
 b'|CP,1,16,2,2,4,16,0,0,1,0;\r\n',
 b'|Cb,1,37,1,0,2,1,11718,11718,0,11718,1,5E-3,0,;\r\n',
 b'|CR,1,30,1,3.662332906061161E-3,0,1,1,V;\r\n',
 b'|CN,1,31,0,0,0,19,ai_iB1_Spannung_UBB,0,;\r\n',
 b'|CG,1,5,1,1,1;\r\n',
 b'|CD,1,16,1E-2,1,1,s,0,0,0;\r\n',
 b'|NT,1,27,30, 6,2017,14,25,15.8050001;\r\n',
 b'|CC,1,3,1,1;\r\n',
$\endgroup$
1
  • $\begingroup$ Would it be possible to share the data so we could try it out? $\endgroup$ Aug 8, 2021 at 5:52

2 Answers 2

0
$\begingroup$

You can try:

np.fromfile(yourfilepath, dtype="byte")

to read content from .dat and then load as a Numpy array.

$\endgroup$
1
  • $\begingroup$ This does not seem to deal with the MDF formatted data. How does it help that? $\endgroup$
    – Stephen Rauch
    Mar 7, 2021 at 17:46
-1
$\begingroup$

you can try the following code:

dat_file = r"C:\Users\HPO2KOR\Desktop\Work\data1.dat"   

with open(dat_file, 'r') as file:
    text = file.read()
    print(text)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.