没有合适的资源?快使用搜索试试~ 我知道了~
首页C# WPF新手入门之串口Modbus通讯
C# WPF新手入门之串口Modbus通讯
需积分: 29 33 下载量 121 浏览量
更新于2023-04-28
评论
收藏 817KB DOCX 举报
C#WPF制作的上位机和SmartGas气体分析模块通讯 需要完整项目文件的可在我的资源中另外下载
资源详情
资源评论
资源推荐
C# WPF 新手入门之串口 Modbus 通讯
本文是基于 C# WPF 制作的上位机软件,用于和红外气体分析模块通讯。由
于电脑串口是 232 标准,就是 -12v 代表 1 ,+12v 代表 0;而模块是单片机采用的 TTL
电平,+5v 代表 1, -5v 代表 0;因此,在硬件方面需要 MAX232 芯片做以下转换,以下为
硬件原理图:
实物图如下:
1
实际运行效果如下:
上图只是吹了口气测的浓度 O(∩_∩)O,主要是测试和模块的通讯,下面介
绍界面和程序实现方法。
2
1. 界面设计
用到的主要控件有 GroupBox, ComboBox,Button,ListView,TextBox。
以下为 XAML 代码:
<Window x:Class="SmartGasComm.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-
compatibility/2006"
xmlns:local="clr-namespace:SmartGasComm"
mc:Ignorable="d"
Title="smartGASComm" Height="450" Width="1085"
Background="#FFF0D0D0" Loaded="Window_Load" ResizeMode="CanMinimize"
WindowStartupLocation="CenterScreen">
3
此 处 需 要 按 CTRL+F1 展
开
内部使用 O(∩_∩)O~
<Grid>
<GroupBox Header="串口设置" HorizontalAlignment="Left"
Height="156" Margin="22,11,0,0" VerticalAlignment="Top" Width="213">
<Button x:Name="Serial_Btn" Content="打开串口"
HorizontalAlignment="Left" Margin="52,93,0,0" VerticalAlignment="Top"
Width="83" Height="32" FontSize="16" BorderBrush="#FF17E8CB"
Background="White" RenderTransformOrigin="4.916,3.769"
Click="Serial_Btn_Click"/>
</GroupBox>
<ComboBox x:Name="Combox1" HorizontalAlignment="Left"
Margin="123,39,0,0" VerticalAlignment="Top" Width="95" FontSize="16"/>
<Label Content="端口:" HorizontalAlignment="Left"
Margin="36,37,0,0" VerticalAlignment="Top" FontSize="16"/>
<Label Content="波特率:" HorizontalAlignment="Left"
Margin="36,74,0,0" VerticalAlignment="Top" FontSize="16"/>
<ComboBox x:Name="Combox2" HorizontalAlignment="Left"
Margin="123,75,0,0" VerticalAlignment="Top" Width="95" FontSize="16">
<ComboBoxItem Content="2400"/>
<ComboBoxItem Content="4800"/>
<ComboBoxItem Content="9600"/>
<ComboBoxItem Content="14400"/>
<ComboBoxItem Content="19200"/>
</ComboBox>
<GroupBox Header="模块通讯" HorizontalAlignment="Left"
Height="206" Margin="22,195,0,0" VerticalAlignment="Top" Width="213">
<TextBox x:Name="Address_Text" HorizontalAlignment="Left"
Height="28" Margin="98,5,0,0" TextWrapping="Wrap" Text="01"
VerticalAlignment="Top" Width="90" FontSize="16"/>
</GroupBox>
<Label x:Name="Lab1" Content="地址:" HorizontalAlignment="Left"
Margin="36,216,0,0" VerticalAlignment="Top" FontSize="16"/>
<Button x:Name="Btn1" Content="开始读取数据"
HorizontalAlignment="Left" Margin="53,259,0,0" VerticalAlignment="Top"
Width="136" Height="37" FontSize="16" Background="White"
BorderBrush="#FF17E8CB" Click="Btn1_Click"/>
<Button x:Name="Btn2" Content="停止读取数据"
HorizontalAlignment="Left" Margin="53,306,0,0" VerticalAlignment="Top"
Width="136" Height="37" FontSize="16" Background="White"
BorderBrush="#FF17E8CB" Click="Btn2_Click"/>
<Button x:Name="Btn3" Content="清除数据"
HorizontalAlignment="Left" Margin="53,352,0,0" VerticalAlignment="Top"
Width="136" Height="37" FontSize="16" Background="White"
BorderBrush="#FF17E8CB" Click="Btn3_Click"/>
4
剩余17页未读,继续阅读
萧汵
- 粉丝: 0
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0