Hello Chloe,
Unfortunately the machines do not have unique identifiers in firmware.
For State Machine r2, r2.5 and r2+, Windows should keep the COM port number the same regardless of which USB port it is plugged into. On those state machine models, you can also get the Teensy's serial number with the following command for a state machine on port COM5:
[status, msg] = system('C:\Users\UserName\Documents\Bpod_Gen2\Functions\"Firmware Update"\tycmd reset -B "@COM5"')
This will briefly reboot the state machine, so don't run it while it is connected. The msg string will show something like:
reset@13710960-Teensy Resetting board '13710960-Teensy' (Teensy 4.1)
You can parse the string to get 13710960, the Teensy board's serial number.
-Josh