SetCommState fails on WinNT

This is a discussion on SetCommState fails on WinNT within the Windows Programming forums, part of the Platform Specific Boards category; Hello People!!, i'm trying to establish a serial communication on WinNT. The routines are running on a Win98 system but ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    47

    Question SetCommState fails on WinNT

    Hello People!!,

    i'm trying to establish a serial communication on WinNT.

    The routines are running on a Win98 system but
    on a WinNT the SetCommState fails with errorcode 57.

    Could someone please help. ?

    Regards,
    Robert

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    57 indicates a hardware error, however, that may not mean ther is a hardware error!

    Is the NT machine set up the same way? What I mean is, does your program get a handle to the COM2: port on the 98 machine but COM2: does not exist on the NT for example. Without knowing a lot more about the setup and the software it is difficult to be overly constructive.

    Things to check are the handle you pass, is it valid; what you have set in the control block, is it valid/complete; the basic configuration, are you doing something illegal, be aware, that 9x systems let you "get away" with a lot of things that are not technically correct, but work anyway. NT cored systems are much more vigorous in protecting themselves. Your code may simply be exploiting one of these holes.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    47

    Thumbs up

    Hi!

    Is the NT machine set up the same way? What I mean is, does your program get a handle to the COM2: port on the 98 machine but COM2: does not exist on the NT for example. Without knowing a lot more about the setup and the software it is difficult to be overly constructive.
    On both systems i get a valid handle.
    I've checked the Ports if the correct one are used etc.

    Thanks anyway, it's my fault not to tell more about my setup

    I'vechecked another thread in this forum
    and saw that first a GetCommState function was used, then
    parameter were set by hand and finally the SetCommState function is applied. I've did it the same way and there is no
    ERROR code.

    I suggest that the DCB wasn't initialised correctly.

    Here a fragment of my code.

    [code]
    tComm = CreateFile( "COM1",
    GENERIC_READ | GENERIC_WRITE,
    0,
    0,
    OPEN_EXISTING,
    0, //FILE_FLAG_OVERLAPPED,
    0);

    if (tComm == INVALID_HANDLE_VALUE)
    {
    status = FALSE;
    printf ("<CreateFile> Errorcode: %lx\n",GetLastError());
    }
    else
    {
    hComm = tComm;

    GetCommState(hComm, &dcb);

    // Fill in the DCB: baud=9600, 8 data bits, no parity, 1 stop bit.

    dcb.BaudRate = 9600;
    dcb.ByteSize = 8;
    dcb.Parity = NOPARITY;
    dcb.StopBits = ONESTOPBIT;

    /*~T*/

    // BuildCommDCB((WCHAR *)"9600,n,8,1,x", &dcb);

    /*~T*/
    dcbStatus = SetCommState(hComm, &dcb);

    if (!dcbStatus)
    {
    printf ("<SetCommState> Errorcode: %lx\n",GetLastError());
    }

    /*~T*/
    status = TRUE;


    Thanks for reply

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Is that the code where you got the error number from, (i.e. is the error code 0x57, or 57 decimal)? 0x57 is a parameter error. In winerror.h the codes are decimal normally.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    47
    Hello,

    you are completly right, somehow i forgot about the %lx, but
    this code works on the WinNT now.

    The routine only failts if the line
    GetCommState(hComm, &dcb);
    is not included.

    Regards,
    Robert

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 06-24-2009, 10:49 AM
  2. Mac - File locking with fcntl() fails on shared volumes!?
    By idelovski in forum Linux Programming
    Replies: 3
    Last Post: 11-10-2008, 07:37 PM
  3. Why this fails - confusing
    By manav-II in forum C++ Programming
    Replies: 2
    Last Post: 07-21-2008, 02:01 AM
  4. Replies: 0
    Last Post: 05-23-2005, 12:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21