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

633 linux problem

Fabrizio

New member
Hello,

I wrote a very simple program to test the 633 (serial) from the linux test provided on the site.
I encounter a problem I can't understand.

Sometimes when I press a key, the incoming reponse contains "C=95(31 = Send Data to LCD...". I assume I haven't purge the buffer or something like that but i can't figured out what must be done.

Please help ! :)

Here is the code :
Code:
int main(int argc, char* argv[]) {
	
	/* Port initialisation */
	if ( Serial_Init(SERIALPORT,BAUDRATE)!=0 ) {
		printf(" [LCD] Could not open port \"%s\" at \"%d\" baud.\n",SERIALPORT,BAUDRATE);
		return(-1);
	} else 
		printf(" [LCD] Running\n");

	/* For some reason, Linux seems to buffer up data from the LCD, and they are sometimes
	 * dumped at the start of the program. Clear the serial buffer. */
	while ( BytesAvail() ) GetByte();

	/* Clear LCD */
	outgoing_command.command = 6;
	outgoing_command.data_length = 0;
	send_packet();
		
	/* Set mask */
	outgoing_command.command = 23;
	outgoing_command.data_length = 2;
	/* Press mask */
	outgoing_command.data[0] = KP_UP | KP_ENTER | KP_CANCEL | KP_LEFT | KP_RIGHT | KP_DOWN;
	/* Release mask */
	outgoing_command.data[1] = 0;
	send_packet();

	while (1) {
		usleep(100000);  /* 1/10 second */	
    /* Send line to the 633 using command 31 */
	outgoing_command.command = 31;
	outgoing_command.data[0]=0; /*col*/
	outgoing_command.data[1]=1; /*row*/
	memcpy(&outgoing_command.data[2],"Youhou",6);
	outgoing_command.data_length = 8;
	send_packet();

	int k,timed_out;
	timed_out = 1; /* default timed_out is true */
	for(k=0;k<=100000;k++)
    	if ( check_for_packet() ) {
			timed_out = 0; /* set timed_out to false */
			break;
		}
		
	if(timed_out)
		printf("Timed out waiting for a response.\n");		
		
		if( check_for_packet() )
		        ShowReceivedPacket();
}
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
USB LCD Displays - Graphic and Character LCDs with a Keypad

IanB

New member
How is the socket initialised? How is the data read from the socket? Can you zip up the full source and include here?

Ian.
 

Fabrizio

New member
The serial port is initialised exactly as in the sample from the site.

Find enclosed a tar.gz with the code that shows the problem, with a working makefile.
When I press keys of the 633, I sometimes receive C=95... instead of the key code.

I had to rename it as a zip to attach it. Sorry.

This is apparently due to the fact that I am sending data to the 633 in the loop. But I need to do it :)

I guess there is something I don't understand in the process of reading

Thanks for the reply.
 

Attachments

IanB

New member
What is probably happening here is that while you are in the usleep() or while writing the data to the LCD, the display asynchronously reports a packet back on the serial line with notification of a keypress. What then happens is your wait_for_reply() routine silently swallows that packet from the 633 and assumes it was the response to the write text command.

What happens next is the LcdWriteLine() function exits (because it has received a reply) and you check for a keypress packet. The packet you then receive is the one in response to the "Send data to LCD" (31) you sent earlier. Hence the confusion. To prove this, dump out the packet type received in you wait_for_reply() function. I see you have this in the routine already, just commented out. :)

Suggestions for a fix? A receive thread which can both handle async packets and allow a command sent from the PC to the display to block until the correct packet type is received. Alternatively, put a routine in the wait_for_reply() function to handle async packets. My preferred solution is the first one, because in the second case if the async packet handler takes a while to run, the sending thread will be blocked until it has processed the async packet.

I'm busy writing an example on Linux which works quite nicely using a few threads. Code will be posted on one of these forums soon.

Hope this helps,

Ian.
 
Top