同系列文章:
注意:
- 针对使用C/C++版本的FaceId.dll
- 本代码仅适合PowerBuilder 10.5版本
- 代码仅供参考,需要根据具体的设备做调整
运行环境
下载安装Visual C++ Redistributable Packages for Visual Studio 2013
演示程序源代码下载:
程序界面:
示例代码(版本:PowerBuilder 10.5)
全局外部函数声明
FUNCTION ULong FaceId_Start(ref Blob Address, UInt Port, Int AddressFamily) LIBRARY "FaceId.dll" FUNCTION Long FaceId_SetSecretKey(ULong SocketHandle, ref Blob SecretKey) LIBRARY "FaceId.dll" FUNCTION ULong FaceId_GetSecretKey(ULong SocketHandle) LIBRARY "FaceId.dll" FUNCTION Long FaceId_Execute(ULong SocketHandle, ref Blob InBuffer, ref ULong hOutBuffer, ULong CodePage) LIBRARY "FaceId.dll" SUBROUTINE FaceId_Close(ULong SocketHandle) LIBRARY "FaceId.dll"
全局变量定义
constant ULong DeviceCodePage = 936
清空命令按钮clicked()事件
mle_answer.Text = ''
执行命令按钮clicked()事件
// 设备地址 Blob DeviceIP DeviceIP = Blob(sle_deviceip.Text) // 设备端口 Integer DevicePort DevicePort = Integer(sle_deviceport.Text) // 连接设备 ULong SocketHandle SocketHandle = FaceId_Start(ref DeviceIP, DevicePort, 2) IF SocketHandle = 0 THEN MessageBox('警告', '请输入正确的设备地址和通信端口!', Exclamation!, OK!) RETURN ELSE // 注意:通信密码要和设备中的密码一致 Blob SecretKey SecretKey = Blob('') IF FaceId_SetSecretKey(SocketHandle, ref SecretKey) <> 0 THEN FaceId_Close(SocketHandle) MessageBox('警告', '设置通信密码失败!', Exclamation!, OK!) RETURN END IF END IF // 清空原有文本 mle_answer.Text = '' // 获取命令 Blob Command Command = Blob(sle_command.Text) // 执行命令 ULong hOutBuffer Long ReceivedChars ReceivedChars = FaceId_Execute(SocketHandle, ref Command, ref hOutBuffer, DeviceCodePage) IF ReceivedChars > 0 THEN Long Index Index = 0 ULong Base Base = hOutBuffer String Answer String DealedChars DO WHILE Index < ReceivedChars DealedChars = String(Base, "Address") Answer = Answer + DealedChars Index = Index + Len(DealedChars) Base = Base + Len(DealedChars)*2 LOOP mle_answer.Text = Answer ELSE MessageBox('警告', '执行命令失败!', Exclamation!, OK!) END IF // 断开连接 FaceId_Close(SocketHandle)