Read and write to txt file in HLA

I am trying to make an HLA and I would like to read from a txt file and output a txt file. which gives permission errors. I can solve this by running as admin and changing file permissions but this is cumbersome. Is there a better way to do this?

Hi @daniel.vo, the permissions should be dependent on the user that launches Logic 2. Does the user have permission to read/write from the file and directory you are interacting with? If you try doing the same thing from a Python script outside of Logic 2, does it work?

Ryan

Yes, I can do this with python scripts outside of Logic 2. I can run it in Visual studio and the python program by itself with no issue. The weird thing is that even If I run logic 2 as admin and make a txt file and write to it, I need to go into the security settings in order to edit the txt file. Can someone confirm if they are able to get txt read/writes in HLAs working? If others are able to get it working it’s probably an issue on my end.

@daniel.vo This works for me in 2.3.59 on Windows using the following code. Note that I am using an absolute path instead of a relative path - a relative path will be relative to the Logic 2 process’s working directory (in my case this would be C:\Program Files\Logic\, which will not be writeable if not running as admin).

from saleae.analyzers import HighLevelAnalyzer, AnalyzerFrame
import os.path


class Hla(HighLevelAnalyzer):
    def __init__(self):

        path = os.path.expanduser('~/hla_file.txt')
        print("Filepath: ", path)

        with open(path, 'w') as f:
            f.write('test string')

        with open(path) as f:
            print('contents of ~/hla_file.txt: ', f.read())

    def decode(self, frame: AnalyzerFrame):
        pass

You can see the output in the Logic 2 terminal:

1 Like

Okay I see what I was doing wrong, I was using the relative path instead of the absolute path. Using the absolute path works for me. Thanks for the help!

1 Like