Comments (12)
Anyone?
from grabserial.
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.
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.
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.
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.
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.
Here you go.
from grabserial.
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.
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:
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.
from grabserial.
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.
That works perfectly. Thank you so much. Could you please see my other issue too: #55 (this one is less critical)
from grabserial.
Stale issue message
from grabserial.
Related Issues (20)
- grabserial as HEX dump data logger HOT 12
- sys.stdout is flushed instead of outputfd HOT 2
- Ignore partial lines on invocation HOT 1
- Logging binary UART stream to file not working, only with --hex-output option HOT 9
- how to send special characters as -c arg? HOT 2
- Shebang Python location could cause not find the interpreter HOT 3
- Output nothing when command larger then 25 characters HOT 1
- Can't send command ending with \r\n HOT 1
- The --nodelta option only works with --systime HOT 2
- Triggering newline on ']' stop condition from buspirate i2C snoop macro HOT 1
- putserial - SyntaxError: multiple exception types must be parenthesized HOT 1
- High CPU usage on Pi Zero 2 W HOT 1
- -n or --nodelta not working HOT 2
- Created file location HOT 5
- Why there is no output? HOT 5
- Is there an error log to check? (Multiple output files being created) HOT 2
- grabserial syntax HOT 2
- Is it able to handle ansi escape sequences? HOT 2
- Date in filepath no longer works HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grabserial.