# Pastebin AQZmk8NV type HDEVINFO = ptr HANDLE const DIGCF_PRESENT: uint = 0x00000002 DIGCF_DEVICEINTERFACE: uint = 0x00000010 setupDiGetClassDevsInitialFlags: uint = uint(DIGCF_PRESENT or DIGCF_DEVICEINTERFACE) var GUID_DEVINTERFACE_COMPORT : GUID = GUID(D1: 0x86e0d1e0'i32, D2: 0x8089'i16, D3: 0x11d0, D4: [ 0x9c'i8, 0xe4'i8, 0x08'i8, 0x00'i8, 0x3e'i8, 0x30'i8, 0x1f'i8, 0x73'i8]) proc SetupDiGetClassDevs(ClassGuid: ptr GUID, Enumerator: cstring, hwndParent: pointer, Flags: DWORD): HDEVINFO {.stdcall, importc: "SetupDiGetClassDevsW", dynlib: "setupapi.dll".} proc listSerialPorts(): string {.raises:[OSError].} = ## Iterate through all of the available serial ports on the system. let devInfoSet = SetupDiGetClassDevs(addr GUID_DEVINTERFACE_COMPORT, nil, nil, cast[DWORD](setupDiGetClassDevsInitialFlags)) if devInfoSet[] == -1: raiseOsError(osLastError())