fasteddy516 / SimplySerial

A windows console application for serial communications.
MIT License
180 stars 22 forks source link

Command line option to log all serial data to a file #9

Closed unwiredben closed 3 years ago

unwiredben commented 3 years ago

I'd like to use this to monitor several embedded devices connected over COM ports to my Windows box. This works great for getting the data into a terminal window, but I'd like a way to specify a file where all the received bytes can also be written for later analysis. I'd suggest

with -log replacing the file and -logappend appending to an existing file

fasteddy516 commented 3 years ago

I assume for your use case you're ok with the terminal window/process remaining open for the duration of the session you want to log. (SimplySerial is a C# console application with no provisions for running in the background.) If a -log option was implemented such that the application behaves exactly as it does now, but writes everything that it prints on the screen to a file as well, would that suffice?

unwiredben commented 3 years ago

Yep, that's exactly what I want -- basically, I'm debugging devices that log a lot of data, so want to be able to go back and check the logs if something goes wrong without worrying about the terminal scrollback.

fasteddy516 commented 3 years ago

I've started working on this, and hope to have it done in the next day or two - it depends on how quickly I can get up to speed on C# file operations. The command line arguments will be:

-log:<path to log file> -logmode:<append | overwrite>

If no logmode is specified, it will default to overwrite mode.

Hamanstone commented 3 years ago

I am so glad to hear that this project still activity. well anyway, you guys did a great job. I love this project so much. Thank you guys.

fasteddy516 commented 3 years ago

I've posted SimplySerial 0.5.0-beta in the releases section with the requested logging functionality. You can give it a try and let me know if you run into any issues. There were a fair amount of under-the-hood changes required throughout the code, and my experience with C#/.NET file operations is minimal, so I've marked it as a pre-release for now, and will issue a full release after there has been sufficient real-world testing.

unwiredben commented 3 years ago

Initial test looks good, but I think you should add some sort of timeout to the write thread -- for example, if there's no serial data in 500ms, flush the buffer. I often see bursty serial traffic, and I was noticing that I could easily have a few lines left off the end when I did a "type device.log" even after a few seconds with the default 4096 bytes.

unwiredben commented 3 years ago

This is weird -- Windows Defender just quarantined ss.exe from this release as an instance of Trojan:Script/Wacatac.B!ml

I searched for more information and didn't find much, just some forums posts about false positives.

fasteddy516 commented 3 years ago

I've posted v0.5.0-beta.2, which automatically flushes the buffer if no serial data is received for 2 seconds or more. Hopefully this resolves the issue you were having with data getting stuck in buffer limbo.

I'm not sure what to say about the Windows Defender bit, other than that at this point I suspect it is just a false positive. Interestingly, I ran the exe file through the VirusTotal and MetaDefender online scanning tools, and both gave it a clean bill of health from every scanning platform they use except for Cyren, which flags it as W32/MSIL_Razy.O.gen!Eldorado. I went back and ran the v0.4.1 exe through the same tools, and got the same results.

Out of curiosity, which version of the SimplySerial installer did you use? (user, system or standalone)

fasteddy516 commented 3 years ago

Also just an fyi - I am considering removing the command-line argument for setting the log buffer size, as the new timeout functions make it unnecessary. I would just set the buffer size to something relatively high to prevent high bandwidth serial traffic from causing tons of disk writes, and allow the timeouts to take care of flushing the buffer within a reasonable amount of time for slow/sporadic traffic.

unwiredben commented 3 years ago

I used the system installer. I think the "ml" at the end of that is "machine learning", which means it looked for a pattern it didn't like. On my own system, I just added it to the whitelist and haven't had a problem.

fasteddy516 commented 3 years ago

I've done a fair bit of testing with the new logging functionality over the last few days, and am happy with how it is working. I've published the release version of 0.5.0, which does fix one bug with regards to the automatic buffer flushing, so it is worth updating,

I'd still love to know what behaviour triggered Windows Defender, but I haven't been able to duplicate that on any of my machines or SimplySerial installations. Regardless, I'm planning on a fairly extensive re-write (for a number of reasons) for version 0.6.0, and am also hoping to learn enough about Github Actions to set up an automated build process and remove my machine from the build process completely.

unwiredben commented 3 years ago

It's been working very well, thanks so much!