none
communcation device class(CDC) and writefile and Getlasterror error code 1814 RRS feed

  • Question

  • Hi,

    I am trying to send the data to the CDC devices through a serial virtual com port,  I am keep getting the getlasterror 1814,  the error define as  "The specified resource name cannot be found in the image file" Could you tell me what could be the specified resource that is missing from the image for the CDC serial communication?

    Thank you,

    Liang


    • Edited by Liang1 Tuesday, January 14, 2014 5:09 PM
    Tuesday, January 14, 2014 4:37 PM

All replies

  • Your description of the problem leaves out a lot of important details.  So far you have just told us something like - I called a function (but didn't tell us which function, or how it is called) and I receive an error, how should I solve it?

    Instead of describing the very low level problem in very high level terms, show us your code that returns an error and your call to GetLastError.

    If I were to guess, I would guess that this occurs before "trying to send the data".  It probably occurs while opening the COM port when calling CreateFile().   And is probably because your first parameter is incorrect.   You may want to look at http://geekswithblogs.net/BruceEitman/archive/2008/06/23/windows-ce-device-driver-index-greater-than-9.aspx 



    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    Tuesday, January 14, 2014 5:11 PM
    Moderator
  • Here is my code,  if you need more, please let me know.  the following code works fine with physical com ports

     DWORD dwWrite=SerialPortWrite();

    if (dwWrite==0)

    {

     wsprintf(szInfo, L"unable to write %d",GetLastError());

    }

    DWORD SerialPortWrite()

    {

    unsigned char buf[64];

     DWORD Res(0);

     BOOL bwrite;

    for (int i=0; i<16; i++)

    {buf[i]=0x20+i;}

    if (m_PortHandle != INVALID_HANDLE_VALUE)

    {

       bwrite=WriteFile(m_PortHandle, buf, 16, &Res, NULL);


    if (!bwrite)

    {


    Res=0;

    }


          }

       

    return Res;

    }


    • Edited by Liang1 Tuesday, January 14, 2014 6:28 PM
    Tuesday, January 14, 2014 5:19 PM
  • CreateFile() was successful? That is, the failure didn't occur when opening the port and you didn't check for errors at that time so you get a transmit error when WriteFile() is called?

    Paul T.

    Tuesday, January 14, 2014 6:01 PM
  • yes, my createfile() was OK, Please check the code above. The same source code works fine with the physical winCE com port.   Could the error indicating that I have something missing from my CDC virtual port?  how does the usbser,  the CDC driver setting up the line information, like baud rate, stopbits, parity and byte size?

    Liang


    • Edited by Liang1 Tuesday, January 14, 2014 6:48 PM
    Tuesday, January 14, 2014 6:30 PM
  • That code needs some work.

    Res is  NOT initialized, so if m_PortHandle is invalid, what is returned?  In a debug build it might be zero.  Further, if we assume that when m_PortHandle is invalid (and I suspect that it is) Res is set to zero - then what will GetLastError() return later?   Answer:  Some value that was set some unknown place earlier.

    Start by debugging your code.  What is the real reason that SerialPortWrite() is returning zero?   Again, I suspect that it is because the call to CreateFile() is failing, and again you didn't show that.


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    Tuesday, January 14, 2014 7:05 PM
    Moderator
  • Res is initialized,  I defined the variable as DWORD Res(0); 

    Liang


    • Edited by Liang1 Tuesday, January 14, 2014 8:46 PM
    Tuesday, January 14, 2014 7:22 PM
  • Yes, sorry I need new glasses....

    So, you say that CreateFile() is ok based on that it works in other cases - great, but what about this case????

    Give me a reason that you know that it is successful in this case?  Time to help yourself a little bit and do some debugging.

    Start by debugging your code.  What is the real reason that SerialPortWrite() is returning zero?   Again, I suspect that it is because the call to CreateFile() is failing, and again you didn't show that.

    Which COM port are you opening?


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    Tuesday, January 14, 2014 7:51 PM
    Moderator
  • here is my createfile code, my CDC ports are 2 and 4,  following is what I have,  the createfile did not return null or

    INVALID_HANDLE_VALUE

    m_PortHandle = CreateFile(L"COM2:", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

    Liang


    • Edited by Liang1 Wednesday, January 15, 2014 3:51 AM
    Tuesday, January 14, 2014 7:59 PM
  • OK. I've never seen a port do this but I'm wondering if the actual USB connection isn't opened until another call is made. That is, the driver doesn't necessarily have to do anything to the USB device when you open the port and maybe that's why CreateFile() works but WriteFile() does not.

    Do you set baud rate, etc. with SetCommState()? If not, do so and check for errors.

    As for your question, yes, I think this is a characteristics of the driver you are using but that doesn't necessarily mean your code isn't at fault for triggering the driver flaw. Which driver is loaded? Is it the Microsoft USBSER driver or a driver specific to your USB serial hardware?

    Paul T.

    Wednesday, January 15, 2014 1:09 AM
  • Another thought is to check the actual values passed to WriteFile(). For example, are you sure you saved the port handle in m_PortHandle? Something like that can keep you guessing for days until you check the parameters in the debugger.

    Paul T.

    Wednesday, January 15, 2014 1:11 AM
  • I am using setcommstate to set the baud rate, parity, stopbit and bytesize.  I am using the Microsoft CDC driver USBSER.   I have just double checked,  my values passing to the writefile and the port handle in m_PortHandle are all good.   Looking at the USB sniffer,  it looks like my data is sending down to the usb device.    Is there any configuration I need to set? or is there a way to check if hardware model match to the driver model?

    Liang




    • Edited by Liang1 Thursday, January 16, 2014 5:04 PM
    Wednesday, January 15, 2014 3:50 AM
  • There is no other external test I'm aware of. I suppose that sending 1 character at a time and comparing to sending 100 at a time might be revealing. If you've set handshaking of some sort you might check the actual serial connection to assure the handshaking lines have "appropriate" values for the USB serial device to use.

    If you are the hardware designer you could verify that the hardware is mapped on a suitable boundary and a few things like that but the next thing I'd try is debugging the driver code and I'm not sure you have source for that.

    Paul T.

    Monday, January 27, 2014 4:00 PM
  • Thank you for the reply! I will check that with the hardware engineer.

    Liang

    Friday, January 31, 2014 4:44 PM