Exemple #1
0
        /// <summary>
        /// 服务器端不停的接受客户端发送过来的消息
        /// </summary>
        /// <param name="o"></param>
        public void Recive(object o)
        {
            Socket socketSend = o as Socket;

            while (true)
            {
                try
                {
                    //客户端连接成功后,服务器应该接受客户端发来的消息
                    byte[] buffer = new byte[1024];
                    //实际接受到的有效字节数
                    int r = socketSend.Receive(buffer);
                    DeviceParameterInfo deviceParameter = new DeviceParameterInfo
                    {
                        DeviceInfoId   = buffer[0],
                        NowOutput      = buffer[1],
                        TargetOutput   = buffer[2],
                        SingleProgress = buffer[3],
                        StatusFlag     = 1,
                        StartTime      = DateTime.Now,
                        StopTime       = DateTime.Now,
                        SubTime        = DateTime.Now
                    };
                    DeviceParameterInfoService.Add(deviceParameter);

                    if (r == 0)
                    {
                        break;
                    }
                }
                catch
                { }
            }
        }
Exemple #2
0
        /// <summary>
        /// 服务器端不停的接受客户端发送过来的消息
        /// </summary>
        /// <param name="o"></param>
        public void Recive(object o)
        {
            Socket socketSend = o as Socket;

            while (true)
            {
                //客户端连接成功后,服务器应该接受客户端发来的消息
                byte[] buffer = new byte[1024];
                //实际接受到的有效字节数
                int r = socketSend.Receive(buffer);
                DeviceParameterInfo deviceParameter = new DeviceParameterInfo
                {
                    DeviceInfoId   = buffer[0],
                    NowOutput      = buffer[1],
                    TargetOutput   = buffer[2],
                    SingleProgress = buffer[3],
                    StatusFlag     = "1",
                    StartTime      = DateTime.Now,
                    StopTime       = DateTime.Now,
                    SubTime        = DateTime.Now
                };
                //通过容器创建一个对象。
                IApplicationContext         ctx = ContextRegistry.GetContext();
                IDeviceParameterInfoService DeviceParameterInfoService = ctx.GetObject("DeviceParameterInfoService") as IDeviceParameterInfoService;
                DeviceParameterInfoService.Add(deviceParameter);

                if (r == 0)
                {
                    break;
                }
            }
        }
        public static T GetDeviceInfo <T>(ClDeviceID device, DeviceParameterInfo <T> parameter)
        {
            int?fixedSize = parameter.ParameterInfo.FixedSize;

#if DEBUG
            bool verifyFixedSize = true;
#else
            bool verifyFixedSize = false;
#endif

            UIntPtr requiredSize;
            if (fixedSize.HasValue && !verifyFixedSize)
            {
                requiredSize = (UIntPtr)fixedSize;
            }
            else
            {
                ErrorHandler.ThrowOnFailure(clGetDeviceInfo(device, parameter.ParameterInfo.Name, UIntPtr.Zero, IntPtr.Zero, out requiredSize));
            }

            if (verifyFixedSize && fixedSize.HasValue)
            {
                if (requiredSize.ToUInt64() != (ulong)fixedSize.Value)
                {
                    throw new ArgumentException("The parameter definition includes a fixed size that does not match the required size according to the runtime.");
                }
            }

            IntPtr memory = IntPtr.Zero;
            try
            {
                memory = Marshal.AllocHGlobal((int)requiredSize.ToUInt32());
                UIntPtr actualSize;
                ErrorHandler.ThrowOnFailure(clGetDeviceInfo(device, parameter.ParameterInfo.Name, requiredSize, memory, out actualSize));
                return(parameter.ParameterInfo.Deserialize(actualSize, memory));
            }
            finally
            {
                Marshal.FreeHGlobal(memory);
            }
        }
        // GET: Device

        /// <summary>
        /// 添加设备信息
        /// </summary>
        /// <param name="deviceInfo"></param>
        /// <returns></returns>
        public ActionResult Add(DeviceInfo deviceInfo)
        {
            var deviceId = DeviceInfoService.GetEntities(u => (u.DeviceId == deviceInfo.DeviceId && u.IsDeleted == false)).FirstOrDefault();

            if (deviceId == null)
            {
                deviceInfo.SubTime = DateTime.Now;
                int id = DeviceInfoService.Add(deviceInfo).Id;
                DeviceParameterInfo deviceParameterInfo = new DeviceParameterInfo
                {
                    DeviceInfoId = id,
                    StatusFlag   = Glove.IOT.Model.Enum.StatusFlagEnum.未连接.ToString(),
                    SubTime      = DateTime.Now,
                };
                DeviceParameterInfoService.Add(deviceParameterInfo);
                //写操作日志
                OperationLogService.Add("添加设备", "设备管理", LoginInfo, deviceInfo.DeviceId, "");
                return(Content("Ok"));
            }
            else
            {
                return(Content("fail"));
            }
        }