-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSerialDeviceConfig.cs
More file actions
105 lines (95 loc) · 4.04 KB
/
SerialDeviceConfig.cs
File metadata and controls
105 lines (95 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SerialDeviceLib
{
public interface ISerialDeviceConfig
{
/// <summary>
/// 初始化函数
/// _serialDevice.ComPortReceived += _serialDevice_ComPortReceived;
/// _serialDevice.GetAvailablePorts_Dis();
/// _serialDevice.MessageReceived += _serialDevice_MessageReceived;
/// _serialDevice.ConnectionStatusChanged += _serialDevice_ConnectionStatusChanged;
/// </summary>
void _serialDeviceConfig();
/// <summary>
/// 串口状态改变事件
/// if (args.ConnectStatus == true)
/// {
/// status.Text = "串口已打开";
/// }
/// else
/// {
/// status.Text = "串口已关闭";
/// }
/// </summary>
/// <param name="sender"></param>
/// <param name="args">args.ConnectStatus串口状态</param>
void _serialDevice_ConnectionStatusChanged(object sender, ConnectionStatusChangedEventArgs args);
/// <summary>
/// 可用串口读取事件处理函数
/// args.DeviceInformationCollection.Count[i].ID为可用串口号
/// </summary>
/// <param name="sender"></param>
/// <param name="args">args.DeviceInformationCollection.Count[i].ID为可用串口号</param>
///
void _serialDevice_ComPortReceived(object sender, ComPortWasFoundEventArgs args);
/// <summary>
/// 数据接收事件处理函数
/// args.Data为数据对应16进制字符数组转换的字符串
/// 转换为对应字符_serialDevice.HexStringToAscii(args.Data.ToString()).ToString()
/// </summary>
/// <param name="sender"></param>
/// <param name="args">args.Data为接收到的byteArray字符串</param>
void _serialDevice_MessageReceived(object sender, MessageReceivedEventArgs args);
/// <summary>
/// 串口硬件连接函数
/// 设置串口_serialDevice.SetPort(deviceInformation.Id);
/// 连接串口 _serialDevice.Connect();
/// </summary>
void _serDeviceConnect();
///设置例子
//SerialDeviceInput _serialDevice = new SerialDeviceLib.SerialDeviceInput();
//DeviceInformation deviceInformation;
//private void _serialDeviceConfig()
//{
// _serialDevice.ComPortReceived += _serialDevice_ComPortReceived; ;
// _serialDevice.GetAvailablePorts_Dis();
// _serialDevice.MessageReceived += _serialDevice_MessageReceived;
// _serialDevice.ConnectionStatusChanged += _serialDevice_ConnectionStatusChanged;
//}
//private void _serialDevice_ConnectionStatusChanged(object sender, ConnectionStatusChangedEventArgs args)
//{
// if (args.ConnectStatus == true)
// {
// status.Text = "串口已打开";
// }
// else
// {
// status.Text = "串口已关闭";
// }
//}
//private void _serialDevice_ComPortReceived(object sender, ComPortWasFoundEventArgs args)
//{
// for (int i = 0; i < args.DeviceInformationCollection.Count; i++)
// {
// status.Text += args.DeviceInformationCollection[i].Id.ToString() + "\n";
// }
// deviceInformation = args.DeviceInformationCollection[1];
// status.Text = "串口:" + deviceInformation.Id.ToString();
//}
//private void _serialDevice_MessageReceived(object sender, MessageReceivedEventArgs args)
//{
// rcvdText.Text = args.Data.ToString() + _serialDevice.HexStringToAscii(args.Data.ToString()).ToString();
// status.Text = "接收数据:" + args.Data.ToString();
//}
//private void _serDeviceConnect()
//{
// _serialDevice.SetPort(deviceInformation.Id);
// _serialDevice.Connect();
//}
}
}