VC programming

LK/ELK/VK/PK/OK/MX/GLK/EGLK/GVK/GLT Series

Moderators: Henry, Mods

Post Reply
contri
LCD?
Posts: 1
Joined: Mon Jun 23, 2003 8:52 am

VC programming

Post by contri »

Hello,

I am trying to control the LK202-24-USB from Visual C++ 6.0, opening a COM port and writing. Everything seemed to work fine, when I complicated the main a bit, with some more commands being sent one after the other, I found the program blocked.

What seems strange to me is that it is blocked inside WriteText function, which I am using to write to screen. Maybe, I am missing something about flow control? But, if I am not wrong, this display doesn't require it (?).

This is the main function. getActualPos returns winamp position in milliseconds. When it enters WriteText, it gets stuck there.

Code: Select all

int main(int argc, char* argv[])
{
	initDisplay ();
	initWinampController();
	clearDisplay();

	do{


		int pos = getActualPos();
		int minuts,seg,milis;
		char display[100]="hola";

		milis = pos % 1000;
		pos -= milis;

		seg = pos / 1000;
		minuts = seg / 60;

		seg = seg % 60;
		sprintf (display,"%.2d:%.2d:%.3d",minuts,seg,milis);
		gotoColRow (1,1);
		writeText (display,9);
		Sleep(100);

	}while (!mustExit());
	
	return 0;
}
Here are the functions that init and write / read to the display.
The strange problem is that in screen I see some "Debugging 1", and then nothing... it's blocked. But, if i press some key in the keypad ( its an MX212), it unblocks....

I don't know how to fix this... any tutorial I find, it seems to be correct...

Thanks...


Code: Select all

#include "lcd.h"
#include "winampcontroller.h"

HANDLE hSerialPort;
DWORD readThreadId;
int exitnow=0;

void initDisplay ()
{
	DCB dcb;

	hSerialPort = CreateFile ("COM3", 
						GENERIC_READ | GENERIC_WRITE,
						0,
						0,
						OPEN_EXISTING,
						FILE_ATTRIBUTE_NORMAL,
						0);

	if (hSerialPort == INVALID_HANDLE_VALUE) printf ("No puc obrir el com3");

	FillMemory (&dcb, sizeof(dcb),0);
	dcb.DCBlength = sizeof(dcb);

	if (!BuildCommDCB ("19200,n,8,1",&dcb)){
		printf ("Error 4");
	}

	if (!SetCommState (hSerialPort,&dcb)) printf ("Error 3");

	CreateThread (NULL, 0,(LPTHREAD_START_ROUTINE) waitKeys,
                 (LPVOID) NULL, 0, &readThreadId);
}

int mustExit (){
	return exitnow;
}

void shutdownDisplay (){
	CloseHandle (hSerialPort);
}


DWORD WINAPI waitKeys (LPVOID lpV) {
	DWORD dwCommEvent;
	DWORD dwRead;
	char chRead;

	if (!SetCommMask (hSerialPort, EV_RXCHAR)) printf ("nooops");

	for (;;){
		if (WaitCommEvent (hSerialPort, &dwCommEvent,NULL)){
			if (ReadFile (hSerialPort,&chRead,1,&dwRead,NULL)){
				if (chRead=='j') break;
				if (chRead=='K') nextTrack();
				else printf ("tecla: %c\n",chRead);
			} else printf ("error readfile");
		} else printf ("error waitcomm");
	}
	shutdownDisplay();
	exitnow=1;

	return 1;
}


void writeText (char *text,int num){
	unsigned long numbytes;

	printf ("Debugging 1");
	printf ("wf result: %d \n",WriteFile (hSerialPort,text,num,&numbytes,NULL));
	printf ("Debugging 2");
}

void gotoColRow (int col,int row){
	unsigned char data[]= {0xFE,0x47,(unsigned char) col,(unsigned char) row};
	unsigned long numbytes;

	printf ("deb. gcr 1");
	WriteFile (hSerialPort, data,4,&numbytes,NULL);	
	printf ("deb. gcr 2");
}

Post Reply