Last active
May 8, 2026 18:51
-
-
Save daisyUniverse/45bd68964683b9acf7441a61e6b8796c to your computer and use it in GitHub Desktop.
Kramer USB serial communication script for the VS-611DT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # VS-611DT COMMUNICATOR | |
| # Interface for communicating with Kramer switches via RS-232 Serial | |
| # Ultimately this is a desperate attempt to not have to walk a quarter mile to unplug a box every other day | |
| # Robin Universe [S] | |
| # 05 . 08 . 2026 | |
| param( | |
| $IN = "#", | |
| $COM = "COM8", | |
| $BAUD = 115200 | |
| ) | |
| # We need to find the most likely USB device that matches the Kramer USB | |
| function find-device { | |
| Write-Host -Fo Yellow " VS-611DT COMMUNICATOR: SEARCHING FOR VALID COM PORT... " -NoNewline | |
| $d = (Get-WMIObject Win32_PnPEntity | where {$_.name -match "USB Serial Device*"}) | |
| $COM = $d.Name.split("(")[1].replace(")","") | |
| Write-Host -Fo Green " $COM " | |
| return $d | |
| } | |
| # Follows a procedure that 'unsticks' the USB driver after a reset | |
| # NOTE: This doesn't work on accounts without elevated access! | |
| # Users with no elevated access must restart or replug the USB physically like a caveman | |
| function restart-device($device) { | |
| Write-Host -Fo Yellow " VS-611DT COMMUNICATOR: RESET PROCEDURE. " | |
| Start-Sleep 2 | |
| Write-Host -Fo Yellow " VS-611DT COMMUNICATOR: DISABLE DRIVER. " | |
| $device | Disable-PnpDevice -Confirm:$false | |
| Start-Sleep 2 | |
| Write-Host -Fo Yellow " VS-611DT COMMUNICATOR: ENABLE DRIVER. " | |
| $device | Enable-PnpDevice -Confirm:$false | |
| } | |
| # Configures the port, opens the connection, and returns it. Most of the stuff | |
| # in here was just fucking around until I found a setup that works | |
| function open-port($COM) { | |
| Write-Host " VS-611DT COMMUNICATOR: ATTEMPTING TO CONNECT VIA $COM " | |
| $port = New-Object System.IO.Ports.SerialPort $COM,$BAUD,None,8,one | |
| $port.ReadTimeout = 2000 | |
| $port.WriteTimeout = 2000 | |
| $port.Handshake = 2 | |
| #$port.RtsEnable = $true | |
| $port.NewLine = "`n" # Same results with "`n and `r and `r`n" | |
| try { $port.Open(); Write-Host -Fo Green " CONNECTED! " } catch { Write-Host -Fo Red "`n STINKY! Failed to connect to serial port!"; break } | |
| return $port | |
| } | |
| # Sends out the formatted command, or dies trying | |
| function send-com($port, $IN){ | |
| try { $o = $port.Write("$IN") } catch [TimeoutException] { Write-Host -Fo Red "`n STINKY! Send command timed out!" } | |
| } | |
| # You would not believe how much of a pain in the ass it is to make this non-blocking | |
| # Returns the last line or an error code (1 for timeout, 2 for dead connection) | |
| function listen-port($port) { | |
| if ($port.IsOpen) { | |
| try { | |
| $a = $port.ReadLine() | |
| return $a | |
| } catch [TimeoutException] { | |
| return 1 | |
| } | |
| } else { | |
| return 2 | |
| } | |
| } | |
| $device = find-device | |
| $COM = $device.Name.split("(")[1].replace(")","") # Hacky bullshit to get the COM# | |
| $p = open-port $COM | |
| $timeout = 1 # this was useful once but now im afraid to remove it | |
| # The main loop. I could have done this cleaner, but EVERYTHING wants to be blocking | |
| # in this context, so we need to play a bit dirty | |
| while ($true) { | |
| $IN = Read-Host " #" | |
| if ($IN -eq "exit") {break} # Breaks out of the outer loop on 'exit' | |
| while ($true) { | |
| send-com $p ("#"+ $IN +"`r`n" ) # Formatting specific to this interface | |
| $d = listen-port $p | |
| if ($d -eq 1) { | |
| $timeout = ($timeout - 1) # This is weird but it works and is stable | |
| if ($timeout -lt 1) { Write-Host "`r Connection timed out! `n" -NoNewline ; break } | |
| } elseif ($d -eq 2) { | |
| Write-Host " Port not open! "; break | |
| } else { | |
| if ( $d -Match "@" ) { $n = $d.split("@")[1] } else { $n = $d } | |
| Write-Host " [RECV] $n" -Fo Green; break # Message recieved | |
| } | |
| Start-Sleep -Milliseconds 50 # Don't eat the entire CPU | |
| } | |
| if ($IN -eq "reset") { # Device reset requires some special treatment | |
| Write-Host -Fo Yellow " DEVICE RESET INITIATED. DISCONNECTING... " | |
| break | |
| } | |
| } | |
| # Make sure we properly close the port and dispose of the buffer, without this | |
| # subsequent connections have problems | |
| Write-Host -Fo Yellow " VS-611DT COMMUNICATOR: DISCONNECTING FROM SERIAL PORT... " | |
| $p.Close() | |
| $p.Dispose() | |
| # Do our special reset procedure if requested | |
| if ($IN -eq "reset"){ | |
| restart-device $device | |
| } | |
| # I don't trust all of those closes driver actions to properly block the script for long enough | |
| # to finish so I hold it here for a few breaths to feel better about myself | |
| Start-Sleep 2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment