Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for latest Nim #49

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
10 changes: 2 additions & 8 deletions src/serial/private/ffi/ffi_windows.nim
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,7 @@ proc ClearCommError*(hFile: Handle, lpErrors: ptr DWORD,
lpStat: ptr ComStat): WINBOOL {.stdcall, dynlib: "kernel32",
importc: "ClearCommError".}

when useWinUnicode:
const CreateFileWindows* = createFileW
else:
const CreateFileWindows* = createFileA
const CreateFileWindows* = createFileW

template getWindowsString*(str: string): untyped =
when useWinUnicode:
newWideCString(str)
else:
cstring(str)
newWideCString(str)
8 changes: 4 additions & 4 deletions src/serial/private/serialport/serialport_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ type
Two = 2,
OnePointFive = 3

InvalidSerialPortError* = object of Exception
InvalidSerialPortError* = object of IOError

TimeoutError* = object of IOError

InvalidSerialPortStateError* = object of IOError

InvalidBaudRateError* = object of Exception
InvalidBaudRateError* = object of ValueError

InvalidDataBitsError* = object of Exception
InvalidDataBitsError* = object of ValueError

InvalidStopBitsError* = object of Exception
InvalidStopBitsError* = object of IOError
RSDuck marked this conversation as resolved.
Show resolved Hide resolved

ReceivedError* {.pure.} = enum
## Types of error detected by the operating system whilst reading from/writing to a serial port.
Expand Down
4 changes: 2 additions & 2 deletions src/serial/private/serialport/serialport_windows.nim
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,8 @@ proc close*(port: SerialPort | AsyncSerialPort) =
if EscapeCommFunction(Handle(port.handle), CLRDTR) == 0:
let lastError = int32(osLastError())

if lastError in {ERROR_ACCESS_DENIED, ERROR_BAD_COMMAND,
ERROR_DEVICE_REMOVED}:
if lastError in [ERROR_ACCESS_DENIED, ERROR_BAD_COMMAND,
ERROR_DEVICE_REMOVED]:
skipFlush = true
else:
# Unknown error
Expand Down
6 changes: 3 additions & 3 deletions src/serial/private/utils/windows_registry.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ iterator enumKeyValues*(path: string, handle: HKEY): tuple[key:string, value:str
call regEnumValue(newHandle, int32(i), regName, addr regNameSize, nil, nil, nil, addr regValueSize)
var regValue = newWideCString("", regValueSize)
regNameSize += 2 # reallocate for null wchar.
call regEnumValue(newHandle, int32(i), regName, addr regNameSize, nil, nil, cast[pointer](regValue), addr regValueSize)
call regEnumValue(newHandle, int32(i), regName, addr regNameSize, nil, nil, addr regValue[0], addr regValueSize)
yield (regName $ regNameSize, regValue $ regValueSize)

call regCloseKey(newHandle)
Expand All @@ -110,13 +110,13 @@ proc getUnicodeValue*(path, key: string; handle: HKEY): string =
call regOpenKeyEx(handle, hh, 0, KEY_READ or KEY_WOW64_64KEY, newHandle)
call regGetValue(newHandle, nil, kk, flags, nil, nil, addr bufsize)
var res = newWideCString("", bufsize)
call regGetValue(newHandle, nil, kk, flags, nil, cast[pointer](res),
call regGetValue(newHandle, nil, kk, flags, nil, addr res[0],
addr bufsize)
result = res $ bufsize
call regCloseKey(newHandle)
else:
var res = newWideCString("", bufsize)
call regGetValue(handle, hh, kk, flags, nil, cast[pointer](res),
call regGetValue(handle, hh, kk, flags, nil, addr res[0],
addr bufsize)
result = res $ bufsize

Expand Down