LCM Module:LCM KeyPad under Windows

From LEXWiKi

Jump to: navigation, search

Contents

The Sample code source you can download from

<Google Drive>

Source file: LCM_Keypad_SDK_v1.0w_Src

Binary file: LCM_Keypad_SDK_v1.0w_Bin

<FTP>

Source file: LCM_Keypad_SDK_v1.0w_Src

Binary file: LCM_Keypad_SDK_v1.0w_Bin

KeyPad Define

Image:KeyPad.jpg

key    recrived value
---------------------
key1       2
key2       4
key3       5
key4       7
key5       A
key6       C

How to use the DEMO application

Image:lcm_keypad_ap_w.jpg

  1. COM Port selection
  2. Setting the text which you want to print to LCM from key1~key6
  3. Setting that print the text to upline or lowline by check the checkbox
  4. After setting , click OK
  5. Press the key on the keypad , the text you set will print to LCM


Sample code Introduction

flow chart

Image:lcm_keypad_flowchart_w.jpg

How to use MSComm in MFC

1.Download mscomm.rar

2.Double click "install" to register MSCOMM32.OCX

3.Click right button of mouse on the dialog and choose "Insert ActiveX Control" as below picture

Image:mscomm1.jpg

4.Choose the "Microsoft Communications Control,version 6.0" and press OK in Insert ActiveX Control dialog as below picture

Image:mscomm2.jpg

define the received value of each key

#define KEYPAD1		'2'
#define KEYPAD2		'4'
#define KEYPAD3		'5'
#define KEYPAD4		'7'
#define KEYPAD5		'A'
#define KEYPAD6		'C'

set COM port and open

void CLCM_Keypad_SDK_v10wDlg::SetCOM(int port)
{
	//set COM port and open
	m_comm.put__CommPort(port);
	m_comm.put_Settings(_T("9600, n, 8, 1")); 
	m_comm.put_InBufferSize(1024);   
	m_comm.put_OutBufferSize(1024);   
	m_comm.put_InputMode(0);                  
	m_comm.put_InputLen(0); 
	m_comm.put_RThreshold(1);
 
	if(!m_comm.get_PortOpen()) 
		m_comm.put_PortOpen(TRUE);

	m_comm.get_Input();
}

Close serial port

m_comm.put_PortOpen(FALSE);

send data

int PortSend(int fdcom, char *data, int datalen)
{
	int len = 0;

	len = write(fdcom, data, datalen);
	if(len == datalen){
		return (len);
	}
	else{
		tcflush(fdcom, TCOFLUSH);
		return -1;
	}
} 

receive data

int PortRecv(int fdcom, char *data, int datalen)
{
 	int readlen, fs_sel = 0;
	fd_set	fs_read;
	struct timeval tv_timeout;

	FD_ZERO(&fs_read);
	FD_SET(fdcom, &fs_read);
	tv_timeout.tv_sec = TIMEOUT_SEC(datalen, baudrate);
	tv_timeout.tv_usec = TIMEOUT_USEC;

	fs_sel = select(fdcom+1, &fs_read, NULL, NULL, &tv_timeout);
	if(fs_sel){
		readlen = read(fdcom, data, datalen);
		return(readlen);
	}
	else{
		return(-1);
	}
	return (readlen);
} 

Set COM Port Device(COM1~COM6)

SetCOM(1);
SetCOM(2);
SetCOM(3);
SetCOM(4);
SetCOM(5);
SetCOM(6);

Use OnComm to receive the value of key

void CLCM_Keypad_SDK_v10wDlg::OnCommMscomm1()
{
	//change COleVariant type to String type
	COleVariant myVar;
	VARIANT var_in; 
	myVar.Attach (m_comm.get_Input());  //receive the data from keypad
	var_in = myVar;
	var_in.vt = VT_BSTR;
	_bstr_t bstr_t(var_in.bstrVal);
	CString keypad_input((char*)bstr_t); 
 
	//recognize the key , and send the text to LCM
	if ( keypad_input == KEYPAD1 )
	{
	}
	if ( keypad_input == KEYPAD2 )
	{
	}
	if ( keypad_input == KEYPAD3 )
	{
	}
	if ( keypad_input == KEYPAD4 )
	{
	}
	if ( keypad_input == KEYPAD5 )
	{
	}
	if ( keypad_input == KEYPAD6 )
	{
	}
}

send text to LCM

char szSendup[30] = {0x1b, 0x51, 0x41};
char szSenddown[30] = {0x1b, 0x51, 0x42};

sprintf(szSendup+3, "%s\r", text1);          //send to upline
m_comm.put_Output(COleVariant(szSendup));

sprintf(szSenddown+3, "%s\r", text1);        //send to low line
m_comm.put_Output(COleVariant(szSenddown));
Personal tools