LCM Module:LCM KeyPad under Windows

From LEXWiKi

(Difference between revisions)
Jump to: navigation, search
(How to use MSComm in MFC)
Current revision (13:36, 25 February 2022) (edit) (undo)
(The Sample code source you can download from)
 
(5 intermediate revisions not shown.)
Line 1: Line 1:
[[Category:AllowPages]]
[[Category:AllowPages]]
== The Sample code source you can download from ==
== The Sample code source you can download from ==
-
Source file: [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/LCM_Keypad/Windows_base/LCM_Keypad_SDK_v1.0w_src.rar LCM_Keypad_SDK_v1.0w_src.rar]
 
-
Binary file: [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/LCM_Keypad/Windows_base/LCM_Keypad_SDK_v1.0w_bin.rar LCM_Keypad_SDK_v1.0w_bin.rar]
+
<Google Drive>
 +
 
 +
Source file: [https://drive.google.com/file/d/1mkVHeEs3rqZOhFSXLnr921C5AlEMA5AC/view?usp=sharing LCM_Keypad_SDK_v1.0w_Src]
 +
 
 +
Binary file: [https://drive.google.com/file/d/1NzA2ujWklukJH30FQkgUs9tlRouJwEZz/view?usp=sharing LCM_Keypad_SDK_v1.0w_Bin]
 +
 
 +
<FTP>
 +
 
 +
Source file: [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/LCM_Keypad/Windows_base/LCM_Keypad_SDK_v1.0w_src.rar LCM_Keypad_SDK_v1.0w_Src]
 +
 
 +
Binary file: [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/LCM_Keypad/Windows_base/LCM_Keypad_SDK_v1.0w_bin.rar LCM_Keypad_SDK_v1.0w_Bin]
== KeyPad Define ==
== KeyPad Define ==
Line 32: Line 41:
=== How to use MSComm in MFC ===
=== How to use MSComm in MFC ===
1.Download [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/LCM_Keypad/Windows_base/mscomm.rar mscomm.rar]
1.Download [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/LCM_Keypad/Windows_base/mscomm.rar mscomm.rar]
 +
2.Double click "install" to register MSCOMM32.OCX
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
3.Click right button of mouse on the dialog and choose "Insert ActiveX Control" as below picture
 +
[[Image:mscomm1.jpg]]
[[Image:mscomm1.jpg]]

Current revision

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