Beispiel #1
0
/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
*              receive mode.
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
void RS485_Initialize(
    void)
{
    RS485_Handle =
        CreateFile(RS485_Port_Name, GENERIC_READ | GENERIC_WRITE, 0, 0,
        OPEN_EXISTING,
        /*FILE_FLAG_OVERLAPPED */ 0,
        0);
    if (RS485_Handle == INVALID_HANDLE_VALUE) {
        fprintf(stderr, "Unable to open %s\n", RS485_Port_Name);
        RS485_Print_Error();
        exit(1);
    }
    if (!GetCommTimeouts(RS485_Handle, &RS485_Timeouts)) {
        RS485_Print_Error();
    }
    RS485_Configure_Status();
#if PRINT_ENABLED
    fprintf(stderr, "RS485 Interface: %s\n", RS485_Port_Name);
#endif

    atexit(RS485_Cleanup);

    return;
}
/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
*              receive mode.
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
void RS485_Initialize(
    void)
{
	wchar_t Temp_wchar[500];
	wchar_t *  pUnicode;  
	int  unicodeLen = MultiByteToWideChar( CP_ACP,0, RS485_Port_Name,-1,NULL,0 );  
//	pUnicode = new  wchar_t[unicodeLen+1];  
	memset(Temp_wchar,0,(unicodeLen+1)*sizeof(wchar_t));  
	MultiByteToWideChar( CP_ACP,  0,RS485_Port_Name,-1,(LPWSTR)Temp_wchar,unicodeLen );  

	//memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));  
	//::MultiByteToWideChar( CP_ACP,  0,str.c_str(),-1,(LPWSTR)pUnicode,unicodeLen );  
	//wstring  rt;  
	//rt = ( wchar_t* )pUnicode;
	//delete  pUnicode; 
	//return  rt;  



    RS485_Handle =
        CreateFile(Temp_wchar, GENERIC_READ | GENERIC_WRITE, 0, 0,
        OPEN_EXISTING,
        /*FILE_FLAG_OVERLAPPED */ 0,
        0);
    if (RS485_Handle == INVALID_HANDLE_VALUE) {
        fprintf(stderr, "Unable to open %s\n", RS485_Port_Name);
        RS485_Print_Error();
		return; // if open com port fail , don't exit ;
        //exit(1);
    }
    if (!GetCommTimeouts(RS485_Handle, &RS485_Timeouts)) {
        RS485_Print_Error();
    }
    RS485_Configure_Status();
#if PRINT_ENABLED
    fprintf(stderr, "RS485 Interface: %s\n", RS485_Port_Name);
#endif

    atexit(RS485_Cleanup);

    return;
}