Data Communication 
Author Message
 Data Communication

I have a ALpha Machine connected to PC through a serial port. Data
transfered from the alpha machine needs to be displayed in Visual Basic
on PC. The C progam on PC works as a buffer between the ALpha and VB.
The C program gets the data from the port and sets it into the SHared
memory..from where the data gets picked up by the VB program.

Well I see a problem where the above protocol works fine if I run my C
program through a de{*filter*} in VC++ but when I execute the same C
program the values does not get transferred to VB. Can you please help
me to solve this issue.

For your reference I am attaching the C routine which reads the data
from the port..

//----------------------------------------------------------------------
//  int NEAR ReadCommBlock( HWND hWnd, LPSTR lpszBlock, int nMaxLength )
//
//  Description:
//     Reads a block from the COM port and stuffs it into
//     the provided buffer.
//
//  Parameters:
//     HWND hWnd
//        handle to TTY window
//
//     LPSTR lpszBlock
//        block used for storage
//
//     int nMaxLength
//        max length of block to read
//
//  Win-32 Porting Issues:
//     - ReadComm() has been replaced by ReadFile() in Win-32.
//     - Overlapped I/O has been implemented.
//
//----------------------------------------------------------------------

-----------------------------------------------------------------
 int NEAR ReadCommBlock( HWND hWnd, LPSTR lpszBlock, int nMaxLength )

{
   BOOL       fReadStat ;
   COMSTAT    ComStat ;
   DWORD      dwErrorFlags;
   DWORD      dwLength;
   DWORD      dwError;
   char       szError[ 10 ] ;
   int i;
   NPTTYINFO  npTTYInfo ;
        //BYTE imsg[4000];
        BYTE      imsg[ MAXBLOCK + 1];
        BYTE      jmsg[ MAXBLOCK + 1];
        BYTE      hmsg[ MAXBLOCK + 1];
        fputs("Enter ReadCommBlock\n", fptr);

   if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd )))
      return ( FALSE ) ;

   // only try to read number of bytes in queue
   ClearCommError( COMDEV( npTTYInfo ), &dwErrorFlags, &ComStat ) ;
   dwLength = min( (DWORD) nMaxLength, ComStat.cbInQue ) ;

   if (dwLength > 0)
   {
      fReadStat = ReadFile( COMDEV( npTTYInfo ), imsg,
                                    dwLength, &dwLength, &READ_OS(
npTTYInfo ) ) ;

          //for( i = 0; i < 15; i++ ) {

//      fputs( imsg, fptr);
    for( i = 0; i < 20; i++ ) {
                jmsg[i] = imsg[i];}

                fputs( jmsg, fptr);

//Dll Function is called to set the data into shared memory.

          SetSharedMem(jmsg,1000,0);
          GetSharedMem (hmsg,1000,0);

                fputs("GetSharedMem", fptr);
                        fputs( hmsg  , fptr);

      if (!fReadStat)
      {
         if (GetLastError() == ERROR_IO_PENDING)
         {
            OutputDebugString("\n\rIO Pending");
            // We have to wait for read to complete.
            // This function will timeout according to the
            // CommTimeOuts.ReadTotalTimeoutConstant variable
            // Every time it times out, check for port errors
            while(!GetOverlappedResult( COMDEV( npTTYInfo ),
               &READ_OS( npTTYInfo ), &dwLength, TRUE ))
            {
               dwError = GetLastError();
               if(dwError == ERROR_IO_INCOMPLETE)
                  // normal result if not finished
                  continue;
               else
               {
                  // an error occurred, try to recover
                  wsprintf( szError, "<CE-%u>", dwError ) ;
                  WriteTTYBlock( hWnd, szError, lstrlen( szError ) ) ;
                  ClearCommError( COMDEV( npTTYInfo ), &dwErrorFlags,
&ComStat ) ;
                  if ((dwErrorFlags > 0) && DISPLAYERRORS( npTTYInfo ))
                  {
                          wsprintf( szError, "<CE-%u>", dwErrorFlags ) ;
                          WriteTTYBlock( hWnd, szError, lstrlen(
szError ) ) ;
                  }
                  break;
               }

            }

              }
         else
         {
            // some other error occurred
            dwLength = 0 ;
            ClearCommError( COMDEV( npTTYInfo ), &dwErrorFlags,
&ComStat ) ;
            if ((dwErrorFlags > 0) && DISPLAYERRORS( npTTYInfo ))
            {
                    wsprintf( szError, "<CE-%u>", dwErrorFlags ) ;
                    WriteTTYBlock( hWnd, szError, lstrlen( szError ) ) ;
            }
         }
      }
   }

   return ( dwLength ) ;

Quote:
} // end of ReadCommBlock()

//----------------------------------------------------------------------

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Wed, 26 Feb 2003 05:59:19 GMT  
 Data Communication
humble suggestion: use the MSCOMM ActiveX control, available to you from the VB to handle the COM port. no shared memory, no C, no pain, but gain.
("now you're telling me")


Wed, 26 Feb 2003 11:02:28 GMT  
 Data Communication
Thanks for the suggestion. I am using a MSCOMM control. The application
I have displays the message in term window. I have to transfer this
message from here to other graphical interface. When I transfer this
value only the part of the message gets transferred..If this is a
timing issue then how come the term window gets the whole message.And I
am calling the graphics form after I receive the value in the term
window so timing should not be anything of concern.. Please help.



Quote:
> humble suggestion: use the MSCOMM ActiveX control, available to you

from the VB to handle the COM port. no shared memory, no C, no pain,
but gain.

Quote:
> ("now you're telling me")

Sent via Deja.com http://www.deja.com/
Before you buy.


Sun, 02 Mar 2003 03:21:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Data Communications, com port, PC, Turbo C

2. Data Communication

3. How to write codes for data communications?

4. Data Communication

5. Data communication through modem

6. Data Communication over USB

7. can you remove data from data streams???

8. Data Grid, Windows forms, Time Data Formatting

9. Recursive/nested data type (similar to data tree)

10. Common areas/common data/data sharing

11. data alignment (was Re: RISC data alignment, in comp.arch)

12. Data Source: Programmatically Configuring an ODBC Data Source - HELP PLEASE

 

 
Powered by phpBB® Forum Software