private void btn2_NotifyConfirm_Click(object sender, EventArgs e) { if (GloablInfo.curDevInfo != null) { Thread th = new Thread(() => { NotifyDeviceUpdate st = new NotifyDeviceUpdate(); st.command = SmartDeviceInterface.COM_NOTIFY_UPDATE_JS_; st.data = new DeviceUpdateInfo[1]; st.data[0] = new DeviceUpdateInfo(); st.data[0].fileID = txtFileID.Text; string strSend = JsonConvert.SerializeObject(st); byte[] byteUTF8 = Encoding.Convert(Encoding.Default, Encoding.UTF8, UnicodeEncoding.Default.GetBytes(strSend)); strSend = UTF8Encoding.Default.GetString(byteUTF8); int iResponseLen = SmartDeviceInterface.MAX_DATA_LENGTH; GloablInfo.UpdateMsg("发送数据:" + strSend); string strJsonResponse = ""; IntPtr szResponse = Marshal.AllocHGlobal(iResponseLen); SmartDeviceInterface.SmartDevice_SetTimeOut(4 * 60 * 1000); int iResult = SmartDeviceInterface.SmartDevice_Common(GloablInfo.curDevInfo.deviceID, SmartDeviceInterface.COM_NOTIFY_UPDATE_JS, strSend, byteUTF8.Length, szResponse, ref iResponseLen); SmartDeviceInterface.SmartDevice_SetTimeOut(1000); if (iResult == SmartDeviceInterface.OPERATOR_SUCCESS && iResponseLen > 0) { byte[] byteJsonResponse = new byte[iResponseLen]; Marshal.Copy(szResponse, byteJsonResponse, 0, iResponseLen); byte[] byteDefault = Encoding.Convert(Encoding.UTF8, Encoding.Default, byteJsonResponse); strJsonResponse = Encoding.Default.GetString(byteDefault); } if (iResult == SmartDeviceInterface.OPERATOR_SUCCESS) { } MessageBox.Show(GloablInfo.GetResultDescription(iResult)); Marshal.FreeHGlobal(szResponse); GloablInfo.UpdateMsg("接收数据:" + strJsonResponse); }); th.Start(); } else { MessageBox.Show("请选择设备"); } }
public SDK() { InitializeComponent(); dtRecord.Columns.Add("deviceID"); dtRecord.Columns.Add("onlineFlag"); dtRecord.Columns.Add("recordTime"); dtRecord.Columns.Add("recordType"); dtRecord.Columns.Add("credenceType"); dtRecord.Columns.Add("userID"); dtRecord.Columns.Add("userType"); dtRecord.Columns.Add("picture"); dtRecord.Columns.Add("gateOpenMode"); dtRecord.Columns.Add("credenceNo"); dtRecord.Columns.Add("recCarNOColor"); dtRecord.Columns.Add("carLogo"); dtRecord.Columns.Add("carType"); dtRecord.Columns.Add("deviceEntryType"); dgvRecord.DataSource = dtRecord.DefaultView; dtEventRecord.Columns.Add("subDviceID"); dtEventRecord.Columns.Add("eventType"); dtEventRecord.Columns.Add("address"); dtEventRecord.Columns.Add("time"); dtEventRecord.Columns.Add("description"); dtEventRecord.Columns.Add("picID"); dgvEventRecord.DataSource = dtEventRecord.DefaultView; GloablInfo.sdk = this; m_SmartDevice_CallBack = mySmartDevice_CallBack; SmartDeviceInterface.SmartDevice_SetCallBack(m_SmartDevice_CallBack); unsafe { m_SmartDeviceNeedResponse_CallBack = mySmartDeviceNeedResponse_CallBack; } SmartDeviceInterface.SmartDevice_SetNeedResponseCallBack(m_SmartDeviceNeedResponse_CallBack); m_SmartDeviceOffline_CallBack = mySmartDeviceOffline_CallBack; SmartDeviceInterface.SmartDevice_SetOfflineCallBack(m_SmartDeviceOffline_CallBack); //设计命令超时1000毫秒 SmartDeviceInterface.SmartDevice_SetTimeOut(1000); //智能设备SDK初始化 SmartDeviceInterface.SmartDevice_Init(20001, 0); }
/// <summary> ///设置设备超时毫秒数 /// </summary> /// <param name="timeOut">超时毫秒数</param> /// <returns>无</returns> public void SmartDevice_SetTimeOut(Int32 timeOut) { SmartDeviceInterface.SmartDevice_SetTimeOut(timeOut); }