Giter Club home page Giter Club logo

Comments (12)

janipewter avatar janipewter commented on August 16, 2024

Anyone?

from grabserial.

tbird20d avatar tbird20d commented on August 16, 2024

Sorry - I missed this earlier. grabserial tries to preserve data as best it can from the serial port. It does not have any character-level filtering option. I primarily use Linux, and on Linux this would be trivial to strip from standard out using 'tr' or from the log file using 'sed'. This is somewhat more difficult in Windows, but you could look at this https://stackoverflow.com/questions/29291986/what-is-the-tr-command-in-windows and see if it does what you want.

from grabserial.

janipewter avatar janipewter commented on August 16, 2024

Thank you for the reply. I agree it is best used on Linux, but unfortunately in this specific use case I have to use Windows 10. I have looked into the tr option and it seems all avenues are too hack-y for my liking. Regardless I want to use grabserial's built-in logging rather than messing around with sed etc after the fact.

I think the underlying issue is caused perhaps due to each line of data having a checksum. I am not proficient enough in Python to fully understand the code, but is there a way I could modify the grabserial code to not print the control characters? I don't need this added to the public version; I am happy to keep a modified version locally.

Thanks again

from grabserial.

tbird20d avatar tbird20d commented on August 16, 2024

OK - no problem. I wrote a very simple (and very specific to your use-case) fix, and put this on the branch "skip_nonprintable". The commit is here: e2cfafe If you see other control characters in your output that you want to skip, you should be able to add them to that if statement to also skip those. Please give it a try and let me know if it works for you.

from grabserial.

janipewter avatar janipewter commented on August 16, 2024

Thank you. I switched to that branch and gave it a try and the characters are still printed and logged. Do you have any suggestions of what else I could try? No need to push commits, I am happy to make changes locally for testing.

from grabserial.

tbird20d avatar tbird20d commented on August 16, 2024

Well that's odd. Can you attach a log? I'd like to look at the contents and see if I can figure out what's going on. Thanks.

from grabserial.

janipewter avatar janipewter commented on August 16, 2024

202103162100-Wind.txt

Here you go.

from grabserial.

tbird20d avatar tbird20d commented on August 16, 2024

I looked at a hexdump of the log:
00000000 5b 54 75 65 20 4d 61 72 20 31 36 20 32 31 3a 34 |[Tue Mar 16 21:4|
00000010 38 3a 33 30 2e 34 36 32 33 38 38 20 32 30 32 31 |8:30.462388 2021|
00000020 5d 20 4d 2c 2b 30 31 34 2e 33 37 2c 30 30 2c 03 |] M,+014.37,00,.|
00000030 30 46 0a 5b 54 75 65 20 4d 61 72 20 31 36 20 32 |0F.[Tue Mar 16 2|
00000040 31 3a 34 38 3a 33 30 2e 35 34 32 39 33 38 20 32 |1:48:30.542938 2|
00000050 30 32 31 5d 20 02 51 2c 2d 30 30 31 2e 35 33 34 |021] .Q,-001.534|
00000060 2c 2b 30 30 30 2e 32 39 30 2c 2b 30 30 30 2e 35 |,+000.290,+000.5|
00000070 30 39 2c 4d 2c 2b 30 31 34 2e 33 37 2c 30 30 2c |09,M,+014.37,00,|
00000080 03 30 33 0a 5b 54 75 65 20 4d 61 72 20 31 36 20 |.03.[Tue Mar 16 |

and the codes are clearly ASCII 02s and 03s, so the filtering code I provided should work.

I wrote a test program using the same logic, to output

the log with the codes stripped, and
it worked. Here is the test program:

#!/usr/bin/python

import sys

fd = open("sl.txt", "r")
while True:
x = fd.read(1)
if not x:
break
if x == "\002" or x == "\003":
continue
sys.stdout.write(x)
sys.stdout.flush()

fd.close()


I'm at a loss for why the grabserial code failed to strip the codes. Can you please check and make sure you were
running the version of grabserial from the strip_nonprintable branch?

Maybe add the following to debug the code:

Where the STX and ETX check are, add some extra prints:

        # if we didn't read anything, loop
        if len(x) == 0:
            continue

        print(" %02X" % ord(x))

        # ignore STX and ETX control characters
        if x == '\002' or x == '\003':
            print("skipping one")
            continue

Let me know what you see.

from grabserial.

janipewter avatar janipewter commented on August 16, 2024

I'm definitely on the right branch, I can see the extra code in the script. When I ran it with the debug prints in, this happened:

Screenshot 2021-03-17 185514

Interestingly the logging was unaffected (new logfile attached). I commented out the print(" %02X" % ord(x)) line which unbroke the printed output. The control characters are still in stdout and the logfile.

202103171800-Wind.txt

from grabserial.

tbird20d avatar tbird20d commented on August 16, 2024

OK - the only thing I can think of is that maybe the literals are not working in Windows the way they work in Linux.

Can you try this instead:

Replace:
# ignore STX and ETX control characters
if x == '\002' or x == '\003':
continue

with
# ignore STX and ETX control characters
if ord(x) == 2 or ord(x) == 3:
continue

from grabserial.

pml-jpe avatar pml-jpe commented on August 16, 2024

That works perfectly. Thank you so much. Could you please see my other issue too: #55 (this one is less critical)

from grabserial.

github-actions avatar github-actions commented on August 16, 2024

Stale issue message

from grabserial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.