示例#1
0
 /// <summary>
 /// 关闭串口方法
 /// </summary>
 /// <param name="f1"></param>
 public void ClosePort()
 {
     //MyPort.IsOpen?MyPort.():;
     if (MyPort.IsOpen)
     {
         MyPort.Close();
     }
     else
     {
         return;
     }
 }
示例#2
0
        public IActionResult Create([FromBody] Data data)
        {
            Console.WriteLine($"HTTP Post(Add) Data {data.ID}!");

            if (data == null)
            {
                return(BadRequest());
            }
            _context.Datas.Add(data);
            _context.SaveChanges();
            myPort.WriteLED(data.Red, data.Green, data.Yellow, data.Blue, data.White);
            if (data.Temperature == -1 && data.Light == -1)
            {
                saveData.Clear();
                Read(data);
                FileStream fs = new FileStream("D:\\temp\\save.json", FileMode.Open);
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List <Data>));
                ser.WriteObject(fs, saveData);
                fs.Close();
            }
            myPort.Close();
            return(CreatedAtRoute("GetData", new { id = data.ID }, data));
        }