Hy everybody !
I start programing in C++ and try to write something on display cfa 365 20x4 with 4 led and keypad.
I try to do this on my own and finnally I get problem to write something even if I look into 635 winTest example.
Should be some error into params or something. I can explain what I do and hope you can help me:
So WriteFile return true but my lcd display still displaying boot text "Crystalfontz CFA-635 \n 20x4 + ....."
For me it' look like lcd receive data but is waiting another command (but which one ?) to refresh display.
anybody can help me ?
I start programing in C++ and try to write something on display cfa 365 20x4 with 4 led and keypad.
I try to do this on my own and finnally I get problem to write something even if I look into 635 winTest example.
Should be some error into params or something. I can explain what I do and hope you can help me:
Code:
char* port ="COM3";
DCB dcbCF;
HANDLE hCom = CreateFile( port,
GENERIC_READ | GENERIC_WRITE,
0, /* comm devices must be opened w/exclusive-access */
NULL, /* no security attrs */
OPEN_EXISTING, /* comm devices must use OPEN_EXISTING */
0, /* not overlapped I/O */
NULL /* hTemplate must be NULL for comm devices */
);
BOOL fSuccess = GetCommState(hCom, &dcbCF);
/* Fill in the DCB: baud=x, 8 data bits, no parity, 1 stop bit. */
dcbCF.BaudRate = 115200;
dcbCF.ByteSize = 8;
dcbCF.Parity = NOPARITY;
dcbCF.StopBits = ONESTOPBIT;
dcbCF.fRtsControl = RTS_CONTROL_ENABLE;
dcbCF.fDtrControl = DTR_CONTROL_ENABLE;
dcbCF.fAbortOnError = FALSE;
fSuccess = SetCommState(hCom, &dcbCF);
COMMTIMEOUTS
our_timeouts;
GetCommTimeouts(hCom,&our_timeouts) ; // address of comm. time-outs structure
//9600 is 1 byte per mS. Set it to 2 mS so the read will stay
//as long as data is coming in. Will wait at least 100mS for
//the 635 to respond.
our_timeouts.ReadIntervalTimeout=2000;
our_timeouts.ReadTotalTimeoutMultiplier=2000; // 1 second
our_timeouts.ReadTotalTimeoutConstant=2000;
SetCommTimeouts(
hCom, // handle of communications device
&our_timeouts) ; // address of comm. time-outs structure
/////// end test
//Display text test
char* cDestString ="Hello MPS !"; // message to display
//cDestString[0]='\0'; // row
//cDestString[1]='\0'; // col
//strcat(&cDestString[2],"Hello MPS !");
unsigned char cBuffer[80] ;
int iIndex = 0;
cBuffer[iIndex++]= 31; // "31 = Send Data to LCD (row,col)",
// because 20 char per line + row + col
cBuffer[iIndex++]= 22; //strlen(cDestString)+ 2 ;
cBuffer[iIndex++]='\0'; // row
cBuffer[iIndex++]='\0'; // column
unsigned int i;
for(i = iIndex; i< strlen(cDestString)+ iIndex; i++)
{
cBuffer[i]= (unsigned char)cDestString[i-iIndex];
}
unsigned short uRealLength = 26;
// GetFileCRC is the function named "get_crc" into 635 WinTest.sln
unsigned short as_word = DisplayDevices.Comm.GetFileCRC((unsigned char*)cBuffer,uRealLength);
cBuffer[i++]=DisplayDevices.packet.CRC.as_bytes[0];
cBuffer[i++]=DisplayDevices.packet.CRC.as_bytes[1];
DWORD bytes_written;
bytes_written=0;
if(!WriteFile(hCom, cBuffer, uRealLength, &bytes_written, NULL))
{
//WriteFile function failed
}
For me it' look like lcd receive data but is waiting another command (but which one ?) to refresh display.
anybody can help me ?
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.