C# 我能';当设备处于服务器模式时,在facestation suprema设备中取消选中use server mode with command(使用服务器模式)

C# 我能';当设备处于服务器模式时,在facestation suprema设备中取消选中use server mode with command(使用服务器模式),c#,wcf,C#,Wcf,我有一个基于服务的项目,我想用命令打开或关闭suprema设备服务器模式。。。我有Facestation设备,并在我的项目中开发了它…当设备不处于服务器模式时,我可以使用BSSDK的BS_WriteConfigUp方法在上面写入配置并成功写入,但当设备连接到服务器时,我无法写入配置并给出错误-105请帮助我…谢谢 public bool SetUseServer(ViewDevice Device, bool SetServer) { int _deviceId = 0;

我有一个基于服务的项目,我想用命令打开或关闭suprema设备服务器模式。。。我有Facestation设备,并在我的项目中开发了它…当设备不处于服务器模式时,我可以使用BSSDK的BS_WriteConfigUp方法在上面写入配置并成功写入,但当设备连接到服务器时,我无法写入配置并给出错误-105请帮助我…谢谢

public bool SetUseServer(ViewDevice Device, bool SetServer)
    {
        int _deviceId = 0;
        int handle = 0;
        BSSDK.BS_OpenInternalUDP(ref handle);
        BSSDK.BS_SearchDeviceInLAN(handle, ref m_NumOfDevice, m_DeviceID, m_DeviceType, DeviceAddr);
        uint targetAddress = (uint)IPAddress.Parse(Device.DeviceIp).Address;

        if (m_DeviceAddr.Length > 0 && Array.Exists(m_DeviceAddr, x => x.Equals(targetAddress)))
        {
            Device.TcpPort = Device.TcpPort ?? 1470;
            setConfigData.useServer = SetServer ? (uint)2 : 0;
            setConfigData.serverPort = (uint)serverPort;
            setConfigData.port = (uint)serverPort;
            setConfigData.maxConnection = maxConnections;
            setConfigData.useDHCP = false;
            setConfigData.syncTimeWithServer = SetServer;
            setConfigData.reserved = new byte[48];
            setConfigData.lanType = 1;
            byte[] serverIP = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)?.GetAddressBytes();
            string ipServer = Empty;
            if (serverIP != null)
            {
                foreach (var b in serverIP)
                {
                    ipServer = ipServer + b + ".";
                }
                ipServer = ipServer.Remove(ipServer.LastIndexOf('.'));
            }

            string defaultGateway = Empty;
            foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (f.OperationalStatus == OperationalStatus.Up)
                {
                    //UnicastIPAddressInformationCollection UnicastIPInfoCol = f.GetIPProperties().UnicastAddresses;
                    foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
                    {
                        defaultGateway = d.Address.ToString();
                    }
                }
            }

            byte[] addr = Encoding.ASCII.GetBytes(Device.DeviceIp);
            setConfigData.ipAddr = new byte[32];
            Buffer.BlockCopy(addr, 0, setConfigData.ipAddr, 0, addr.Length);

            addr = Encoding.ASCII.GetBytes(defaultGateway);
            setConfigData.gateway = new byte[32];
            Buffer.BlockCopy(addr, 0, setConfigData.gateway, 0, addr.Length);

            addr = Encoding.ASCII.GetBytes("255.255.255.0");
            setConfigData.subnetMask = new byte[32];
            Buffer.BlockCopy(addr, 0, setConfigData.subnetMask, 0, addr.Length);

            addr = Encoding.ASCII.GetBytes(ipServer);
            setConfigData.serverIP = new byte[32];
            Buffer.BlockCopy(addr, 0, setConfigData.serverIP, 0, addr.Length);

            IntPtr config = Marshal.AllocHGlobal(Marshal.SizeOf(setConfigData));
            Marshal.StructureToPtr(setConfigData, config, true);

            int index = Array.IndexOf(m_DeviceAddr, Array.Find(m_DeviceAddr, x => x.Equals(targetAddress)));
            _deviceId = m_DeviceID[index];

            if (BSSDK.BS_WriteConfigUDP(handle, targetAddress, _deviceId, BSSDK.BS_CONFIG_TCPIP, Marshal.SizeOf(setConfigData), config) == BSSDK.BS_SUCCESS)
            {
                Marshal.FreeHGlobal(config);
                if (SetServer && resetEvent.WaitOne(28000))
                {
                    return true;
                }
                else
                {
                    setConfigData.useServer = 0;
                    BSSDK.BS_WriteConfigUDP(handle, targetAddress, _deviceId, BSSDK.BS_CONFIG_TCPIP, Marshal.SizeOf(setConfigData), config);
                }
                return true;
            }
        }
        return false;
    }

在更改值之前,在连接/断开之前设置值如何?例如,在已经有连接之后更改SqlConnections连接字符串有什么意义请注意,这些类听起来不太常见。所以我们至少需要一个到他们文档的链接。在Web应用程序领域之外,返回数字错误代码是一个相当过时的概念。