public int SetDevChnColor(ref SDK_CONFIG_VIDEOCOLOR pVideoColor) { IntPtr ptr = new IntPtr(); Marshal.StructureToPtr(pVideoColor, ptr, true); return(XMSDK.H264_DVR_SetDevConfig(m_lLogin, (uint)SDK_CONFIG_TYPE.E_SDK_VIDEOCOLOR, m_iChannel, ptr, (uint)Marshal.SizeOf(pVideoColor), 3000)); }
private void SaveConfig(int nLoginID, int nChannel, uint nConfig) { if (nLoginID > 0) { uint nBufSize = 0; uint nOutSize = 0; switch (nConfig) { case (uint)SDK_CONFIG_TYPE.E_SDK_CONFIG_SYSNORMAL: { nBufSize = (uint)Marshal.SizeOf(typeof(SDK_CONFIG_NORMAL)); SDK_CONFIG_NORMAL configNormal = new SDK_CONFIG_NORMAL(); configNormal.iDateSeparator = comboBoxDateSeparator.SelectedIndex; configNormal.iDSTRule = 0; // configNormal.iLanguage = 0; configNormal.iLocalNo = System.Int32.Parse(textBoxDeviceNo.Text); configNormal.iOverWrite = comboBoxDiskFullTo.SelectedIndex; configNormal.iVideoFormat = comboBoxVideoStandard.SelectedIndex; configNormal.iVideoStartOutPut = 0; configNormal.sMachineName = textBoxDeviceName.Text; configNormal.iWorkDay = System.Int32.Parse(textBoxStandbyTime.Text); configNormal.iTimeFormat = comboBoxTimeFormat.SelectedIndex; configNormal.iDateFormat = comboBoxDateFormat.SelectedIndex; IntPtr ptrBuf = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SDK_CONFIG_NORMAL))); Marshal.StructureToPtr(configNormal, ptrBuf, false); int nRet = XMSDK.H264_DVR_SetDevConfig(nLoginID, nConfig, nChannel, ptrBuf, nBufSize, 5000); if (nRet < 0) { if (nRet == (int)SDK_RET_CODE.H264_DVR_OPT_REBOOT) { MessageBox.Show("Need reboot device!"); } else { MessageBox.Show("Save config error!"); } } else { MessageBox.Show("Save config OK!"); } break; } case (uint)SDK_CONFIG_TYPE.E_SDK_CONFIG_NET_WIFI: { nBufSize = (uint)Marshal.SizeOf(typeof(SDK_NetWifiConfig)); curcfgWifi.bEnable = Convert.ToByte(checkEnableWifi.Checked); curcfgWifi.sSSID = textBoxSSID.Text; curcfgWifi.nKeyType = 1; //默认是ASCII curcfgWifi.sKeys = textBoxWifiPassword.Text; curcfgWifi.nChannel = 0; //对WEP加密方式,限制条件 if (Convert.ToBoolean(curcfgWifi.bEnable)) { if (comboBoxWifiEntryType.SelectedItem != null) { curcfgWifi.sEncrypType = comboBoxWifiEntryType.SelectedItem.ToString(); if (curcfgWifi.sEncrypType == "WEP") { curcfgWifi.nKeyType = comboBoxWifiKeyType.SelectedIndex; } } } string strIP, strMask, strGateway; strIP = textBoxWifiIP.Text; char[] ch = { '.' }; string[] arrIP = strIP.Split(ch, StringSplitOptions.RemoveEmptyEntries); if (arrIP.GetLength(0) == 4) { byte[] byIP = { byte.Parse(arrIP[0]), byte.Parse(arrIP[1]), byte.Parse(arrIP[2]), byte.Parse(arrIP[3]) }; curcfgWifi.HostIP.c = byIP; } strMask = textBoxWifiSubmask.Text; string[] arrMask = strMask.Split(ch, StringSplitOptions.RemoveEmptyEntries); if (arrMask.GetLength(0) == 4) { byte[] byMask = { byte.Parse(arrMask[0]), byte.Parse(arrMask[1]), byte.Parse(arrMask[2]), byte.Parse(arrMask[3]) }; curcfgWifi.Submask.c = byMask; } strGateway = textBoxWifiGateway.Text; string[] arrGateway = strGateway.Split(ch, StringSplitOptions.RemoveEmptyEntries); if (arrGateway.GetLength(0) == 4) { byte[] byGateway = { byte.Parse(arrGateway[0]), byte.Parse(arrGateway[1]), byte.Parse(arrGateway[2]), byte.Parse(arrGateway[3]) }; curcfgWifi.Gateway.c = byGateway; } if (curWifiDevice.sAuth != null && curWifiDevice.sNetType != null) //有修改 { curcfgWifi.sAuth = curWifiDevice.sAuth; curcfgWifi.sNetType = curWifiDevice.sNetType; } IntPtr ptrBufWifi = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SDK_NetWifiConfig))); Marshal.StructureToPtr(curcfgWifi, ptrBufWifi, false); int nRet = XMSDK.H264_DVR_SetDevConfig(nLoginID, nConfig, nChannel, ptrBufWifi, nBufSize, 5000); if (nRet < 0) { if (nRet == (int)SDK_RET_CODE.H264_DVR_OPT_REBOOT) { MessageBox.Show("Need reboot device!"); } else { MessageBox.Show("Save config error!"); } } else { MessageBox.Show("Save config OK!"); } break; } case (uint)SDK_CONFIG_TYPE.E_SDK_CONFIG_NET_DHCP: { nBufSize = (uint)Marshal.SizeOf(typeof(SDK_NetDHCPConfigAll)); SDK_NetWifiConfig cfgWifi = new SDK_NetWifiConfig(); //if( checkBoxDHCP.Enabled ) { curDHCPcfgAll.vNetDHCPConfig[2].bEnable = Convert.ToByte(checkBoxDHCP.Checked); } IntPtr ptrBufDHCP = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SDK_NetWifiConfig))); Marshal.StructureToPtr(curDHCPcfgAll, ptrBufDHCP, false); int nRet = XMSDK.H264_DVR_SetDevConfig(nLoginID, nConfig, nChannel, ptrBufDHCP, nBufSize, 1000); if (nRet < 0) { if (nRet == (int)SDK_RET_CODE.H264_DVR_OPT_REBOOT) { MessageBox.Show("Need reboot device!"); } else { MessageBox.Show("Save config error!"); } } else { // MessageBox.Show("Save config OK!"); } break; } } } }