Commit 75e3cbf5 authored by captainwong's avatar captainwong

add c# manualy parse ademco_id/event etc. example

parent cdf10bef
......@@ -38,7 +38,7 @@
## demo
演示基本使用方法
演示基本使用方法:正确性测试以及使用C++开发、直接引入头文件的示例
## server_demo
......@@ -46,7 +46,9 @@
## ademco_hb
动态链接库,提供解包、打包等接口
动态链接库,仅提供对网络数据的解包、打包等接口。
调用者需要在解包后再次对数据包解析,以提取安定宝ID、事件码等信息,建议使用定址取值或正则取值。
## dll_demo
......
using System;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace csharp_dll_demo
{
......@@ -31,7 +32,17 @@ namespace csharp_dll_demo
string raw = "\nC5C30053\"HENG-BO\"0000R000000L000000#90219125916578[#000000|1737 00 000]_09:11:19,08-05-2019\r";
Int32 commited = 0;
Int32 res = parse(raw, raw.Length, ref commited);
Console.WriteLine("res={0:D}, commited={1:D}", res, commited);
Console.WriteLine("res={0:D}, commited={1:D}", res, commited);
Console.WriteLine("parse ademco_id/event, etc.");
string pattern = @"\[\#(?<ademco_id>\d{6})\|(?<ademco_event>\d{4})\s(?<gg>\d{2})\s(?<zone>\d{3})\]";
foreach (Match match in Regex.Matches(raw, pattern))
{
GroupCollection groups = match.Groups;
foreach(Group group in groups)
{
Console.WriteLine(group.Name + " " + group.Value);
}
}
Console.WriteLine("");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment