コード例 #1
0
        public async Task <IActionResult> Edit(string id, [Bind("id,gpio,status,desc")] LedModel ledModel)
        {
            if (id != ledModel.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ledModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LedModelExists(ledModel.id, ledModel.gpio))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(ledModel));
        }
コード例 #2
0
        public async Task <Message <LedModel> > SetLed(LedModel model)
        {
            var requestUrl = CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                            "AspCoreConsumingWebApi/api/LedModels/" + model.id + "/" + model.gpio));

            return(await PutAsync(requestUrl, model));
        }
コード例 #3
0
        public async Task <IActionResult> PostLedModel([FromBody] LedModel ledModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.LedModels.Add(ledModel);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (LedModelExists(ledModel.id, ledModel.gpio))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetLedModel", new { id = ledModel.id, gpio = ledModel.gpio }, ledModel));
        }
コード例 #4
0
        public async Task <Message <LedModel> > SetLed(string model)
        {
            LedModel ledModel   = JsonConvert.DeserializeObject <LedModel>(model);
            var      requestUrl = CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                                 "AspCoreConsumingWebApi/api/LedModels/" + ledModel.id + "/" + ledModel.gpio));

            return(await PutAsync(requestUrl, ledModel));
        }
コード例 #5
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            LedModel _ledModel = new LedModel();

            _ledModel.ComPort    = 3;
            _ledModel.BlockWidth = 40;
            _ledModel.LedMatrixIndicatorReadinessLOGO = "STE鈞耀科技測試用LOGO";
            _ledModel.Connect();
            _ledModel.Cleaner();
            _ledModel.Disconnect();
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("id,gpio,status,desc")] LedModel ledModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ledModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ledModel));
        }
コード例 #7
0
        private bool _clear()
        {
            LedModel _ledModel = new LedModel();

            _ledModel.ComPort    = 3;
            _ledModel.BlockWidth = 40;
            _ledModel.LedMatrixIndicatorReadinessLOGO = "STE鈞耀科技測試用LOGO";
            _ledModel.Connect();
            _ledModel.Cleaner();
            _ledModel.Disconnect();
            return(true);
        }
コード例 #8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            LedModel _ledModel = new LedModel();

            _ledModel.ComPort         = 3;
            _ledModel.BlockWidth      = 40;
            _ledModel.TrayAreaCount_X = 8080 / 1000;
            if (_ledModel.SetParameter("測試") == true)
            {
                _ledModel.Connect();
                string _trayArea = AreaName.Text;
                string Goods_Id  = GoodsId.Text;
                _ledModel.Active(_trayArea, "|" + Goods_Id + "|");
                _ledModel.Disconnect();
            }
        }
コード例 #9
0
        private bool _write()
        {
            LedModel _ledModel = new LedModel();

            _ledModel.ComPort         = 3;
            _ledModel.BlockWidth      = 40;
            _ledModel.TrayAreaCount_X = 8080 / 1000;
            if (_ledModel.SetParameter("測試") == true)
            {
                _ledModel.Connect();
                string _trayArea = AreaName.Text;
                string Goods_Id  = GoodsId.Text;
                _ledModel.Active(_trayArea, "|" + Goods_Id + "|");
                _ledModel.Disconnect();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #10
0
        public async Task <IActionResult> SetLed(string model, string id, string action)
        {
            LedModel ledModel = new LedModel();

            try
            {
                int gpio = int.Parse(action.Substring(0, 2));
                ledModel = await _context.LedModels.SingleOrDefaultAsync(m => m.id == id && m.gpio == gpio);

                ledModel.status = action.Contains("DESLIGA") ? 0 : 1;
            }
            catch { }
            if (!string.IsNullOrEmpty(ledModel.id))
            {
                var response = await ApiClientFactory.Instance.SetLed(ledModel);
            }
            if (!string.IsNullOrEmpty(model))
            {
                var response = await ApiClientFactory.Instance.SetLed(model);
            }
            return(RedirectToAction("Index"));
        }
コード例 #11
0
        /// <summary>
        /// LED屏协议码生成,以数据模型
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static byte[] GetLedBytes(LedModel model)
        {
            //协议头
            var hand = new byte[6]
            {
                0xAA,
                0x01,
                0xBB,
                0x51,
                0x54,
                0x00  // data size
            };
            //数据位
            var ledSet = new byte[5]
            {
                (byte)model.Paly,
                model.Speed,
                model.Wait,
                (byte)model.Color,
                0x63
            };
            //文本转义编码
            var bytes = Encoding.GetEncoding("GB2312").GetBytes(model.Text);
            //数据位拼装
            var list = new List <byte>();

            list.AddRange(ledSet);
            list.AddRange(bytes);
            //校验码计算,协议规定
            list.ForEach((byte o) =>
            {
                hand[5] += o;
            });
            //开始协议码拼装
            var code = new List <byte>();

            code.AddRange(hand);    //协议头
            code.AddRange(list);    //数据位
            code.Add(0xFF);         //协议结尾
            return(code.ToArray()); //转换为数组

            #region #1

            /*
             * byte[] temp = Encoding.GetEncoding("GB2312").GetBytes(text);
             * //text_GB.Text = BitConverter.ToString(temp, 0).Replace("-", string.Empty).ToLower();
             * byte[] tenp = new byte[11 + temp.Length + 1];
             * tenp[0] = 0xAA;
             * tenp[1] = 0x01;
             * tenp[2] = 0xBB;
             * tenp[3] = 0x51;
             * tenp[4] = 0x54;
             * tenp[5] = 0x00;//数据长度
             * tenp[6] = 0x01;
             * tenp[7] = 0x00;
             * tenp[8] = 0x00;
             * tenp[9] = 0x02;
             * tenp[10] = 0x63;
             * for (int i = 0; i < temp.Length; i++)
             * {
             *  tenp[i + 11] = temp[i];
             * }
             * for (int i = 0; i < tenp.Length - 6; i++)
             * {
             *  tenp[5] += tenp[i + 6];
             * }
             * tenp[11 + temp.Length] = 0xff;
             * return tenp;*/
            #endregion
            #region #2

            /*
             * byte[] collection = new byte[]
             * {
             *  170,
             *  1,
             *  187,
             *  81,
             *  84
             * };
             * byte[] collection2 = new byte[]
             * {
             *  1,
             *  0,
             *  0,
             *  2,
             *  99
             * };
             * byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(txt);
             * List<byte> list = new List<byte>();
             * list.AddRange(collection2);
             * list.AddRange(bytes);
             * byte totalByte = 0;
             * list.ForEach(delegate (byte o)
             * {
             *  totalByte += o;
             * });
             * List<byte> list2 = new List<byte>();
             * list2.AddRange(collection);
             * list2.Add(totalByte);
             * list2.AddRange(list);
             * list2.Add(byte.MaxValue);
             * return list2.ToArray();
             */
            #endregion
        }
コード例 #12
0
        /// <summary>
        /// LED屏协议码生成
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>
        public static byte[] GetLedBytes(string txt)
        {
            var model = new LedModel(txt);

            return(GetLedBytes(model));
        }
コード例 #13
0
        public async Task <IActionResult> PutLedModel([FromRoute] string id, int gpio, [FromBody] LedModel ledModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != ledModel.id || gpio != ledModel.gpio)
            {
                return(BadRequest());
            }

            _context.Entry(ledModel).State = EntityState.Modified;
            if (string.IsNullOrEmpty(ledModel.desc))
            {
                _context.Entry(ledModel).Property(p => p.desc).IsModified = false;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LedModelExists(id, gpio))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }