Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Regarding System Error Code 995 in Serial Communication

Regarding System Error Code 995 in Serial Communication

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++comdebuggingtutorial
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pra84veen
    wrote on last edited by
    #1

    hi one and all, iam having a problem with accessing serial port in my pc. i have developed an application which access the serial port in VC++ 6.0.After configuring the Serial port to 115200, iam able to send the data to the com port using WriteFile().But, iam unable to receive the data from the com port through ReadFile() operation and i have checked the error by using GetLastError() and it is given as 995(system error code).Even though i have restarted my system several times,iam unable to debug. Please help me why this error is getting and how to fix this error? Thanks in advance Regards, Praveen

    modified on Monday, June 9, 2008 8:23 AM

    CPalliniC 1 Reply Last reply
    0
    • P pra84veen

      hi one and all, iam having a problem with accessing serial port in my pc. i have developed an application which access the serial port in VC++ 6.0.After configuring the Serial port to 115200, iam able to send the data to the com port using WriteFile().But, iam unable to receive the data from the com port through ReadFile() operation and i have checked the error by using GetLastError() and it is given as 995(system error code).Even though i have restarted my system several times,iam unable to debug. Please help me why this error is getting and how to fix this error? Thanks in advance Regards, Praveen

      modified on Monday, June 9, 2008 8:23 AM

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Cross post: http://www.codeproject.com/script/Forums/View.aspx?fid=1648&msg=2588888[^], please don't do it. BTW why didn't you post the relevant code, as I suggested? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      In testa che avete, signor di Ceprano?

      P 1 Reply Last reply
      0
      • CPalliniC CPallini

        Cross post: http://www.codeproject.com/script/Forums/View.aspx?fid=1648&msg=2588888[^], please don't do it. BTW why didn't you post the relevant code, as I suggested? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        P Offline
        P Offline
        pra84veen
        wrote on last edited by
        #3

        Iam calling this function for capturing data. The ReadFile() returns 0 value and GetLastError() gives error 995 bool CSerialPort::bReceiveBytes( unsigned char* x_pcBuffer, unsigned short x_usLengthExpected, unsigned short *x_pusLengthReceived ) { bool bResult = FALSE; unsigned long ulLengthReceived=0; int iResult; iResult = ReadFile( m_comPortHandle, x_pcBuffer[0], x_usLengthExpected, &ulLengthReceived, NULL ); DWORD err1 = GetLastError(); *x_pusLengthReceived = (unsigned short)ulLengthReceived; return( bResult ); }

        CPalliniC 1 Reply Last reply
        0
        • P pra84veen

          Iam calling this function for capturing data. The ReadFile() returns 0 value and GetLastError() gives error 995 bool CSerialPort::bReceiveBytes( unsigned char* x_pcBuffer, unsigned short x_usLengthExpected, unsigned short *x_pusLengthReceived ) { bool bResult = FALSE; unsigned long ulLengthReceived=0; int iResult; iResult = ReadFile( m_comPortHandle, x_pcBuffer[0], x_usLengthExpected, &ulLengthReceived, NULL ); DWORD err1 = GetLastError(); *x_pusLengthReceived = (unsigned short)ulLengthReceived; return( bResult ); }

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          pra84veen wrote:

          x_pcBuffer[0]

          The above is wrong: you should use x_pcBuffer instead. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          In testa che avete, signor di Ceprano?

          P 1 Reply Last reply
          0
          • CPalliniC CPallini

            pra84veen wrote:

            x_pcBuffer[0]

            The above is wrong: you should use x_pcBuffer instead. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            P Offline
            P Offline
            pra84veen
            wrote on last edited by
            #5

            hello, thanks for your reply... even though if i replace x_pcBuffer instead of x_pcBuffer[0], i dint get any data into the buffer. but here the return values for ReadFile is 1 but iam unable to capture the data.. Thanks & Regards, praveen

            CPalliniC 1 Reply Last reply
            0
            • P pra84veen

              hello, thanks for your reply... even though if i replace x_pcBuffer instead of x_pcBuffer[0], i dint get any data into the buffer. but here the return values for ReadFile is 1 but iam unable to capture the data.. Thanks & Regards, praveen

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              When return value is 1, ReadFile succeeded. What is the value of ulLengthReceived? :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              In testa che avete, signor di Ceprano?

              P 1 Reply Last reply
              0
              • CPalliniC CPallini

                When return value is 1, ReadFile succeeded. What is the value of ulLengthReceived? :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                P Offline
                P Offline
                pra84veen
                wrote on last edited by
                #7

                the value received by the ulLengthReceived is 0.

                void CER2TSerialDlg::OnStartThread()
                {
                CWinThread *pThread = NULL;
                m_SerialCommn->bOpen()
                pThread = AfxBeginThread((AFX_THREADPROC)ReadFromModuleThread,NULL);
                }

                UINT CER2TSerialDlg::ReadFromModuleThread(LPVOID pPARAM)
                {
                unsigned char ucLengthExpected=10;
                char chBuffer[FIFO_SIZE]={0};
                unsigned short usReceived=0;

                while(TRUE)
                {
                m_SerialCommn->bReceiveBytes(chBuffer,ucLengthExpected,&usReceived);
                }
                return 0;
                }

                bool CSerialPort::bReceiveBytes(char* x_pcBuffer,
                unsigned short x_usLengthExpected,
                unsigned short *x_pusLengthReceived )
                {

                unsigned long ulLengthReceived=0;
                int iResult;
                iResult = ReadFile(m_comPortHandle,
                x_pcBuffer[0],
                x_usLengthExpected,
                ulLengthReceived,
                NULL );
                DWORD err1 = GetLastError();
                *x_pusLengthReceived = (unsigned short)ulLengthReceived;
                return( iResult );

                }/

                Regards praveen

                modified on Wednesday, June 11, 2008 1:48 AM

                CPalliniC 1 Reply Last reply
                0
                • P pra84veen

                  the value received by the ulLengthReceived is 0.

                  void CER2TSerialDlg::OnStartThread()
                  {
                  CWinThread *pThread = NULL;
                  m_SerialCommn->bOpen()
                  pThread = AfxBeginThread((AFX_THREADPROC)ReadFromModuleThread,NULL);
                  }

                  UINT CER2TSerialDlg::ReadFromModuleThread(LPVOID pPARAM)
                  {
                  unsigned char ucLengthExpected=10;
                  char chBuffer[FIFO_SIZE]={0};
                  unsigned short usReceived=0;

                  while(TRUE)
                  {
                  m_SerialCommn->bReceiveBytes(chBuffer,ucLengthExpected,&usReceived);
                  }
                  return 0;
                  }

                  bool CSerialPort::bReceiveBytes(char* x_pcBuffer,
                  unsigned short x_usLengthExpected,
                  unsigned short *x_pusLengthReceived )
                  {

                  unsigned long ulLengthReceived=0;
                  int iResult;
                  iResult = ReadFile(m_comPortHandle,
                  x_pcBuffer[0],
                  x_usLengthExpected,
                  ulLengthReceived,
                  NULL );
                  DWORD err1 = GetLastError();
                  *x_pusLengthReceived = (unsigned short)ulLengthReceived;
                  return( iResult );

                  }/

                  Regards praveen

                  modified on Wednesday, June 11, 2008 1:48 AM

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  pra84veen wrote:

                  iResult = ReadFile(m_comPortHandle, x_pcBuffer[0], x_usLengthExpected, ulLengthReceived, NULL );

                  That's completely wrong (compiler doesn't complain, does it?). Should be:

                  ReadFile(m_comPortHandle,
                  x_pcBuffer,
                  x_usLengthExpected,
                  &ulLengthReceived,
                  NULL );

                  Please note the ampersand in front of ulLengthReceived. BTW: How did you set serial port timeouts? :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                  In testa che avete, signor di Ceprano?

                  P 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    pra84veen wrote:

                    iResult = ReadFile(m_comPortHandle, x_pcBuffer[0], x_usLengthExpected, ulLengthReceived, NULL );

                    That's completely wrong (compiler doesn't complain, does it?). Should be:

                    ReadFile(m_comPortHandle,
                    x_pcBuffer,
                    x_usLengthExpected,
                    &ulLengthReceived,
                    NULL );

                    Please note the ampersand in front of ulLengthReceived. BTW: How did you set serial port timeouts? :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                    P Offline
                    P Offline
                    pra84veen
                    wrote on last edited by
                    #9

                    Even after modification also, iam not able to collect the data The serial port timeouts are

                    GetCommTimeouts(m_comPortHandle, &sCommTimeOuts);
                    sCommTimeOuts.ReadIntervalTimeout = 5;//100; //[ms]
                    sCommTimeOuts.ReadTotalTimeoutMultiplier = 1;//10; //[ms]
                    sCommTimeOuts.ReadTotalTimeoutConstant = 1;//500; //[ms]
                    sCommTimeOuts.WriteTotalTimeoutMultiplier = 1;//10; //[ms]
                    sCommTimeOuts.WriteTotalTimeoutConstant = 1;//100; //[ms]
                    SetCommTimeouts(m_comPortHandle, &sCommTimeOuts);

                    Thanks & Regards, Praveen

                    CPalliniC 1 Reply Last reply
                    0
                    • P pra84veen

                      Even after modification also, iam not able to collect the data The serial port timeouts are

                      GetCommTimeouts(m_comPortHandle, &sCommTimeOuts);
                      sCommTimeOuts.ReadIntervalTimeout = 5;//100; //[ms]
                      sCommTimeOuts.ReadTotalTimeoutMultiplier = 1;//10; //[ms]
                      sCommTimeOuts.ReadTotalTimeoutConstant = 1;//500; //[ms]
                      sCommTimeOuts.WriteTotalTimeoutMultiplier = 1;//10; //[ms]
                      sCommTimeOuts.WriteTotalTimeoutConstant = 1;//100; //[ms]
                      SetCommTimeouts(m_comPortHandle, &sCommTimeOuts);

                      Thanks & Regards, Praveen

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #10

                      Why don't you widen them (you can also set them for a blocking call, just to make a test)? :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                      In testa che avete, signor di Ceprano?

                      P 1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        Why don't you widen them (you can also set them for a blocking call, just to make a test)? :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                        P Offline
                        P Offline
                        pra84veen
                        wrote on last edited by
                        #11

                        sorry, i dint get you

                        P 1 Reply Last reply
                        0
                        • P pra84veen

                          sorry, i dint get you

                          P Offline
                          P Offline
                          pra84veen
                          wrote on last edited by
                          #12

                          even if i change the values of commtimeouts to

                          GetCommTimeouts(m_comPortHandle, &sCommTimeOuts);
                          sCommTimeOuts.ReadIntervalTimeout = 100; //[ms]
                          sCommTimeOuts.ReadTotalTimeoutMultiplier = 10; //[ms]
                          sCommTimeOuts.ReadTotalTimeoutConstant = 500; //[ms]
                          sCommTimeOuts.WriteTotalTimeoutMultiplier = 10; //[ms]
                          sCommTimeOuts.WriteTotalTimeoutConstant = 100; //[ms]
                          SetCommTimeouts(m_comPortHandle, &sCommTimeOuts);

                          i dint observe any change.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups