125 lines
4.1 KiB
C#
125 lines
4.1 KiB
C#
using LolaiService.Devices.Tunnel;
|
||
using Rovinj.Device;
|
||
using Rovinj.Reader.Silion;
|
||
using Rovinj.Tunnel;
|
||
using Rovinj.Tunnel.Plc;
|
||
|
||
namespace LolaiService.Global
|
||
{
|
||
/// <summary>
|
||
/// 隧道机设备
|
||
/// </summary>
|
||
public class GlobalDeviceInfo
|
||
{
|
||
/// <summary>
|
||
/// 连接设备
|
||
/// </summary>
|
||
public static bool ConnectDevice()
|
||
{
|
||
//创建日志目录
|
||
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
|
||
|
||
|
||
#region 配置PLC连接方式
|
||
|
||
ConnectionConfig plcConnectionConfig = new ConnectionConfig();
|
||
plcConnectionConfig.ConnectionMode = ConnectionMode.Network; //网口连接模式
|
||
plcConnectionConfig.NetworkAddress = "192.168.1.250"; //PLC IP地址
|
||
plcConnectionConfig.NetworkPort = 502; //PLC 端口号
|
||
#endregion
|
||
|
||
|
||
#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
|
||
|
||
//封装成隧道配置 根据用户选择,判断是三菱还是西门子 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)
|
||
//{
|
||
// return false;
|
||
//}
|
||
|
||
//是否连接成功
|
||
bool result = rfidTunnel.ConnectTunnel(readerConfig, plcConnectionConfig, tunnelConfig);
|
||
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 隧道关门
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static string CloseDoorTunnel()
|
||
{
|
||
RfidTunnel rfidTunnel = new RfidTunnel();
|
||
|
||
return rfidTunnel.CloseDoor();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 隧道开门
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static string OpenDoorTunnel()
|
||
{
|
||
RfidTunnel rfidTunnel = new RfidTunnel();
|
||
|
||
return rfidTunnel.OpenDoor();
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
}
|