請先看『使用說明』
LCM Module:LCM KeyPad under Windows
From LEXWiKi
Contents |
The Sample code source you can download from
Source file: LCM_Keypad_SDK_v1.0w_src.rar
Binary file: LCM_Keypad_SDK_v1.0w_bin.rar
KeyPad Define
key recrived value --------------------- key1 2 key2 4 key3 5 key4 7 key5 A key6 C
How to use the DEMO application
- COM Port selection
- Setting the text which you want to print to LCM from key1~key6
- Setting that print the text to upline or lowline by check the checkbox
- After setting , click OK
- Press the key on the keypad , the text you set will print to LCM
Sample code Introduction
flow chart
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));