Serial Communication (API-calls) and possible error in CW API-Viewer 
Author Message
 Serial Communication (API-calls) and possible error in CW API-Viewer

Could anyone please help me out on the following:

API-calls for Serial-Communication.
I've obtained the prototypes for these calls via the API-viewer
which comes with CW20.
Additionally, I've obtained the necessary parameter datatypes/structures
and added these definition at the appropriate places in my application.

The problem.
    [ I've used the following API-call to open communication to COM1/COM2:   ]
    [ This function returns a handle/filedescriptor; HCOM.                   ]
    [ The handlevalue returned by CreateFileA is greater than 0, but I'm not ]
    [ 100% sure that the operation succeeded.                                ]
    [ The function is called like this:                                      ]
    [ Hcom = CreateFileA(DeviceName,FileIOMask,0,Security,OPEN_EXISTING,0,_NULL_) ]

    After (hopefully) obtaining the filedescriptor/handle (HCOM), I use the
    following function to obtain the CURRENT settings for the


    According to the CW API-Viewer,     |   On the other hand, Microsoft
    the DCB-structure is supposed       |   claims (ref: MSDN-CD) DCB
    to be like this:                    |   consists of the following:
    DCB        GROUP,TYPE               |   DCB        GROUP,TYPE
     Id           BYTE                  |   DCBlength         ULONG
     BaudRate     UNSIGNED              |   BaudRate          ULONG
     ByteSize     BYTE                  |   fBinary           ULONG
     Parity       BYTE                  |   fParity           ULONG
     StopBits     BYTE                  |   fOutxCtsFlow      ULONG
     RlsTimeout   UNSIGNED              |   fOutxDsrFlow      ULONG
     CtsTimeout   UNSIGNED              |   fDtrControl       ULONG
     DsrTimeout   UNSIGNED              |   fDsrSensitivity   ULONG
     XonChar      STRING(1)             |   fTXContinueOnXoff ULONG
     XoffChar     STRING(1)             |   fOutX             ULONG
     XonLim       UNSIGNED              |   fInX              ULONG
     XoffLim      UNSIGNED              |   fErrorChar        ULONG
     PeChar       STRING(1)             |   fNull             ULONG
     EofChar      STRING(1)             |   fRtsControl       ULONG
     EvtChar      STRING(1)             |   fAbortOnError     ULONG
     TxDelay      UNSIGNED              |   fDummy2           ULONG
    END                                 |   wReserved         SIGNED
                                        |   XonLim            SIGNED
                                        |   XoffLim           SIGNED
                                        |   ByteSize          BYTE
                                        |   Parity            BYTE
                                        |   StopBits          BYTE
This is confusing!                      |   XonChar           STRING(1)                                  |   XonChar           STRING(1)
Anyway - when used as parameter in the  |   XoffChar          STRING(1)                                  |   XoffChar          STRING(1)
GetCommState API-Call, *neither*        |   ErrorChar         STRING(1)                              |   ErrorChar         STRING(1)
of these structures' datamembers,       |   EofChar           STRING(1)                              |   EofChar           STRING(1)
e.g. DCB:BaudRate, result in correct    |   EvtChar           STRING(1)                              |   EvtChar           STRING(1)
values.                                 |   wReserved1        SIGNED                                 |   wReserved1        SIGNED
Furthermore, the testapplication        |   END                                                      |   END
performs an illegal operation
and shuts down.

I've narrowed down the possible errors to the following:
    * The CreateFileA-function fails, eventhough it returns a value
      greater than 0, resulting in everything following it to fail too.
          takes SECURITY_ATTRIBUTES as a pointer.
          The structure is defined like this and added to the testapplication:
               nLength                  DWORD
               lpSecurityDescriptor     LPVOID
               bInheritHandle           BOOL
          The structure variable is created like this:
              Security  LIKE(SECURITY_ATTRIBUTES)

          Does the compiler fix the pointer-parameter when perforiming:
          Hcom = CreateFileA(DeviceName,FileIOMask,0,Security,OPEN_EXISTING,0,_NULL_)
          If not, how should it be done??
    * Both DCB-structures suggested here are incorrect. (I've tried
    * The following declaration is incorrect for declaring a DCB-variable:
        DCBStruct   LIKE(DCB)
    * When calling GetComState, the following syntax is wrong:
      GetComState(HCOM, DCBStruct)
        - Should the DCBStruct variable be defined as a reference variable?
          (If yes; How?)
        - GetCommState(HANDLE,*DCB) indicates that DCB (=DCBStruct) is
          a pointer to a structure.  Does clarion resolve this automatically
          when compiling?  If not, how should it be done?

I urge someone from TOPSPEED to answer (too), since it seems like
the API-viewer has an incorrect DCB-structure definition...

    In advance, thanx.

            Eljar Ness

Thu, 19 Aug 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. API calls missing from readline API

2. Api call for HD serial number

3. CW 32bit API calls

4. Calling Windows NT APIs from CW

5. Calling all WinAPI Gurus: Help me make a list of Useful API functions for CW programmers

6. FindWindow API call in 16 bit CW

7. Protection Violation Error during GUI API call

8. API Call error

9. Static linking error MF Cobol WIN95 API calls

10. Raise error with API call?

11. API Question: API Menues...

12. Abstracted GUI APIs (was: RANT: Ruby GUI API)


Powered by phpBB® Forum Software