In general, I am trying to read the .trc file. I decided to use the answer from the question .trc extension. How to read and display correctly in Open_GL?

"There is a python project github.com/yetifrisstlama/readTrc - Cerbo 13 Apr at 6:21"

But when it starts, it complains to me and gives an error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 18: ordinal not in range(128) 

.

 # -*- coding: utf-8 -*- """ # -*- coding: cp1251 -*- Little helper function to load data from a .trc binary file. This is the file format used by LeCroy oscilloscopes. M. Betz 09/2015 """ #form __fiture__ import with_statement #для питон 2.5 import datetime import numpy as np import struct print 1 fName = "Newfile1a.trc"; with open(fName, "rb") as fid: #data = fid.read(50).encode() data = fid.read(50).decode() wdOffset = data.find('WAVEDESC') print 2 

P.S. Spyder (IDE) is very good, is there any similar crap on Qt 4.8 ?????

  • Try decode to specify the encoding of your file. And always lay out the full stack, and not just the error message itself - I almost suggested adding the encoding attribute in open until I noticed that the rb mode was gil9red
  • I do not know in what encoding .trc files are laid. The only thing I know is that it is the (format) database in which the header of the file goes at the beginning. There are clearly used variables of different formats. From byte to double And after reading the title reveals a mechanism for reading the basic information. BUT I have a problem at the very beginning; _; . - timob256
  • To find out what format, you can open, for example, Notepad ++ and see. Or in the code specify in decode() specify different encodings until the error disappears. Try utf-8 or latin1 - gil9red

1 answer 1

There is one of two things: either your file does not meet the standard, or you have been advised to have a bad parser.

From the description of the .trc format:

<0> DESCRIPTOR_NAME: string; the first 8 chars are always WAVEDESC

<16> TEMPLATE_NAME: string

<32> COMM_TYPE: enum; chosen by remote command COMM_FORMAT

and the utility tries to read 50 bytes at once and decode them:

 data = fid.read(50).decode() wdOffset = data.find('WAVEDESC') 

In this format, the string type is described as:

string - up to 16-character name terminated with a null byte

those. apparently, this is a type with a fixed size (in bytes).

I can advise you to correct the utility and make it so that it does not read 50 bytes, but only 16 (or even 8):

 data = fid.read(16).decode() 

it should not break the rest of the logic.

And yes, according to the utility author, it was tested on Python 3, so you should use the third version until it takes off. And then it will be possible to try to run at 2.6.