Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
f178426
This commit introduces a complete, user-friendly Tkinter GUI for the …
KillaVolt Dec 8, 2025
8b56fd6
Updated GUI for sizing, attempting to make it more compact
KillaVolt Dec 8, 2025
ae028ad
Cleaned up repo of files that are not necessary for the GUI to funciton.
KillaVolt Dec 13, 2025
d3c0333
Added .gitignore, Help Contents.txt, M18.png, and updated the GUI.
KillaVolt Dec 14, 2025
738d619
Add comprehensive comments to M18 scripts
KillaVolt Dec 14, 2025
1818b26
Merge pull request #1 from KillaVolt/add-comments-and-docblocks-to-m1…
KillaVolt Dec 14, 2025
8950377
Began work on advanced GUI with full settings, ported to C#.
KillaVolt Dec 14, 2025
0a5d3c4
Populated bare C# GUI with the requisite elements to use all funcitons.
KillaVolt Dec 14, 2025
2aa33c3
Syncing repositories.
KillaVolt Dec 14, 2025
d09bc16
Add helper to run python script
KillaVolt Dec 14, 2025
4bdfbee
Merge pull request #2 from KillaVolt/add-function-to-run-python-scrip…
KillaVolt Dec 14, 2025
d9ee17e
Add verbose serial port management
KillaVolt Dec 14, 2025
06a9c54
Merge pull request #3 from KillaVolt/implement-serial-port-management…
KillaVolt Dec 14, 2025
8820ac7
Add output separator to serial logs
KillaVolt Dec 14, 2025
2b971e9
Merge branch 'master' into implement-serial-port-management-in-winfor…
KillaVolt Dec 14, 2025
b0ed607
Merge pull request #4 from KillaVolt/implement-serial-port-management…
KillaVolt Dec 14, 2025
594cdc7
Updated .gitignore
KillaVolt Dec 14, 2025
9f53eb3
Clean up build artifacts and update .gitignore
KillaVolt Dec 14, 2025
08a3091
Merge branch 'master' of https://github.com/KillaVolt/m18-protocol-gui
KillaVolt Dec 14, 2025
224c573
Add System.IO.Ports and System.Maintainence
KillaVolt Dec 14, 2025
a6eb4d0
Minor visual tweaks.
KillaVolt Dec 14, 2025
f0f8b80
Improve log formatting
KillaVolt Dec 14, 2025
9fd4a57
Merge pull request #5 from KillaVolt/update-richtextbox-logging-forma…
KillaVolt Dec 14, 2025
cd81721
Minor visual tweaks, updated basic instructions in output window.
KillaVolt Dec 14, 2025
b85603f
Add C# M18 protocol implementation
KillaVolt Dec 14, 2025
871be42
Merge pull request #6 from KillaVolt/port-m18-python-class-to-c#-2025…
KillaVolt Dec 14, 2025
99d7044
Minor tweaks.
KillaVolt Dec 14, 2025
b92b0e9
Add async protocol handlers for Simple tab controls
KillaVolt Dec 14, 2025
7b803bd
Merge pull request #7 from KillaVolt/implement-event-handlers-for-sim…
KillaVolt Dec 14, 2025
39e27c4
Add UI-controlled TX/RX logging
KillaVolt Dec 14, 2025
d710c14
Merge pull request #8 from KillaVolt/update-checkbox-control-for-tx/r…
KillaVolt Dec 14, 2025
0a211db
Added temporary debugging output window.
KillaVolt Dec 14, 2025
f4283da
Add comprehensive debug logging
KillaVolt Dec 14, 2025
701c7af
Merge pull request #9 from KillaVolt/implement-logging-for-winforms-a…
KillaVolt Dec 14, 2025
c04195b
Add concise debug logging for key actions
KillaVolt Dec 14, 2025
79efa26
Merge pull request #10 from KillaVolt/update-logging-for-button-and-k…
KillaVolt Dec 14, 2025
abb4dce
Added Test Device button to check the connected device is correct.
KillaVolt Dec 14, 2025
7b71084
Improve serial port selection and testing
KillaVolt Dec 14, 2025
df0747a
Merge pull request #11 from KillaVolt/update-serial-port-dropdown-wit…
KillaVolt Dec 14, 2025
44b45a9
Enhance Simple tab serial handling
KillaVolt Dec 14, 2025
2ed8f29
Merge pull request #12 from KillaVolt/implement-simple-tab-functional…
KillaVolt Dec 14, 2025
fc2e940
Handle WMI failures when refreshing serial ports
KillaVolt Dec 14, 2025
59176b0
Merge pull request #13 from KillaVolt/investigate-error-in-screenshot…
KillaVolt Dec 14, 2025
9086799
Improve serial port detection and logging
KillaVolt Dec 16, 2025
a4753e6
Merge pull request #14 from KillaVolt/update-serial-port-combobox-log…
KillaVolt Dec 16, 2025
9082fc9
Improve serial port enumeration via SetupAPI
KillaVolt Dec 16, 2025
96c4b6d
Merge pull request #15 from KillaVolt/update-serial-port-discovery-lo…
KillaVolt Dec 16, 2025
fae5e26
Enhance serial port enumeration details
KillaVolt Dec 16, 2025
e8083bb
Merge pull request #16 from KillaVolt/enhance-serial-port-enumeration…
KillaVolt Dec 16, 2025
02bcf25
Better serial port naming.
KillaVolt Dec 16, 2025
9eae665
Visual tweaks.
KillaVolt Dec 16, 2025
24a9c55
Standardize serial port display formatting
KillaVolt Dec 16, 2025
d88ef2e
Merge pull request #17 from KillaVolt/revise-combobox-item-display-fo…
KillaVolt Dec 16, 2025
f21cd34
Changed serial port display names.
KillaVolt Dec 16, 2025
ec09777
Improve TX control logging and safe disconnects
KillaVolt Dec 16, 2025
823f844
Merge pull request #18 from KillaVolt/implement-logging-and-protocol-…
KillaVolt Dec 16, 2025
82e5e70
Minor change to error logging.
KillaVolt Dec 16, 2025
6156430
Implement full health report logic in C#
KillaVolt Dec 16, 2025
a32f319
Merge pull request #20 from KillaVolt/port-m18.py-health-report-to-c#…
KillaVolt Dec 16, 2025
3a67b91
Corrected some errors.
KillaVolt Dec 16, 2025
336b203
Improve serial reset reliability for health report
KillaVolt Dec 16, 2025
950fdc7
Merge pull request #21 from KillaVolt/port-m18.py-functions-to-c#-gui…
KillaVolt Dec 16, 2025
7b14965
Added Echo Test button for debugging.
KillaVolt Dec 17, 2025
0f1b679
Expose protocol serial port for diagnostics
KillaVolt Dec 17, 2025
9d87378
Merge pull request #22 from KillaVolt/expose-serialport-in-m18protoco…
KillaVolt Dec 17, 2025
a1869d4
Add comprehensive inline documentation
KillaVolt Dec 18, 2025
aa806a3
Merge pull request #23 from KillaVolt/add-comprehensive-documentation…
KillaVolt Dec 18, 2025
927174a
Added extensive comments.
KillaVolt Dec 18, 2025
f821969
Debugging
KillaVolt Dec 18, 2025
98e7235
Align C# protocol reset/read handling with Python
KillaVolt Dec 18, 2025
3224adc
Merge pull request #24 from KillaVolt/fix-c#-m18-protocol-to-match-py…
KillaVolt Dec 18, 2025
ce4282b
Removed Test Raw Echo button.
KillaVolt Dec 18, 2025
9e0d633
Align serial control line initialization with pyserial
KillaVolt Dec 18, 2025
d7eafc5
Merge pull request #25 from KillaVolt/modify-serialport-control-line-…
KillaVolt Dec 18, 2025
147923c
Mirror Python protocol flow in C#
KillaVolt Dec 18, 2025
9546a68
Merge pull request #26 from KillaVolt/rewrite-c#-serial-protocol-to-m…
KillaVolt Dec 18, 2025
7e230dd
Add protocol logger delegates and public logging flags
KillaVolt Dec 18, 2025
c8d35a4
Merge pull request #27 from KillaVolt/fix-missing-txlogger-and-rxlogg…
KillaVolt Dec 18, 2025
77987f5
Minor debugging.
KillaVolt Dec 18, 2025
bb28e35
Switch to FTDI D2XX driver and add raw log
KillaVolt Dec 18, 2025
c244fab
Merge pull request #28 from KillaVolt/port-m18.py-protocol-to-c#-usin…
KillaVolt Dec 18, 2025
60a6bc0
Debugging.
KillaVolt Dec 18, 2025
123b13d
Remove D2XX dependency in favor of SerialPort
KillaVolt Dec 18, 2025
9b4cf1c
Merge pull request #29 from KillaVolt/remove-ftdi-d2xx-references-fro…
KillaVolt Dec 18, 2025
6fa909a
Ensure SerialPort dependency is referenced and public
KillaVolt Dec 18, 2025
ef16c97
Merge pull request #30 from KillaVolt/update-project-to-use-system.io…
KillaVolt Dec 18, 2025
865891e
Use System.IO.Ports package reference
KillaVolt Dec 18, 2025
232405b
Merge pull request #31 from KillaVolt/update-project-to-use-system.io…
KillaVolt Dec 18, 2025
758e470
Log wire-format bytes and standardize hex output
KillaVolt Dec 18, 2025
9835b8e
Merge pull request #32 from KillaVolt/review-and-fix-serialport.write…
KillaVolt Dec 18, 2025
dc4e72a
Ensure serial commands use byte arrays and hex logging
KillaVolt Dec 18, 2025
099b710
Merge pull request #33 from KillaVolt/refactor-m18protocol.cs-command…
KillaVolt Dec 18, 2025
09ada2c
Match Python send logging order
KillaVolt Dec 18, 2025
d570b54
Merge pull request #34 from KillaVolt/examine-and-replicate-m18.py-be…
KillaVolt Dec 18, 2025
f1546d2
Use SerialPortStream for RJCP-based serial handling
KillaVolt Dec 18, 2025
6bf0476
Merge pull request #35 from KillaVolt/rewrite-m18protocol-using-rjcp.…
KillaVolt Dec 18, 2025
d948479
Integrate Python process controller
KillaVolt Dec 25, 2025
8ab932b
Merge pull request #36 from KillaVolt/implement-pythonprocesscontroll…
KillaVolt Dec 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Build results
bin/
obj/
*.exe
*.dll
*.pdb

# VS temporary files
.vs/
*.suo
*.user
*.userosscache
*.sln.docstates

# VS Code workspace
.vscode/

# Backup and cache
*.cache
*.dbmdl
*.bak
*.log
*.tlog

# Project-specific
*.ncb
*.sdf
*.opensdf
*.VC.db

# Others you mentioned
*.dtbcache.v2
*.futdcache.v2
*.suo
*.DocumentLayout*
*.metadata.*
*.projects.*
*.strings.*
M18Batte.C072E897.Up2Date
TempPE/

# System
__pycache__/
runtimes/
System.IO.Ports.dll
System.Management.dll
61 changes: 61 additions & 0 deletions AppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.IO;
using System.Text.Json;

namespace M18BatteryInfo
{
/// <summary>
/// Persists user configurable paths for the Python executable and m18.py script. Paths are stored
/// in a JSON file under the user's application data folder so they survive app restarts without
/// requiring registry edits or manual config tweaks.
/// </summary>
public class AppSettings
{
public string PythonExecutablePath { get; set; } = "python";
public string ScriptPath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "m18.py");

private static string SettingsFilePath =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "M18BatteryInfo", "settings.json");

/// <summary>
/// Load persisted settings from disk. If the file is missing or unreadable, defaults are
/// returned and a new settings file will be written the next time <see cref="Save"/> is called.
/// </summary>
public static AppSettings Load()
{
try
{
if (File.Exists(SettingsFilePath))
{
var json = File.ReadAllText(SettingsFilePath);
var settings = JsonSerializer.Deserialize<AppSettings>(json);
if (settings != null)
{
return settings;
}
}
}
catch
{
// If the file is malformed, fall back to defaults without throwing to keep the UI usable.
}

return new AppSettings();
}

/// <summary>
/// Persist the current settings to disk, creating the directory if needed.
/// </summary>
public void Save()
{
var directory = Path.GetDirectoryName(SettingsFilePath);
if (!string.IsNullOrWhiteSpace(directory) && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}

var json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(SettingsFilePath, json);
}
}
}
121 changes: 121 additions & 0 deletions Help Contents.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
Functions:
DIAGNOSTICS:
m.health() - print simple health report on battery
m.read_id() - print labelled and formatted diagnostics
m.read_id(output="raw") - print in spreadsheet format
m.submit_form() - prompts for manual inputs and submits battery diagnostics data

m.help() - this message
m.adv_help() - advanced help

exit() - end program

Advanced functions:
m.read_all() - print all known bytes in 0x01 command
m.read_all_spreadsheet() - print bytes in spreadsheet format

CHARGING SIMULATION:
m.simulate() - simulate charging comms
m.simulate_for(t) - simulate for t seconds
m.high_for(t) - bring J2 high for t sec, then idle

m.write_message(message) - write ascii string to 0x0023 register (20 chars)

Debug:
m.PRINT_TX = True - boolean to enable TX messages
m.PRINT_RX = True - boolean to enable RX messages
m.txrx_print(bool) - set PRINT_TX & RX to bool
m.txrx_save_and_set(bool) - save PRINT_TX & RX state, then set both to bool
m.txrx_restore() - restore PRINT_TX & RX to saved values
m.brute(addr_msb, addr_lsb)
m.full_brute(start, stop, len) - check registers from 'start' to 'stop'. look for 'len' bytes
m.debug(addr_msb, addr_lsb, len, rsp_len) - send reset() then cmd() to battery
m.try_cmd(cmd, addr_h, addr_l, len) - try 'cmd' at [addr_h addr_l] with 'len' bytes

Internal:
m.high() - bring J2 pin high (20V)
m.idle() - pull J2 pin low (0V)
m.reset() - send 0xAA to battery. Return true if battery replies wih 0xAA
m.get_snapchat() - request 'snapchat' from battery (0x61)
m.configure() - send 'configure' message (0x60, charger parameters)
m.calibrate() - calibration/interrupt command (0x55)
m.keepalive() - send charge current request (0x62)




@echo off

echo ***************************************************
echo ** Runs m18.py with spreadsheet output and **
echo ** copies to clipboard. You will not see output, **
echo ** just a completion message. Then you can **
echo ** 'ctrl+v' into a spreadsheet **
echo ** **
echo ** THIS WILL TAKE ~10 SECONDS **
echo ** **
echo ** RIGHT-CLICK AND EDIT .BAT FILE. **
echo ** CHANGE "--port COM5" to where your adapter is **
echo ** (you can delete this message) **
echo ***************************************************

python.exe .\m18.py --ss --port COM5 | clip.exe

echo:
echo ***************************************************
echo ** Finished. Now use 'ctrl+v' to paste **
echo ** diagnostics output into spreadsheet **
echo ** **
echo ** If you get errors, you must edit this batch **
echo ** file to have the correct port. You may also **
echo ** have hardware issues. See github **
echo ***************************************************

cmd /k




:: RECOMMEND RUNNING m18_idle.bat BEFORE CONNECTING TO BATTERY
:: Gives simple health report of M18 batteries
:: Add "--port COM5" (or whatever your port is) to avoid
:: having to enter it everytime

@echo off
echo ***************************************************
echo ** RIGHT-CLICK AND EDIT .BAT FILE. **
echo ** ADD "--port COM5" to command **
echo ** (or whatever port your serial adapter is on) **
echo ** (you can delete this message **
echo ***************************************************

python.exe .\m18.py --health
cmd /k





:: Puts serial adapter TX in idle (low = <1V)
:: This prevents false charge count increases

@echo off

echo ***************************************************
echo ** RIGHT-CLICK AND EDIT .BAT FILE. **
echo ** ADD "--port COM5" to command **
echo ** (or whatever port your serial adapter is on) **
echo ** (you can delete this message **
echo ***************************************************

python.exe .\m18.py --idle
cmd /k




:: RECOMMEND RUNNING m18_idle.bat BEFORE CONNECTING TO BATTERY
:: Runs script in interactive mode
:: All functions available

python.exe .\m18.py
Binary file added M18 copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added M18.ico
Binary file not shown.
Binary file added M18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading