Fixed win32 builds where UNICODE is defined. The code now uses CreateFileA instead of CreateFile due to ANSI-C filenames. (#1076)
This commit is contained in:
+3
-3
@@ -454,15 +454,15 @@ static void named_pipe_create(const char *pipe_name)
|
|||||||
}
|
}
|
||||||
/* create the pipe */
|
/* create the pipe */
|
||||||
while (Pipe_Handle == INVALID_HANDLE_VALUE) {
|
while (Pipe_Handle == INVALID_HANDLE_VALUE) {
|
||||||
/* use CreateFile rather than CreateNamedPipe */
|
/* use CreateFileA rather than CreateNamedPipeA */
|
||||||
Pipe_Handle = CreateFile(
|
Pipe_Handle = CreateFileA(
|
||||||
pipe_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,
|
pipe_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,
|
||||||
NULL);
|
NULL);
|
||||||
if (Pipe_Handle != INVALID_HANDLE_VALUE) {
|
if (Pipe_Handle != INVALID_HANDLE_VALUE) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* if an error occured at handle creation */
|
/* if an error occured at handle creation */
|
||||||
if (!WaitNamedPipe(pipe_name, 20000)) {
|
if (!WaitNamedPipeA(pipe_name, 20000)) {
|
||||||
printf("Could not open pipe: waited for 20sec!\n"
|
printf("Could not open pipe: waited for 20sec!\n"
|
||||||
"If this message was issued before the 20sec finished,\n"
|
"If this message was issued before the 20sec finished,\n"
|
||||||
"then the pipe doesn't exist!\n");
|
"then the pipe doesn't exist!\n");
|
||||||
|
|||||||
+3
-3
@@ -48,7 +48,7 @@ SerialPort::~SerialPort()
|
|||||||
/* Open the communication channel */
|
/* Open the communication channel */
|
||||||
void SerialPort::openChannel()
|
void SerialPort::openChannel()
|
||||||
{
|
{
|
||||||
/* CreateFile expects a constant char, or char from the heap */
|
/* CreateFileA expects a constant char, or char from the heap */
|
||||||
static char comName[64] = "COM1";
|
static char comName[64] = "COM1";
|
||||||
|
|
||||||
COMMTIMEOUTS comTimeouts;
|
COMMTIMEOUTS comTimeouts;
|
||||||
@@ -62,11 +62,11 @@ void SerialPort::openChannel()
|
|||||||
comName[3] = '0' + portNumber;
|
comName[3] = '0' + portNumber;
|
||||||
} else if (portNumber < 100) {
|
} else if (portNumber < 100) {
|
||||||
/* For COM ports greater than 9 you have to use a special syntax
|
/* For COM ports greater than 9 you have to use a special syntax
|
||||||
for CreateFile. The syntax also works for COM ports 1-9. */
|
for CreateFileA. The syntax also works for COM ports 1-9. */
|
||||||
/* http://support.microsoft.com/kb/115831 */
|
/* http://support.microsoft.com/kb/115831 */
|
||||||
snprintf(comName, sizeof(comName), "\\\\.\\COM%ld", portNumber);
|
snprintf(comName, sizeof(comName), "\\\\.\\COM%ld", portNumber);
|
||||||
}
|
}
|
||||||
serialHandle = CreateFile( comName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
serialHandle = CreateFileA( comName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
||||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
||||||
|
|
||||||
/* Print error and return if failed opening port */
|
/* Print error and return if failed opening port */
|
||||||
|
|||||||
+3
-3
@@ -81,7 +81,7 @@ static void strupper(char *str)
|
|||||||
void RS485_Set_Interface(char *ifname)
|
void RS485_Set_Interface(char *ifname)
|
||||||
{
|
{
|
||||||
/* For COM ports greater than 9 you have to use a special syntax
|
/* For COM ports greater than 9 you have to use a special syntax
|
||||||
for CreateFile. The syntax also works for COM ports 1-9. */
|
for CreateFileA. The syntax also works for COM ports 1-9. */
|
||||||
/* http://support.microsoft.com/kb/115831 */
|
/* http://support.microsoft.com/kb/115831 */
|
||||||
if (ifname) {
|
if (ifname) {
|
||||||
strupper(ifname);
|
strupper(ifname);
|
||||||
@@ -112,7 +112,7 @@ bool RS485_Interface_Valid(unsigned port_number)
|
|||||||
char ifname[255] = "";
|
char ifname[255] = "";
|
||||||
|
|
||||||
snprintf(ifname, sizeof(ifname), "\\\\.\\COM%u", port_number);
|
snprintf(ifname, sizeof(ifname), "\\\\.\\COM%u", port_number);
|
||||||
h = CreateFile(
|
h = CreateFileA(
|
||||||
ifname, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
ifname, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||||
if (h == INVALID_HANDLE_VALUE) {
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
err = GetLastError();
|
err = GetLastError();
|
||||||
@@ -252,7 +252,7 @@ static void RS485_Cleanup(void)
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void RS485_Initialize(void)
|
void RS485_Initialize(void)
|
||||||
{
|
{
|
||||||
RS485_Handle = CreateFile(
|
RS485_Handle = CreateFileA(
|
||||||
RS485_Port_Name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
|
RS485_Port_Name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
|
||||||
/*FILE_FLAG_OVERLAPPED */ 0, 0);
|
/*FILE_FLAG_OVERLAPPED */ 0, 0);
|
||||||
if (RS485_Handle == INVALID_HANDLE_VALUE) {
|
if (RS485_Handle == INVALID_HANDLE_VALUE) {
|
||||||
|
|||||||
Reference in New Issue
Block a user