// jlidd-exampleDlg.cpp : 实现文件 // #ifdef _DEBUG #define new DEBUG_NEW #endif #include "stdafx.h" #include #include "jlidd-example.h" #include "jlidd-exampleDlg.h" #ifndef __MSG #define __MSG(x) x #endif // CjliddexampleDlg 对话框 #define MSG_SHOW_STR (WM_USER+1) #define MSG_TYPE_RESPONSE 1 #define MSG_TYPE_SYNC_REPORT 2 #define MSG_TYPE_ASYN_REPORT 3 CjliddexampleDlg::CjliddexampleDlg(CWnd* pParent /*=NULL*/) : CDialog(CjliddexampleDlg::IDD, pParent) , m_devId(65535) , m_Ip(_T("192.168.0.111")) , m_cardId(_T("")) , m_Msg(_T("")) , m_milliSeconds(3000) , m_SoundAction(1) , m_SoundIndex(0) , m_Timeouts(5000) , m_ComId(0) , m_TTSText(_T("")) , m_cmdText(_T("")) , m_selMode(0) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CjliddexampleDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_DEVID, m_devId); DDX_Text(pDX, IDC_DEVIP, m_Ip); DDX_Text(pDX, IDC_CARD, m_cardId); DDX_Text(pDX, IDC_MSG, m_Msg); DDX_Text(pDX, IDC_MILLISECONDS, m_milliSeconds); DDV_MinMaxInt(pDX, m_milliSeconds, 30, 65535); DDX_Text(pDX, IDC_SOUND, m_SoundIndex); DDV_MinMaxByte(pDX, m_SoundIndex, 0, 255); DDX_Text(pDX, IDC_ACTION, m_SoundAction); DDV_MinMaxByte(pDX, m_SoundAction, 0, 255); DDX_Text(pDX, IDC_TIMEOUTS, m_Timeouts); DDV_MinMaxUInt(pDX, m_Timeouts, 100, 120000); DDX_Text(pDX, IDC_COMID, m_ComId); DDV_MinMaxByte(pDX, m_ComId, 0, 9); DDX_Text(pDX, IDC_TTS_TEXT, m_TTSText); DDX_Text(pDX, IDC_CMD_TEXT, m_cmdText); DDX_CBIndex(pDX, IDC_SEL_PROCESS_MODE, m_selMode); } BEGIN_MESSAGE_MAP(CjliddexampleDlg, CDialog) ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_WM_DESTROY() ON_BN_CLICKED(IDC_ADD_RIGHT, &CjliddexampleDlg::OnBnClickedAddRight) ON_BN_CLICKED(IDC_REMOVE_RIGHT, &CjliddexampleDlg::OnBnClickedRemoveRight) ON_BN_CLICKED(IDC_CLEAR, &CjliddexampleDlg::OnBnClickedClear) ON_BN_CLICKED(IDC_CLEAR_RPT, &CjliddexampleDlg::OnBnClickedClearRpt) ON_MESSAGE(MSG_SHOW_STR, &CjliddexampleDlg::OnShowStr) ON_BN_CLICKED(IDC_CLEAR_SYNC, &CjliddexampleDlg::OnBnClickedClearSync) ON_BN_CLICKED(IDC_OPEN, &CjliddexampleDlg::OnBnClickedOpen) ON_BN_CLICKED(IDC_CLEAR_RIGHT, &CjliddexampleDlg::OnBnClickedClearRight) ON_BN_CLICKED(IDC_PLAYSOUND, &CjliddexampleDlg::OnBnClickedPlaySound) ON_BN_CLICKED(IDC_MEMO1, &CjliddexampleDlg::OnBnClickedMemo1) ON_BN_CLICKED(IDC_MEMO2, &CjliddexampleDlg::OnBnClickedMemo2) ON_BN_CLICKED(IDC_GETTIME, &CjliddexampleDlg::OnBnClickedGettime) ON_BN_CLICKED(IDC_SETTIME, &CjliddexampleDlg::OnBnClickedSettime) ON_BN_CLICKED(IDC_SETTIME2, &CjliddexampleDlg::OnBnClickedSettime2) ON_BN_CLICKED(IDC_CARD_ISSUE, &CjliddexampleDlg::OnBnClickedCardIssue) ON_BN_CLICKED(IDC_CARD_RECYCLE, &CjliddexampleDlg::OnBnClickedCardRecycle) ON_BN_CLICKED(IDC_CARD_STOP, &CjliddexampleDlg::OnBnClickedCardStop) ON_BN_CLICKED(IDC_CARD_START, &CjliddexampleDlg::OnBnClickedCardStart) ON_BN_CLICKED(IDC_REBOOT, &CjliddexampleDlg::OnBnClickedReboot) ON_BN_CLICKED(IDC_GET_ONLINE, &CjliddexampleDlg::OnBnClickedGetOnline) ON_BN_CLICKED(IDC_SHOW_TEXT, &CjliddexampleDlg::OnBnClickedShowText) ON_BN_CLICKED(IDC_SHOW_LED, &CjliddexampleDlg::OnBnClickedShowLed) ON_BN_CLICKED(IDC_SHOW_LED2, &CjliddexampleDlg::OnBnClickedShowLed2) ON_BN_CLICKED(IDC_GET_RIGHT, &CjliddexampleDlg::OnBnClickedGetRight) ON_BN_CLICKED(IDC_CHECK_RIGHT, &CjliddexampleDlg::OnBnClickedCheckRight) ON_BN_CLICKED(IDC_TTS, &CjliddexampleDlg::OnBnClickedTts) ON_BN_CLICKED(IDC_FIND_DEV, &CjliddexampleDlg::OnBnClickedFindDev) ON_BN_CLICKED(IDC_CALLTEXTCMD, &CjliddexampleDlg::OnBnClickedCalltextcmd) END_MESSAGE_MAP() // CjliddexampleDlg 消息处理程序 // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void CjliddexampleDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中 int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR CjliddexampleDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } /////////////////////////////////////////////////////////////////////////////////////////////// // #include #include "jlidd.h" HINSTANCE m_hInstance = NULL; call_protype m_call = NULL; freeBuffer_protype m_freeBuffer = NULL; setCallback_protype m_setCallback = NULL; const char *getCBCName( int callbackCode ) { switch(callbackCode) { case CBC_RT_SIGNAL: return __MSG("实时信号变化"); case CBC_RT_CONN: return __MSG("实时连接检测"); case CBC_RT_MESSAGE: return __MSG("实时调试消息"); case CBC_RT_SCAN: return __MSG("实时刷卡消息"); case CBC_LOG_2ND: return __MSG("刷身份证日志上报"); case CBC_LOG_CARD: return __MSG("刷卡日志上报"); case CBC_LOG_EVENT: return __MSG("事件日志上报"); case CBC_FIND_DEV: return __MSG("设备搜索回应"); } return __MSG("未知命令"); } std::vector SplitCString(CString strSource, char ch) { CString strTmp; std::vector vecString; int iPos=0; while(AfxExtractSubString(strTmp,strSource,iPos,ch)) { iPos++; vecString.push_back(strTmp); } return vecString; } int Callback_impl( int callbackCode, char *content ) { CjliddexampleDlg *dlg = (CjliddexampleDlg*)(::AfxGetApp()->GetMainWnd()); if ( dlg ) { CString msg; //显示到异步上报消息框中 switch(callbackCode) { case CBC_RT_SIGNAL: case CBC_RT_CONN: case CBC_RT_MESSAGE: case CBC_RT_SCAN: { msg.Format(__MSG("%s(回调命令字%d)-%s"),getCBCName(callbackCode),callbackCode,content); dlg->SendMessage(MSG_SHOW_STR,MSG_TYPE_SYNC_REPORT,(LPARAM)msg.GetBuffer()); } break; case CBC_LOG_2ND: case CBC_LOG_CARD: case CBC_LOG_EVENT: { msg.Format(__MSG("%s(回调命令字%d)-%s"),getCBCName(callbackCode),callbackCode,content); dlg->SendMessage(MSG_SHOW_STR,MSG_TYPE_ASYN_REPORT,(LPARAM)msg.GetBuffer()); } break; case CBC_FIND_DEV: default: { msg.Format(__MSG("%s(回调命令字%d)-%s"),getCBCName(callbackCode),callbackCode,content); dlg->SendMessage(MSG_SHOW_STR,MSG_TYPE_RESPONSE,(LPARAM)msg.GetBuffer()); } break; } //1.这是一个范例,实现为:收到任意刷卡数据直接发开门指令 if ( callbackCode==CBC_RT_SCAN && dlg->m_selMode==0 ) { //从请求数据解析出卡号和门号 std::vector strs = SplitCString(content,'|'); //最后的数据肯定是来源设备的ip:port CString fromIpPort = *strs.rbegin(); //构造指令,返回指令发向消息来源端口。使用65535不关心目标设备的板号,开门1持续3000毫秒 CString strLog = "65535|" + fromIpPort + "|1|3000"; char *buffer = call(CMD_OPENDOOR, strLog.GetBuffer()); TRACE("开门返回=%s\n",buffer); freeBuffer(buffer); } //2.这是一个范例,实现功能为:收到任意ic卡后直接开门并提示"请过闸"。收到任意条码(>10字节)则出票并提示"请取票后过闸" if ( callbackCode==CBC_RT_SCAN &&dlg->m_selMode==1 ) { //从请求数据解析出卡号和门号 std::vector strs = SplitCString(content,'|'); //最后的数据肯定是来源设备的ip:port CString fromIpPort = *strs.rbegin(); //偷懒的做法,直接拉大数组,防止引用到无效元素 strs.resize(30); //解析实时上报消息内容。消息格式如下(参考开发文档): //固定为10个0|姓名|性别|民族|生日|卡号或证件号码|地址|发卡机关|开始有效期|结束有效期|身份证附加信息|应用分类标志|设备标志|控制器验证结果0表示控制器已经直接开门其它表示错误|刷卡时间|读头号|门号|方向1进2出|类型|子类型|身份证芯片内码|对端通信地址 //来源设备标志 int devId = atoi(strs[12].GetBuffer()); //刷卡读头 int reader = atoi(strs[15].GetBuffer()); //刷卡读头对应的门(控制器侧的配置) int door = atoi(strs[16].GetBuffer()); //刷卡读头对应的方向1进,2出(控制器侧的配置) int dir = atoi(strs[17].GetBuffer()); //来源设备的ip,没有带端口信息,则返回指令将发向此IP的65534端口。 int pos = 0; CString devIp = fromIpPort.Tokenize(":",pos); //刷卡数据 CString cardId = strs[5]; //文本指令 CString text; if ( cardId.GetLength()<=10 ) { //指令含义:开1号门,持续300毫秒后恢复;显示屏提示请过闸。 //text.Format("open%d=%d;prompt=%s",1,300,"请过闸$"); text.Format("open%d=%d;prompt-page=2;prompt=^^%s^^%s^%s^^$;",1,300,cardId.GetBuffer(),"测试卡","2025-03-24 23:12:25"); } else if ( cardId.GetLength()>10 ) { //指令含义:提示请取票后过闸;备票;出票;开取票灯3-20秒超时关灯-20秒内检测到信号即开门1并关灯; text.Format("prompt-page=2;prompt=^^^^请取票后过闸^^^$;preTicket=1;doTicket=1;waitTicket=3120;"); } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%s", devId, //控制器序号 devIp.GetBuffer(), //控制器ip地址 text.GetBuffer() ); //请求 char *buffer = m_call(CMD_CALL_TEXT,cmd); if ( memcmp(buffer,"OK-ACKOK",8)==0 ) { TRACE("收到=%s,指令=%s。操作成功\n",cardId.GetBuffer(),cmd); } else { TRACE("收到=%s,指令=%s。操作失败,信息=%s\n",cardId.GetBuffer(),cmd,buffer); } m_freeBuffer(buffer); } } return 0; } BOOL CjliddexampleDlg::OnInitDialog() { CDialog::OnInitDialog(); // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 std::string file = _T(".\\jlidd.dll"); m_hInstance = LoadLibrary(file.c_str()); if ( m_hInstance ) { m_call = (call_protype)GetProcAddress(m_hInstance,_T("call")); m_freeBuffer = (freeBuffer_protype)GetProcAddress(m_hInstance,_T("freeBuffer")); m_setCallback = (setCallback_protype)GetProcAddress(m_hInstance,_T("setCallback")); } if ( m_call==NULL || m_freeBuffer==NULL || m_setCallback==NULL ) { ::AfxMessageBox(__MSG("加载失败!")); } //启动服务。第二个参数为空表示不使用ic读写器。为0表示使用ic读写器并且自动检测端口中,为1-9表示使用指定端口打开读写器。 char *cmd = ""; //不使用ic读写器 //char *cmd = "0"; //加载并自动检测ic读写器 //char *cmd = "1"; //使用端口1打开ic读写器 char *s = m_call(CMD_START,cmd); if ( s ) { m_Msg += s; m_Msg += "\r\n"; m_freeBuffer(s); this->UpdateData(FALSE); } //设置回调函数 m_setCallback(Callback_impl); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } void CjliddexampleDlg::OnDestroy() { CDialog::OnDestroy(); //停止服务 if ( m_call ) { char *s = m_call(CMD_STOP,""); m_freeBuffer(s); } ::FreeLibrary(m_hInstance); m_hInstance = NULL; } void CjliddexampleDlg::OnBnClickedOpen() { if ( !this->UpdateData() ) { return; } CString buf; this->GetDlgItem(IDC_RELAYER)->GetWindowText(buf); if ( buf.IsEmpty() || this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("设备IP地址及继电器编号不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%s|%d", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 buf.GetBuffer(), //继电器编号1-4 this->m_milliSeconds //开门时长,1/1000秒为单位 ); //请求 char *buffer = m_call(CMD_OPENDOOR,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedClearRight() { if ( !this->UpdateData() ) { return; } if ( this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("设备IP地址不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer() //控制器ip地址 ); //请求 char *buffer = m_call(CMD_CLEARRIGHT,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedAddRight() { this->UpdateData(); if ( this->m_cardId.IsEmpty() || this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("卡号及设备IP地址不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%s|%s|%s|%s|%d|%d|%d|%d", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 __MSG("测试名称"), //姓名,最大4字节,通常为空,特殊模式下才存储在控制板上 this->m_cardId.GetBuffer(), //卡号。10位卡号,18位身份证号码 "2000-01-01 00:00:00", //生效时间 "2030-01-01 23:59:59", //失效时间 255, //可刷卡的读头号,255表示所有 65535, //可用刷卡次数,65535表示不限次 0, //可用时段,0表示随时可开门 0 //人员类型 ); //请求 char *buffer = m_call(CMD_ADDRIGHT,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedRemoveRight() { this->UpdateData(); if ( this->m_cardId.IsEmpty() || this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("卡号及设备IP地址不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 this->m_cardId.GetBuffer() //卡号。10位卡号,18位身份证号码 ); //请求 char *buffer = m_call(CMD_REMOVERIGHT,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedClear() { this->UpdateData(); m_Msg = ""; this->UpdateData(FALSE); } void CjliddexampleDlg::OnBnClickedClearRpt() { this->GetDlgItem(IDC_MSG_RPT)->SetWindowText(""); } LRESULT CjliddexampleDlg::OnShowStr(WPARAM wParam, LPARAM lParam) { const char *data = (const char*)lParam; switch(wParam) { case MSG_TYPE_RESPONSE: this->GetDlgItem(IDC_MSG)->SetWindowText(data); break; case MSG_TYPE_SYNC_REPORT: this->GetDlgItem(IDC_MSG_SYNC)->SetWindowText(data); break; case MSG_TYPE_ASYN_REPORT: this->GetDlgItem(IDC_MSG_RPT)->SetWindowText(data); break; } return TRUE; } void CjliddexampleDlg::OnBnClickedClearSync() { this->GetDlgItem(IDC_MSG_SYNC)->SetWindowText(""); } void CjliddexampleDlg::OnBnClickedPlaySound() { this->UpdateData(); if ( this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("IP地址不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%d|%d|%d", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 this->m_SoundAction, //放音动作(0无效,1-250表示指定次数播放,(-4)无限循环播放,(-3)执行m_SoundIndex指定的指令,(-2)停止播放并清除待播放列表,(-1)清除待播放列表) this->m_SoundIndex, //指令或者声音索引(0-219 要播放语音索引。224-231 音量调节指令,值越大音量越大。242 循环播放,在语音播放过程中发送此命令可循环当前地址语音。254 停止播放指令。) ((CButton*)this->GetDlgItem(IDC_CHECK))->GetCheck()?1:0 //是直接播放还是放入播放队列 ); //请求 char *buffer = m_call(CMD_SOUND,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedMemo1() { ::AfxMessageBox("放音动作(0无效,1-250表示指定次数播放,如2表示播放2次;(-4)无限循环播放;(-3)执行m_SoundIndex指定的指令,(-2)停止播放并清除待播放列表,(-1)清除待播放列表)"); } void CjliddexampleDlg::OnBnClickedMemo2() { ::AfxMessageBox("指令或者声音索引(0-219 要播放语音索引。224-231 音量调节指令,值越大音量越大。242 循环播放,在语音播放过程中发送此命令可循环当前地址语音。254 停止播放指令。)"); } void CjliddexampleDlg::OnBnClickedGettime() { this->UpdateData(); if ( this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("IP地址不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer() //控制器ip地址 ); //请求 char *buffer = m_call(CMD_GETTIME,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedSettime() { this->UpdateData(); if ( this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("IP地址不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer() //控制器ip地址 ); //请求 char *buffer = m_call(CMD_SETTIME,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedSettime2() { this->UpdateData(); //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d", this->m_Timeouts); //请求 char *buffer = m_call(CMD_SET_TIMEOUT,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedCardStart() { this->UpdateData(); //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d",this->m_ComId); //端口号,0表示自动检测。1-9指定设备端口号 //请求 char *buffer = m_call(CMD_CARD_START,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedCardStop() { this->UpdateData(); //请求 char *buffer = m_call(CMD_CARD_STOP,""); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedCardIssue() { this->UpdateData(); //楼层权限。由;分隔多组,每组由:分隔控制器组号和楼层列表。楼层列表中楼层间由#分隔。 std::string floorRight = "10:1#15#25;11:1#2#3#4"; //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%s|%s|%s|%s|%d|%d|%d|%d|%d|%d|%s", 0, //控制器标志,未使用,填空或者0 "", //控制器ip地址,未使用,填空或者0 "", //姓名,未使用,填空或者0 "0", //卡号。10位卡号。0表示自动检测操作的卡。 "2000-01-01 00:00:00", //生效时间 "2030-01-01 23:59:59", //失效时间 255, //可刷卡的读头号,255表示所有 65535, //可用刷卡次数,65535表示不限次 0, //可用时段,0表示随时可开门 0, //人员类型 0, //操作密码 0, //反潜回 floorRight.c_str() ); //请求 char *buffer = m_call(CMD_CARD_ADDRIGHT,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedCardRecycle() { this->UpdateData(); //请求 char *buffer = m_call(CMD_CARD_REMOVERIGHT,""); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedReboot() { if ( !this->UpdateData() ) { return; } if ( this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("设备IP地址不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer() //控制器ip地址 ); //请求 char *buffer = m_call(CMD_REBOOT_DEV,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedGetOnline() { if ( !this->UpdateData() ) { return; } //请求 char *buffer = m_call(CMD_GET_ONLINE,""); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedShowText() { if ( !this->UpdateData() ) { return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%d|%d|%d|%d|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 3, //1进2出3双向 2, //显示的页面 0, //显示后恢复的页面 5, //显示时长,0表示永久显示 "张三^2忽略^1234567890^4忽略^刷卡成功^时间及详细信息^7忽略^8忽略" //内容 ); //请求 char *buffer = m_call(CMD_SHOW_TEXT,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedShowLed() { if ( !this->UpdateData() ) { return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%d|%s|%d", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 1, //1表示com1 "测试数据^第二行", //内容,多条以^分隔 5 //显示时长,0-120间,0表示一直显示。超时后恢复默认显示 ); //请求 char *buffer = m_call(CMD_SHOW_LEDX,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedShowLed2() { if ( !this->UpdateData() ) { return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%d|%s|%d", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 3, //3表示com3 "测试数据^第二行", //内容,多条以^分隔 5 //显示时长,0-120间,0表示一直显示。超时后恢复默认显示 ); //请求 char *buffer = m_call(CMD_SHOW_LEDX,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedGetRight() { this->UpdateData(); if ( this->m_cardId.IsEmpty() || this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("卡号及设备IP地址不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 this->m_cardId.GetBuffer() //卡号。10位卡号,18位身份证号码 ); //请求 char *buffer = m_call(CMD_GETRIGHT,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedCheckRight() { this->UpdateData(); if ( this->m_cardId.IsEmpty() || this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("卡号及设备IP地址不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 this->m_cardId.GetBuffer() //卡号。10位卡号,18位身份证号码 ); //请求 char *buffer = m_call(CMD_CHECKRIGHT,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedTts() { this->UpdateData(); if ( this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("设备IP地址不能为空!")); return; } if ( this->m_TTSText.IsEmpty() ) { ::AfxMessageBox(__MSG("放音内容不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%d|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 0, //0表示设备自动检测连接TTS设备的串口。需要先在板上配置。如果已经知道串口号,直接填串口号(1-4)即可。 this->m_TTSText.GetBuffer() //放音内容 ); //请求 char *buffer = m_call(CMD_PLAY_TTS,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedFindDev() { //组装请求命令 char cmd[1024] = {0}; //组播搜索目标ip固定为224.10.0.0,端口为3366 sprintf(cmd,"%s|%d","224.10.0.0",3366); //如果要普通广播搜索使用广播地址和端口65534 sprintf(cmd,"%s|%d","255.255.255.255",65534); //请求 char *buffer = m_call(CMD_FIND_DEV,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); } void CjliddexampleDlg::OnBnClickedCalltextcmd() { this->UpdateData(); if ( this->m_Ip.IsEmpty() ) { ::AfxMessageBox(__MSG("设备IP地址不能为空!")); return; } if ( this->m_cmdText.IsEmpty() ) { ::AfxMessageBox(__MSG("文本命令内容不能为空!")); return; } //组装请求命令 char cmd[1024] = {0}; sprintf(cmd,"%d|%s|%s", this->m_devId, //控制器序号 this->m_Ip.GetBuffer(), //控制器ip地址 this->m_cmdText.GetBuffer() //文本命令内容 ); //请求 char *buffer = m_call(CMD_CALL_TEXT,cmd); //显示返回结果 m_Msg += buffer; m_Msg += "\r\n"; this->UpdateData(FALSE); //释放内存 m_freeBuffer(buffer); }