Closed pcdangio closed 3 years ago
It seems like a simpler fix would be to just use the CreateFileA()
API, and keep the filename format of \\.\COM99
per CreateFileA documentation.
If you fork this repository to your own GitHub account, you can create a branch and then issue a PR from that branch back to this main project.
I just verified that simple CreateFileA()
works on my machine. One quick thought: CreateFile()
itself is a macro that, from what I can tell, ultimately decides (based on preprocessor definitions) whether to use the actual CreateFileW()
or CreateFileA()
functions. I did a short search but couldn't track down what may need to be defined / not defined to ultimately get CreateFile()
to use CreateFileA()
on Windows/MinGW. If we can track that down, this may not have to be implemented as a code change and instead just documented for users to know when to make that definition or not.
I think it's safest to just switch to CreateFileA()
, which will work regardless of whether UNICODE
is defined during compilation. We don't need unicode support to open the COM port, and CreateFileA()
has been around since Windows XP.
Since you found this issue, I'd welcome a PR that just switches to CreateFileA()
. It could be a good opportunity to learn the pull request flow on GitHub. Let me know if you aren't interested in doing that, and I'll just make a commit with the fix.
Submitted pull request: https://github.com/digidotcom/xbee_ansic_library/pull/32
Merged PR #32.
On windows 10 + mingw,
xbee_ser_open()
was failing with IO errors (123 and 5). I debugged a little bit and it turns out that a wchar array must be used when getting thehCom
handle. The error can be traced to the following lines:https://github.com/digidotcom/xbee_ansic_library/blob/64261a71fef428029b4631e53b5c22bf0d1cf1fc/ports/win32/xbee_serial_win32.c#L298-L299
Here,
buffer
is a regularchar
and not awchar_t
(akauint16_t
). This formatting issue results in a failure to obtain a validhCom
handle no matter what COM port is used.I've implemented a working fix that uses a
wchar_t
buffer andswprintf()
. Tried to set up a pull request but didn't have branch access so I've included the fixedxbee_ser_open()
function below. The only places I changed anything were setting up the buffer at the beginning of the function, and switching toswprintf()
just before thehCom
handle is opened withCreateFile()
.