• We recently switched our forum platform. If you experience any issues please email support@crystalfontz.com

Cfa 635

michael_s

New member
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:
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
}
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 ?
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

michael_s

New member
.... but send_packet from serial cpp do only the "packaging" with command,size,row,col, data and CRC.

It 'doesn't do any com parameter initialisation.

For me, send packet do the same as what I've written , no ? (from comment "Display text test")
What is different ?

Is there any command to transmit before to be able to send write command on lcd ?
 

CF Tech

Administrator
The LCD should always be ready to receive a packet (unless you are supposed to be waiting for a response or an acknowledge).

int Serial_Init(char *port, int baud_rate, CWnd* pParent) is what you are looking for to get the port open.

The reason to use 635_WinTest is that it is known working code. If your code does not work, make it more like 635_WinTest :)
 

Heffo

New member
Looking at your COM port initialization code above, you are enabling flow control (DTR & RTS control enable) try setting those to disabled and see how it goes.
 

michael_s

New member
Hello Everybody !

Everything is ok now I can display from my application.

Don't really undersatnd what 's difference beetween my code and yours but I don't care now !!!!!:D

I use Wintest "simplified" function (without history packet, Init comm messages, etc) and it works !

Thanks for your assistance ! (.....and I 'll be back for other prblm !:rolleyes: )
 

michael_s

New member
I've something to ask........., it's not really important but.....

I'd like to control a beep device with my cfa-635. So is there any way to do this ?
Is there any Output available on display ?

Thanks
Regards

Mic
 
USB LCD Displays - Graphic and Character LCDs with a Keypad

CF Tech

Administrator
If you have a buzzer that will accept 5v, you should be able to connect it to one of the GPIOs. Find a buzzer and post a link, I'll check it to see if it should work.

Mouser, Jameco or Digi-Key should have one, I would think.
 

michael_s

New member
I allready have a buzzer and I think it 's ok for using it with CFA-635.

Here's the link to the buzzer's datasheet : https://www.distrelec.com/distrelec/datasheets.nsf/WebAttachments/1ABA40EA47A5C962C1257296003A79EE/$File/SMA21Series.pdf

I should work easily....
 

CF Tech

Administrator
Yep, it should not be any trouble. Nice little buzzer.

Probably the easiest approach would be to connect it in parallel with one of the LEDs. Then you could control the LED with CrystalControl 2, and whenever the CC2 turns on the red LED, the buzzer would also fire.

 

Attachments

michael_s

New member
Hy !

Sure ! That solution is a good general solution but I want to do that more specific. 1 device, 1 control.

So what about even outputs of GPO ? They are "reserved" .... but if I don't plan to use additionnal SCAB, I can use them as I want like other outputs ?
 

CF Tech

Administrator
The one device should be hooked as shown in my sketch (the "circle B").

The one control would be CC2 turning on that LED (the fourth red LED).

The other pins cannot be controlled by the module--only one SCAB can be connected, the connectors on the CFA-635 are not identical.
 
Top