Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions packages/rhsplib/librhsp/include/rhsp/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ int rhsp_serialWrite(RhspSerial* serial, const uint8_t* buffer, size_t bytesToWr
* */
void rhsp_serialClose(RhspSerial* serial);

/**
* @brief Get the last error code from the OS.
* This is errno on unix, and GetLastError on windows.
* */
int rhsp_getLastOsError();

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 4 additions & 1 deletion packages/rhsplib/librhsp/src/arch/linux/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>

#include "rhsp/serial.h"

Expand Down Expand Up @@ -359,4 +360,6 @@ static int baudrateToBits(uint32_t baudrate)
}
}


int rhsp_getLastOsError() {
return errno;
}
5 changes: 5 additions & 0 deletions packages/rhsplib/librhsp/src/arch/mac/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>

#include "rhsp/serial.h"

Expand Down Expand Up @@ -228,3 +229,7 @@ void rhsp_serialClose(RhspSerial* serial)
serial->fd = -1;
}

int rhsp_getLastOsError() {
return errno;
}

15 changes: 14 additions & 1 deletion packages/rhsplib/librhsp/src/arch/win/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,18 @@ int rhsp_serialOpen(RhspSerial* serial,
{
return RHSP_SERIAL_ERROR;
}

char modifiedSerialPortName[20];

// if the user has already prefixed the workaround, don't add it again
if(serialPort[0] == '\\') {
strncpy(modifiedSerialPortName, serialPort, 20);
} else {
snprintf(modifiedSerialPortName, 20, "\\\\.\\%s", serialPort);
}

/* Try to open specified COM-port */
serial->handle = CreateFile(serialPort,
serial->handle = CreateFile(modifiedSerialPortName,
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // default security attributes
Expand Down Expand Up @@ -242,3 +251,7 @@ void rhsp_serialClose(RhspSerial* serial)
}
}
}

int rhsp_getLastOsError(void) {
return (int) GetLastError();
}