Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrument.write_raw() and term_char #13

Open
razed11 opened this issue Feb 13, 2016 · 0 comments
Open

Instrument.write_raw() and term_char #13

razed11 opened this issue Feb 13, 2016 · 0 comments

Comments

@razed11
Copy link

razed11 commented Feb 13, 2016

I'm using Python 3.5 on Ubuntu.

I modified this routine to show what I think it should be. Before it was flags = OP_FLAG_TERMCHAR_SET if a terminating char exists but was immediately followed by flags = 0.

But I'm also confused by the behavior if term_char is set. It looks like the intent is the convert it to an integer than append to data. I've been passing bytes objects to this routine. This will fail when it attempts data += term_char. Also you cannot specify term_char as a single element bytes literal such as b'\r'.

If the encoding is assumed to be 'UTF-8' anyway shouldn't this line simply be ord(term_char)?

I might also change the if self.term_char is not None to if self.term_char for readability/simplicity.

    def write_raw(self, data):
        "Write binary data to instrument"
        if self.link is None:
            self.open()

        # TODO: Test
        flags = 0

        if self.term_char is not None:
            flags |= OP_FLAG_TERMCHAR_SET
            term_char = str(self.term_char).encode('utf-8')[0]
            data += term_char

        # Was this: flags = 0

        num = len(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant