四模拟量采集器组zigbee转串口数据采集

来源:互联网 发布:linux 系统软件测试 编辑:程序博客网 时间:2024/05/17 03:37
xaml:
<Window x:Class="wsd.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded_1">    <Grid>        <ComboBox HorizontalAlignment="Left" Margin="191,10,0,0" VerticalAlignment="Top" Width="120"/>        <Label  Name="wendu" Content="N/A" HorizontalAlignment="Left" Margin="271,64,0,0" VerticalAlignment="Top"/>        <Label Name="shidu" Content="N/A" HorizontalAlignment="Left" Margin="271,132,0,0" VerticalAlignment="Top"/>        <Label  Name="guangzhao" Content="N/A" HorizontalAlignment="Left" Margin="271,206,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.024,1.244"/>        <Label Content="温度" HorizontalAlignment="Left" Margin="171,64,0,0" VerticalAlignment="Top" RenderTransformOrigin="1.483,0.193"/>        <Label Content="湿度" HorizontalAlignment="Left" Margin="171,132,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.252,1.811"/>        <Label Content="光照" HorizontalAlignment="Left" Margin="171,206,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.924,0.364"/>    </Grid></Window>
<pre name="code" class="csharp">cs:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using ZigBeeLibrary;using System.Windows.Threading;namespace wsd{    /// <summary>    /// MainWindow.xaml 的交互逻辑    /// </summary>    public partial class MainWindow : Window    {        ZigBee zigbee = null;        ComSettingModel model = new ComSettingModel();        DispatcherTimer timer = new DispatcherTimer();        private Dictionary<string, ZigBee> mdic = new Dictionary<string, ZigBee>();        public MainWindow()        {               InitializeComponent();        }        private void Window_Loaded_1(object sender, RoutedEventArgs e)        {                        if (model.ZigbeeCom == null)            {                MessageBox.Show("请检查串口");                return;            }            else             {                model.ZigbeeCom = "COM3";                if(!mdic.TryGetValue(model.ZigbeeCom,out zigbee))                {                    zigbee = new ZigBee(model);                    zigbee.InitSerialPort();                }              //  zigbee.GetSet();              //  wendu.Content = zigbee.temperatureValue;              //  shidu.Content = zigbee.humidityValue;              // guangzhao.Content = zigbee.lightValue;                timer.Tick+=new EventHandler(timertick);                timer.Interval = TimeSpan.FromSeconds(1);                timer.Start();                        }        }        private void timertick(object sender, EventArgs e)        {            zigbee.GetSet();            wendu.Content = zigbee.temperatureValue;            shidu.Content = zigbee.humidityValue;            guangzhao.Content = zigbee.lightValue;        }    }}


0 0
原创粉丝点击