添加项目文件。

This commit is contained in:
29353 2025-11-01 15:24:28 +08:00
parent d1737f1ff6
commit 53f828559a
17 changed files with 951 additions and 0 deletions

31
SysTunnelNuget.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36623.8 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TunnelNuget", "TunnelNuget\TunnelNuget.csproj", "{7B9289E9-0AE5-40A8-B5F8-1DCD5FC9F4E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UITunnel", "UITunnel\UITunnel.csproj", "{974DBE1D-C300-4BAA-8163-F7D7AA99CED4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B9289E9-0AE5-40A8-B5F8-1DCD5FC9F4E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B9289E9-0AE5-40A8-B5F8-1DCD5FC9F4E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B9289E9-0AE5-40A8-B5F8-1DCD5FC9F4E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B9289E9-0AE5-40A8-B5F8-1DCD5FC9F4E3}.Release|Any CPU.Build.0 = Release|Any CPU
{974DBE1D-C300-4BAA-8163-F7D7AA99CED4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{974DBE1D-C300-4BAA-8163-F7D7AA99CED4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{974DBE1D-C300-4BAA-8163-F7D7AA99CED4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{974DBE1D-C300-4BAA-8163-F7D7AA99CED4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {57D3B418-10FA-47A0-9EAF-3CDC901A6EF1}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rovinj.Tunnel;
using Rovinj.Reader.Silion;
using Rovinj.Device;
namespace TunnelNuget
{
/// <summary>
/// 隧道机接口
/// </summary>
public interface IRfidTunnel
{
/// <summary>
/// 连接通道机
/// </summary>
bool ConnectTunnel(SilionReaderConfig readerConfig, ConnectionConfig plcConnectionConfig, TunnelConfig tunnelConfig);
/// <summary>
/// 关闭通道机
/// </summary>
/// <returns></returns>
void CloseTunnel();
/// <summary>
/// 标签报告事件
/// </summary>
/// <param name="tunnel"></param>
/// <param name="e"></param>
void Tunnel_TagsReported(ITunnel tunnel, TunnelTagsReportedEventArgs e);
/// <summary>
/// 通道机读写器状态变化事件
/// </summary>
/// <param name="tunnel"></param>
/// <param name="e"></param>
void Tunnel_ReaderStateChanged(ITunnel tunnel, TunnelReaderStateChangedEventArgs e);
/// <summary>
/// 通道机PLC状态变化事件
/// </summary>
/// <param name="tunnel"></param>
/// <param name="e"></param>
void Tunnel_PlcStateChanged(ITunnel tunnel, TunnelPlcStateChangedEventArgs e);
/// <summary>
/// 通道机错误事件
/// </summary>
/// <param name="tunnel"></param>
/// <param name="e"></param>
void Tunnel_ErrorReceived(ITunnel tunnel, TunnelErrorReceivedEventArgs e);
}
}

214
TunnelNuget/InfoParams.cs Normal file
View File

@ -0,0 +1,214 @@
using Rovinj.Device;
using Rovinj.Reader.Silion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TunnelNuget
{
/// <summary>
/// 参数列表
/// </summary>
public class InfoParams
{
/// <summary>
/// Plc连接工厂
/// </summary>
public class PlcConnectionParams
{
/// <summary>
/// Ip地址
/// </summary>
public string Address { get; set; }
/// <summary>
/// 端口号
/// </summary>
public ushort Port { get; set; } = 502;
/// <summary>
/// 波特率
/// </summary>
public int BaudRate { get; set; } = 9600;
/// <summary>
/// 连接模式
/// </summary>
public ConnectionMode Mode { get; set; }
}
/// <summary>
/// 工厂/构建方法:根据参数创建配置对象
/// </summary>
public static class PlcConnectionFactory
{
public static ConnectionConfig Create(PlcConnectionParams parameters)
{
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
var config = new ConnectionConfig
{
ConnectionMode = parameters.Mode
};
// 设置网络相关字段
switch (parameters.Mode)
{
case ConnectionMode.Network:
config.ConnectionMode = parameters.Mode;
config.NetworkAddress = parameters.Address;
config.NetworkPort = parameters.Port;
break;
case ConnectionMode.Serial:
config.ConnectionMode = parameters.Mode;
config.SerialPortName = parameters.Address;
config.BaudRate = parameters.BaudRate;
break;
case ConnectionMode.USB:
config.ConnectionMode = parameters.Mode;
config.Address = parameters.Address;
break;
// 未来扩展…… 继续加
default:
throw new NotSupportedException($"不支持的连接模式: {parameters.Mode}");
}
return config;
}
}
/// <summary>
/// 参数对象:读写器连接参数
/// </summary>
public class ReaderConnectionParams
{
/// <summary>
/// 天线数量
/// </summary>
public object[] Args { get; set; }
/// <summary>
/// IP地址
/// </summary>
public string Address { get; set; }
/// <summary>
/// 连接模式
/// </summary>
public ConnectionMode Mode { get; set; }
}
/// <summary>
/// 工厂/构建方法:根据参数创建读取/写入器的连接配置对象
/// </summary>
public static class ReaderConnectionFactory
{
public static ConnectionConfig Create(ReaderConnectionParams parameters)
{
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
var config = new ConnectionConfig
{
ConnectionMode = parameters.Mode
};
// 设置网络相关字段(当前示例为网络模式)
switch (parameters.Mode)
{
case ConnectionMode.Network:
config.Args = new object[] { parameters.Args };
config.ConnectionMode = parameters.Mode;
config.NetworkAddress = parameters.Address;
break;
// 未来扩展…… 继续加
default:
throw new NotSupportedException($"不支持的连接模式: {parameters.Mode}");
}
return config;
}
}
/// <summary>
/// 参数对象RFID 读写器参数
/// </summary>
public class SilionReaderParams
{
/// <summary>
/// Q值-1=DynamicQ, 0~15时为StaticQ
/// </summary>
public int QValue { get; set; } = 5;
/// <summary>
/// Gen2会话取值范围为0、1、2、3
/// </summary>
public int Session { get; set; } = 1;
/// <summary>
/// 读取TID
/// </summary>
public bool ReadTID { get; set; } = false;
/// <summary>
/// 目标0=A, 1=B, 2=AB, 3=BA
/// </summary>
public int Target { get; set; } = 0;
/// <summary>
/// 0=FM0, 1=M2, 2=M4, 3=M8
/// </summary>
public int RfMode { get; set; } = 1;
/// <summary>
/// 快速模式
/// </summary>
public bool IsFastRead { get; set; } = true;
/// <summary>
/// 0快速模式1快速模式-读距离优先2快速模式-读次数优先3Ex10快速模式4按照给定的Gen2参数进行设置
/// </summary>
public int QuickModeType { get; set; } = 3;
/// <summary>
/// 天线
/// </summary>
public int AntCount { get; set; } = 4; // 天线数量,默认 4
/// <summary>
/// 天线功率,单位 dBm
/// </summary>
public double PowerDbm { get; set; } = 30;
}
/// <summary>
/// 工厂/构建方法:根据参数创建 SilionReaderConfig 对象
/// </summary>
public static class SilionReaderFactory
{
public static SilionReaderConfig Create(SilionReaderParams parameters)
{
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
// 基础配置
var readerConfig = new SilionReaderConfig
{
Qvalue = parameters.QValue,
Session = parameters.Session,
ReadTID = parameters.ReadTID,
Target = parameters.Target,
RfMode = parameters.RfMode,
IsFastRead = parameters.IsFastRead,
QuickModeType = parameters.QuickModeType,
Antennas = new List<SilionAntennaConfig>()
};
// 确保天线数量至少为 1避免出现无天线的情况。
int antCount = Math.Max(1, parameters.AntCount);
for (int i = 0; i < antCount; i++)
{
readerConfig.Antennas.Add(new SilionAntennaConfig
{
IsEnabled = true,
PortNumber = (ushort)(i + 1),
TxPowerInDbm = (int)parameters.PowerDbm
});
}
return readerConfig;
}
}
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("TunnelNuget")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TunnelNuget")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("7b9289e9-0ae5-40a8-b5f8-1dcd5fc9f4e3")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

245
TunnelNuget/RfidTunnel.cs Normal file
View File

@ -0,0 +1,245 @@
using Rovinj.Device;
using Rovinj.Reader.Silion;
using Rovinj.Tunnel;
using Rovinj.Tunnel.Plc;
using Rovinj.Reader;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Rovinj.Log;
namespace TunnelNuget
{
/// <summary>
/// 隧道机实现类
/// </summary>
public class RfidTunnel : IRfidTunnel
{
/// <summary>
/// 是否开始校验数量
/// </summary>
private volatile bool isStartCheckTags;
/// <summary>
/// 扫描ID的标签
/// </summary>
private string tagsScanId;
/// <summary>
/// 标签ID列表可以是EPC或TID
/// </summary>
private List<string> tagIdList = new List<string>();
/// <summary>
/// 当前PLC的状态
/// </summary>
private PlcStatus currentPlcStatus;
/// <summary>
/// 隧道是否已连接
/// </summary>
private bool isTunnelConnected;
/// <summary>
///通道机接口
/// </summary>
private ITunnel tunnel;
/// <summary>
/// 线程退出标识
/// </summary>
private CancellationTokenSource cancellationTokenSource;
/// <summary>
/// 检查标签线程
/// </summary>
private Thread checkTagsThread;
/// <summary>
/// Silion读写器支持R2000/E310/E710芯片支持1、2、3、4、8、16口天线
/// </summary>
private SilionReader silionReader;
public RfidTunnel() { }
/// <summary>
/// 通道机读写器状态变化事件
/// </summary>
/// <param name="tunnel"></param>
/// <param name="e"></param>
public void Tunnel_ReaderStateChanged(ITunnel tunnel, TunnelReaderStateChangedEventArgs e)
{
LogHelper.Error("e.RunningState:" + e.RunningState);
if (e.RunningState == 0)
{
//停止业务
LogHelper.Info("停止业务");
}
else if (e.RunningState == 1)
{
//启动业务
tagsScanId = e.ScanId;
LogHelper.Info("启动业务");
}
else
{
LogHelper.Info("其他状态");
//其他状态
}
}
/// <summary>
/// 标签报告事件
/// </summary>
/// <param name="tunnel"></param>
/// <param name="e"></param>
public void Tunnel_TagsReported(ITunnel tunnel, TunnelTagsReportedEventArgs e)
{
LogHelper.Error("e.Tags.Count:" + e.Tags.Count);
for (int i = 0; i < e.Tags.Count; i++)
{
Tag tag = e.Tags[i];
//过滤掉不符合扫描ID的标签
if (tag.ScanId != tagsScanId)
continue;
//如果配置为"TID"且TID不为空则使用TID否则使用EPC。检查标签ID是否已存在于 tagIdList 中,避免重复添加。
if (tunnel.TunnelConfig.TagIdFieldName == "TID" && !string.IsNullOrEmpty(tag.TID))
{
if (tagIdList.Contains(tag.TID))
continue;
tagIdList.Add(tag.TID);
LogHelper.Info("tag.TID" + tag.TID);
}
else
{
if (tagIdList.Contains(tag.EPC))
continue;
tagIdList.Add(tag.EPC);
LogHelper.Info("tag.TID" + tag.TID);
}
}
}
/// <summary>
/// 通道机PLC状态变化事件
/// </summary>
/// <param name="tunnel"></param>
/// <param name="e"></param>
public void Tunnel_PlcStateChanged(ITunnel tunnel, TunnelPlcStateChangedEventArgs e)
{
currentPlcStatus = e.PlcStatus;//记录当前PLC状态
LogHelper.Info("通道机PLC状态变化事件" + e.PlcStatus);
}
/// <summary>
/// 通道机错误接收事件
/// </summary>
/// <param name="tunnel"></param>
/// <param name="e"></param>
/// <exception cref="NotImplementedException"></exception>
public void Tunnel_ErrorReceived(ITunnel tunnel, TunnelErrorReceivedEventArgs e)
{
// 在控制台输出错误信息,包括错误消息和异常详情
Console.WriteLine($"错误信息:{e.ErrorMessage},异常:{e.Exception}");
LogHelper.Error("通道机错误接收事件:" + $"错误信息:{e.ErrorMessage},异常:{e.Exception}");
}
/// <summary>
/// 关闭通道机连接
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public void CloseTunnel()
{
if (tunnel == null)
return;
if (tunnel.Reader.IsStarted)
{
tunnel.StopReader();
}
StopTunnel();
tunnel.Close();
tunnel = null;
isTunnelConnected = false;
}
/// <summary>
/// 停止隧道
/// </summary>
private void StopTunnel()
{
if (tunnel.IsStarted)
tunnel.Stop();
isStartCheckTags = false;
if (cancellationTokenSource != null)
cancellationTokenSource.Cancel();
if (checkTagsThread != null)
checkTagsThread.Join();
}
/// <summary>
/// 连接隧道
/// </summary>
/// <param name="readerConfig">配置RFID读写器参数</param>
/// <param name="plcConnectionConfig">配置PLC连接方式</param>
/// <param name="tunnelConfig">配置读写器连接方式</param>
public bool ConnectTunnel(SilionReaderConfig readerConfig, ConnectionConfig plcConnectionConfig, TunnelConfig tunnelConfig)
{
if (!isTunnelConnected)
{
//创建并打开隧道
tunnel = TunnelFactory.CreateTunnel(TunnelType.SC201, tunnelConfig);//根据实际的设备选择对应的类型这里假设是SC201
tunnel.TagsReported += Tunnel_TagsReported; //读到标签时触发;
tunnel.ReaderStateChanged += Tunnel_ReaderStateChanged; //读写器状态变化
tunnel.PlcStateChanged += Tunnel_PlcStateChanged; //PLC 状态变化
tunnel.ErrorReceived += Tunnel_ErrorReceived; //收到错误时触发
if (tunnel.Open())
{
LogHelper.Info("连接成功");
isTunnelConnected = true;
//获取读写器能力(支持的发射功率列表)
silionReader = tunnel.Reader as SilionReader;
if (silionReader.ReaderCapability != null)
{
//发射率列表
List<double> doubles = new List<double>();
for (int i = 0; i < silionReader.ReaderCapability.TxPowers.Count; i++)
{
doubles.Add(silionReader.ReaderCapability.TxPowers[i]);
LogHelper.Info("发射率列表:" + silionReader.ReaderCapability.TxPowers[i]);
}
}
if (tunnel.Initialize())//复位
{
LogHelper.Info("复位成功");
//语音提示
SoundPlayer player = new SoundPlayer();
player.Play();
}
return true;
}
else
{
LogHelper.Error("连接失败");
tunnel.Close();
isTunnelConnected = false;
return false;
}
}
else
{
CloseTunnel();
return false;
}
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7B9289E9-0AE5-40A8-B5F8-1DCD5FC9F4E3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TunnelNuget</RootNamespace>
<AssemblyName>TunnelNuget</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ModuleAPI, Version=1.24.1.17, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Reader.Silion.1.4.3.3\lib\net461\ModuleAPI.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Device, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Device.1.2.0\lib\net461\Rovinj.Device.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Log, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Log.1.1.0\lib\net461\Rovinj.Log.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Reader, Version=1.4.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Reader.1.4.3\lib\net461\Rovinj.Reader.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Reader.Silion, Version=1.4.3.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Reader.Silion.1.4.3.3\lib\net461\Rovinj.Reader.Silion.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Tunnel, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Tunnel.1.9.0\lib\net461\Rovinj.Tunnel.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="InfoParams.cs" />
<Compile Include="IRfidTunnel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RfidTunnel.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="tunnelPlc.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
<package id="Rovinj.Device" version="1.2.0" targetFramework="net461" />
<package id="Rovinj.Log" version="1.1.0" targetFramework="net461" />
<package id="Rovinj.Reader" version="1.4.3" targetFramework="net461" />
<package id="Rovinj.Reader.Silion" version="1.4.3.3" targetFramework="net461" />
<package id="Rovinj.Tunnel" version="1.9.0" targetFramework="net461" />
</packages>

BIN
TunnelNuget/tunnelPlc.dll Normal file

Binary file not shown.

6
UITunnel/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

136
UITunnel/Program.cs Normal file
View File

@ -0,0 +1,136 @@
using Rovinj.Device;
using Rovinj.Log;
using Rovinj.Reader;
using Rovinj.Reader.Silion;
using Rovinj.Tunnel;
using Rovinj.Tunnel.Plc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TunnelNuget;
using static TunnelNuget.InfoParams;
namespace UITunnel
{
internal class Program
{
/// <summary>
/// 模拟连接隧道机
/// </summary>
static void Main(string[] args)
{
//创建日志目录
if (!Directory.Exists("log"))
Directory.CreateDirectory("log");
//初始化日志组件(仅供测试使用)
Rovinj.Log.LogHelper.InitLogger(new Rovinj.Log.TextLog($"log\\{DateTime.Now:yyyy-MM-dd}.log"));
//隧道机业务层
RfidTunnel rfidTunnel = new RfidTunnel();
////配置RFID读写器参数
#region RFID读写器参数
//SilionReaderConfig readerConfig = new SilionReaderConfig()
//{
// Qvalue = 5,
// Session = 1,
// ReadTID = false,
// Target = 0,
// RfMode = 1,
// IsFastRead = true,
// QuickModeType = 3,
// Antennas = new List<SilionAntennaConfig>(),
//};
//double power = 30; //功率
//int antCount = 4; //4个天线
////根据用户输入的天线数量(默认 4 个),给每个天线端口配置功率和启用状态。
//for (int i = 0; i < antCount; i++)
//{
// readerConfig.Antennas.Add(new SilionAntennaConfig()
// {
// IsEnabled = true,
// PortNumber = (ushort)(i + 1),
// TxPowerInDbm = power
// });
//}
#endregion
var readerParams = new SilionReaderParams
{
QValue = 5,
Session = 1,
ReadTID = false,
Target = 0,
RfMode = 1,
IsFastRead = true,
QuickModeType = 3,
AntCount = 4,
PowerDbm = 30
};
SilionReaderConfig readerConfig = SilionReaderFactory.Create(readerParams);
#region PLC连接方式
//ConnectionConfig plcConnectionConfig = new ConnectionConfig();
//plcConnectionConfig.ConnectionMode = ConnectionMode.Network; //网口连接模式
//plcConnectionConfig.NetworkAddress = "192.168.1.250"; //PLC IP地址
//plcConnectionConfig.NetworkPort = 502; //PLC 端口号
#endregion
var PlcParameters = new PlcConnectionParams
{
Address = "192.168.1.250",
Mode = ConnectionMode.Network,
Port = 502
};
ConnectionConfig plcConnectionConfig = PlcConnectionFactory.Create(PlcParameters);
#region
//ConnectionConfig readerConnectionConfig = new ConnectionConfig();
//readerConnectionConfig.Args = new object[] { antCount }; //天线数量默认是4个天线支持1,2,4,8,16
//readerConnectionConfig.ConnectionMode = ConnectionMode.Network; //网口连接模式
//readerConnectionConfig.NetworkAddress = "192.168.1.100";
#endregion
var ReaderParameters = new ReaderConnectionParams
{
Args = new object[] { 4 },
Mode = ConnectionMode.Network,
Address = "192.168.1.100"
};
ConnectionConfig readerConnectionConfig = ReaderConnectionFactory.Create(ReaderParameters);
//封装成隧道配置 根据用户选择,判断是三菱还是西门子 PLC。
TunnelConfig tunnelConfig = new TunnelConfig()
{
PlcType = PlcType.Mitsubishi_FX5U, //PLC类型
PlcConnectionConfig = plcConnectionConfig, //PLC连接配置
ReaderConnectionConfig = readerConnectionConfig, //读写器连接配置
ReaderConfig = readerConfig, //读写器配置
ReaderType = Rovinj.Tunnel.Reader.ReaderType.Silion //读写器类型
};
//西门子PLC暂时不支持使用串口的通讯方式
if ((tunnelConfig.PlcType == PlcType.Mitsubishi_FX5U || tunnelConfig.PlcType == PlcType.Siemens)
&& tunnelConfig.PlcConnectionConfig.ConnectionMode != ConnectionMode.Network)
{
LogHelper.Error("暂不支持的连接方式!");
return;
}
//是否连接成功
bool result = rfidTunnel.ConnectTunnel(readerConfig, plcConnectionConfig, tunnelConfig);
if (result)
{
}
}
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("UITunnel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UITunnel")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("974dbe1d-c300-4baa-8163-f7d7aa99ced4")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

103
UITunnel/UITunnel.csproj Normal file
View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{974DBE1D-C300-4BAA-8163-F7D7AA99CED4}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>UITunnel</RootNamespace>
<AssemblyName>UITunnel</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ModuleAPI, Version=1.24.1.17, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Reader.Silion.1.4.3.3\lib\net461\ModuleAPI.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Device, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Device.1.2.0\lib\net461\Rovinj.Device.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Log, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Log.1.1.0\lib\net461\Rovinj.Log.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Reader, Version=1.4.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Reader.1.4.3\lib\net461\Rovinj.Reader.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Reader.Silion, Version=1.4.3.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Reader.Silion.1.4.3.3\lib\net461\Rovinj.Reader.Silion.dll</HintPath>
</Reference>
<Reference Include="Rovinj.Tunnel, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Rovinj.Tunnel.1.9.0\lib\net461\Rovinj.Tunnel.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TunnelNuget\TunnelNuget.csproj">
<Project>{7b9289e9-0ae5-40a8-b5f8-1dcd5fc9f4e3}</Project>
<Name>TunnelNuget</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

9
UITunnel/packages.config Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
<package id="Rovinj.Device" version="1.2.0" targetFramework="net461" />
<package id="Rovinj.Log" version="1.1.0" targetFramework="net461" />
<package id="Rovinj.Reader" version="1.4.3" targetFramework="net461" />
<package id="Rovinj.Reader.Silion" version="1.4.3.3" targetFramework="net461" />
<package id="Rovinj.Tunnel" version="1.9.0" targetFramework="net461" />
</packages>