View Single Post
  #4  
Old 01-21-2010, 05:18 PM
juppmaifeld juppmaifeld is offline
Member
 
Join Date: Aug 2009
Posts: 43
Smile

Hi Nicknack,

thanks for your answer.

Question 1:
Yes I am sure the call failed. Try the updated test prog to see the result.

Question 2:
See my remark in the test prog.
// The call of SetCommState after each dcb.xx setting is just for test purpose to find out which dcb setting works and which not.
In my prog I first setup the whole dcb struct and then I call SetCommstate once only. Concerning the order of setting the dcb values I am almost sure it is independent.

Question 3:
I am aware of that. I added XonChar, XofChar (XonChar != XoffChar) to the test prog to show that the errors setting fOutxCtsFlow$ and fOutxDsrFlow$ are still there.

I did a lot of testing concerning the problem. I can't find anything wrong with how I handle the dcb settings. I also looked intensively into the dcb structure definition itself, changed and tested a lot of different things, but the problem did not disappear. Maybe it is a question of the underlying comm port hardware. I tested it on different hardware as I described it in my initial post but with no success.

I attach the updated test prog to this post again so that maybe others can try it out. Just copy it to the PIDE and do a RUN.

Jupp


#include "comm.ppl"

//Problem: Configuring COM Port with SetCommState fails for fOutxDsrFlow$ and fOutxDsrFlow$

// Open port !!! For trying the testprog change COM port to yuor necessity !!!
p$ = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

// Input and Output buffer size
SetupComm(p$, 128, 128);

// Setup port
struct(dcb$, DCB);
dcb.DCBlength$ = sizeof(dcb$);

struct(dcb0$, DCB);
dcb0.DCBlength$ = sizeof(dcb0$);

GetCommState(p$, &dcb$);
GetCommState(p$, &dcb0$);

// The call of SetCommState after each dcb.xx setting is just for test purpose to find out
// which dcb setting works and which not

dcb.BaudRate$ = 9600;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("1-Error: SetCommState BaudRate$ => false; ErrorCode:" + error$);
end;

dcb.ByteSize$ = 8;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("2-Error: SetCommState ByteSize$ => false; ErrorCode:" + error$);
end;

dcb.Parity$ = NOPARITY;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("3-Error: SetCommState Parity$ => false; ErrorCode:" + error$);
end;

dcb.StopBits$ = ONESTOPBIT;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("4-Error: SetCommState StopBits$ => false; ErrorCode:" + error$);
end;

dcb.fAbortOnError$ = FALSE;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("5-Error: SetCommState fAbortOnError$ => false; ErrorCode:" + error$);
end;

dcb.fBinary$ = TRUE;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("6-Error: SetCommState fBinary$ => false; ErrorCode:" + error$);
end;

dcb.fDsrSensitivity$ = FALSE;
if (SetCommState(p$, &dcb$) == false)
error$ = GetLastError();
ShowMessage("7-Error: SetCommState fDsrSensitivity$ => false; ErrorCode:" + error$);
end;

// Set RTS/CTS Handshake for example

dcb.fDtrControl$ = DTR_CONTROL_DISABLE;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("8-Error: SetCommState fDtrControl$ => false; ErrorCode:" + error$);
end;


dcb.fRtsControl$ = RTS_CONTROL_HANDSHAKE;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("10-Error: SetCommState fRtsControl$ => false; ErrorCode:" + error$);
end;


dcb.fOutX$ = TRUE;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("12-Error: SetCommState fOutX$ => false; ErrorCode:" + error$);
end;

dcb.fInX$ = TRUE;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("13-Error: SetCommState fInX$ => false; ErrorCode:" + error$);
end;

dcb.XonChar$ = 0x11;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("14-Error: SetCommState XonChar$ => false; ErrorCode:" + error$);
end;

dcb.XoffChar$ = 0x13;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("14-Error: SetCommState XonOff$ => false; ErrorCode:" + error$);
end;

// So far everything is okay...

//... but for setting fOutxDsrFlow$ = TRUE and fOutxCtsFlow$ = TRUE/FALSE
// I always get the Microsoft error code 87 -> ERROR_INVALID_PARAMETER, The parameter is incorrect.
// but according to the COMMPROP Structure Values of the selected CommPort ->
// dwProvCapabilities$ = DTR,DSR supported
// dwProvCapabilities$ = RTS, CTS supported
// these functionality is supported



dcb.fOutxDsrFlow$ = TRUE;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("9-Error: SetCommState fOutxDsrFlow$ => false; ErrorCode:" + error$);
end;

GetCommState(p$, &dcb$);
ShowMessage("dcb0.fOutxDsrFlow$ = " + dcb0.fOutxDsrFlow$ + "\n" + "dcb.fOutxDsrFlow$ = " + dcb.fOutxDsrFlow$);

dcb.fOutxCtsFlow$ = TRUE;
if (SetCommState(p$, &dcb$) == FALSE)
error$ = GetLastError();
ShowMessage("11-Error: SetCommState fOutxCtsFlow$ => false; ErrorCode:" + error$);
end;

GetCommState(p$, &dcb$);
ShowMessage("dcb0.fOutxCtsFlow$ = " + dcb0.fOutxCtsFlow$ + "\n" + "dcb.fOutxCtsFlow$ = " + dcb.fOutxCtsFlow$);

Last edited by juppmaifeld; 01-30-2010 at 11:11 AM.
Reply With Quote