物联网-登录模块实现,环境监测模块实现

1:添加引用Comm.Utils,Comm.Bus.dll,Comm.Sys.dll,完成后台代码实现
在这里插入图片描述
2:App.config配置服务器端的访问地址
在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <appSettings>
    <!-- 服务端接口请求地址 -->
    <add key="ServiceUrl" value="http://localhost/ServerLogin/Index.ashx" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>

3:在“MainWindow.xaml”中添加代码,完成界面制作
在这里插入图片描述

<Window x:Class="PcLogin.Main"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="main" Height="560.0" Width="1200.0" WindowStartupLocation="CenterScreen" WindowState="Maximized">
    <Window.Background>
        <ImageBrush ImageSource="Resource/In.gif"/>
    </Window.Background>
    <Grid>
   
        <Image x:Name="image"  Source="Resource/smart_community.png" MouseLeftButtonDown="image_MouseLeftButtonDown" HorizontalAlignment="Left" Height="61" Margin="537,210,0,0" VerticalAlignment="Top" Width="78" Stretch="Fill"/>
    </Grid>
</Window> 

4:在MainWindow.xam.cs中添加代码
在这里插入图片描述

namespace PcLogin
{
    /// <summary>
    /// main.xaml 的交互逻辑
    /// </summary>
    public partial class Main : Window
    {
        public Main()
        {
            InitializeComponent();
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //退出程序
            Environment.Exit(0);
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            this.Hide();
            huanjingjc h = new huanjingjc ();
            h.ShowDialog();
        }

        private void image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }
    }
}

5:启动测试
在这里插入图片描述
6:环境监测模块实现
在这里插入图片描述
7:在“MainWindow.xaml”中添加代码,完成界面制作
在这里插入图片描述

<Window x:Class="PcLogin.huanjingjc"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="四模拟量数据采集" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100*"/>
            <ColumnDefinition Width="150*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50*"/>
            <RowDefinition Height="50*"/>
            <RowDefinition Height="50*"/>
            <RowDefinition Height="50*"/>
            <RowDefinition Height="50*"/>
        </Grid.RowDefinitions>
        <Label Content="串口:" HorizontalAlignment="Right" VerticalAlignment="Center"/>
        <ComboBox Name="cmbPortList"  HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" Grid.Column="1"/>
        <Label Content="光照:" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="1"/>
        <Label Name="lblLight" Content="N/A" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1"/>
        <Label Content="温度:" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="2"/>
        <Label Name="lblTemperature" Content="N/A" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="2" Grid.Column="1"/>
        <Label Content="湿度:" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="3"/>
        <Label Name="lblHumidity" Content="N/A" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="3" Grid.Column="1"/>
        <Button Name="btnGet" Content="获取" Grid.Column="1" HorizontalAlignment="Left" Grid.Row="4" VerticalAlignment="Center" Width="75" Click="btnGet_Click"/>
        <Button x:Name="button" Content="返回" HorizontalAlignment="Left" Height="33" Margin="10,12,0,0" VerticalAlignment="Top" Width="62" Click="button_Click" RenderTransformOrigin="-6.933,5.833"/>
    </Grid>
</Window>

8:添加引用Comm.Utils,Comm.Bus.dll,Comm.Sys.dll,完成后台代码实现
在这里插入图片描述
9:在MainWindow.xam.cs中添加代码
在这里插入图片描述

namespace PcLogin
{
    
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class huanjingjc : Window
    {
        private static inPut_4 input4;
        /// <summary>
        /// 四输入模拟量操作类(需要引用Comm.Bus.dll、Comm.Sys.dll、Comm.Utils.dll、Newland.DeviceProviderImpl.dll、Newland.DeviceProviderIntf.dll、NewlandLibrary.dll)
        /// </summary>
        public static inPut_4 InPut_4
        {
            get
            {
                if (input4 == null)
                {
                    input4 = new inPut_4();
                }
                return input4;
            }
        }

        public huanjingjc()
        {
            InitializeComponent();
            this.Loaded += Window_Loaded;
        }

       

        private void GetPortList()
        {
            //SerialPort.GetPortNames()获取当前计算机的串口名称数组
            //遍历串口名称数组,并将其添加到ComboBox控件中
            foreach (string item in SerialPort.GetPortNames())
            {
                cmbPortList.Items.Add(item);
            }

            //若ComboBox控件记录数大于0,即有选项,则将当前选择的第一个项索引设置为索引0
            //否则添加一个“未找到串口”的项,并禁用“发送按钮”
            if (cmbPortList.Items.Count > 0)
            {
                cmbPortList.SelectedIndex = 0;
            }
            else
            {
                MessageBox.Show("未找到串口");
            }
        }

        private void btnGet_Click(object sender, RoutedEventArgs e)
        {
            if (cmbPortList.SelectedIndex == -1)
            {
                MessageBox.Show("请选择串口号");
                return;
            }


            if (!InPut_4.IsOpen)
            {
                InPut_4.Open(cmbPortList.SelectedValue.ToString());
            }

            //获取传感器数据
            lblLight.Content = InPut_4.getInPut4_Illumination();
            lblTemperature.Content = InPut_4.getInPut4_Temp();
            lblHumidity.Content = InPut_4.getInPut4_Humidity();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            GetPortList();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            this.Hide();
            //创建主窗体的对象并显示主窗体
            Main m = new Main();
            m.ShowDialog();


        }
    }
}

10:启动项目测试
在这里插入图片描述
熟悉操作用户登入
掌握温度,湿度,光照度等环境监测的方法

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云计算架构师0001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值