0

I am trying to read a serial port by using api calls createfile, readfile, getcommstate, setcommstate etc...

this all requires the proper declaration of a structure "dcb"

typedef struct _DCB {
 DWORD DCBlength;
 DWORD BaudRate;
 DWORD fBinary  :1;
 DWORD fParity  :1;
 DWORD fOutxCtsFlow  :1;
 DWORD fOutxDsrFlow  :1;
 DWORD fDtrControl  :2;
 DWORD fDsrSensitivity  :1;
 DWORD fTXContinueOnXoff  :1;
 DWORD fOutX  :1;
 DWORD fInX  :1;
 DWORD fErrorChar  :1;
 DWORD fNull  :1;
 DWORD fRtsControl  :2;
 DWORD fAbortOnError  :1;
 DWORD fDummy2  :17;
 WORD  wReserved;
 WORD  XonLim;
 WORD  XoffLim;
 BYTE  ByteSize;
 BYTE  Parity;
 BYTE  StopBits;
 char  XonChar;
 char  XoffChar;
 char  ErrorChar;
 char  EofChar;
 char  EvtChar;
 WORD  wReserved1;
} DCB, *LPDCB;

My first question is how would you declare this in mapbasic? Then how to determine the structures length?

1 Answer 1

1

DWORD = Integer (32-bit signed) WORD = SmallInt (16-bit signed) BYTE do not exist in mapbasic. CHAR may be done as string*1

You have to create another DLL, that sits between mapbasic and your DLL. This DLL should translate to a record format, where Mapbasic understands all the fields.

2
  • thanks for your response, can you explain further about these DLL's and how this might work, thanks
    – P Thomas
    Commented Nov 15, 2011 at 21:13
  • I have assumed this _DCB structure is part of DLL function calls? Since it uses types that mapbasic do not support, you need to write a DLL, that sits as a proxy between the DLL and mapbasic. This should remap the data structure into one that mapbasic understands. That is changing BYTES to WORDS etc. Commented Nov 16, 2011 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.