add - 心跳数据解析完成

master
wangsr 1 year ago
parent 52321d7987
commit 3822a56b41

@ -32,7 +32,7 @@ namespace HighWayIot.Log4net
*
*/
//private readonly string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");
private readonly string fileName = "Z:\\Desktop\\日常代码\\HighWayIot\\HighWayIot.Log4net\\config\\log4net.config";
private readonly string fileName = "\\config\\log4net.config";
private LogHelper()
{

@ -39,8 +39,8 @@
<Reference Include="Oracle.ManagedDataAccess">
<HintPath>..\HighWayIot.Library\Oracle.ManagedDataAccess.dll</HintPath>
</Reference>
<Reference Include="SqlSugar">
<HintPath>Z:\Desktop\日常代码\HighWayIot\HighWayIot.Library\SqlSugar.dll</HintPath>
<Reference Include="SqlSugar, Version=5.1.4.130, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SqlSugar.5.1.4.130\lib\SqlSugar.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
@ -59,17 +59,17 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="domain\BaseBomInfo.cs" />
<Compile Include="domain\SysUserInfo.cs" />
<Compile Include="domain\BaseDeviceinfo.cs" />
<Compile Include="domain\RFIDHeartbeat.cs" />
<Compile Include="domain\RFIDState.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repository.cs" />
<Compile Include="service\IBaseBomInfoService.cs" />
<Compile Include="service\Impl\BaseBomInfoServiceImpl.cs" />
<Compile Include="service\ISysUserInfoService.cs" />
<Compile Include="service\IBaseDeviceinfoService.cs" />
<Compile Include="service\Impl\BaseSysUserInfoServiceImpl.cs" />
<Compile Include="service\Impl\BaseDeviceinfoServiceImpl.cs" />
<Compile Include="domain\RFIDContent.cs" />
<Compile Include="service\IContentService.cs" />
<Compile Include="service\Impl\BaseContentServiceImpl.cs" />
<Compile Include="service\IHeartbeatService.cs" />
<Compile Include="service\Impl\BaseHeartbeatServiceImpl.cs" />
<Compile Include="service\IStateService.cs" />
<Compile Include="service\Impl\BaseStateServiceImpl.cs" />
<Compile Include="SqlSugarHelper.cs" />
</ItemGroup>
<ItemGroup>
@ -84,6 +84,7 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -26,7 +26,7 @@ namespace HighWayIot.Repository
/**
* Mysql
*/
private static string mysqlConnStr = "Data Source=127.0.0.1;Port=6000;Initial Catalog=ry-cloud;uid=root;pwd=123456;Charset=utf8mb4;SslMode=none";
private static string mysqlConnStr = "Data Source=127.0.0.1;Port=3306;Initial Catalog=rfid;uid=root;pwd=123456;Charset=utf8mb4;SslMode=none";
//private static string oracleConnStr = "Data Source=175.27.215.92/helowin;User ID=aucma_mes;Password=aucma";
#endregion

@ -22,6 +22,10 @@
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.122.21.1" newVersion="4.122.21.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

@ -1,22 +0,0 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.domain
{
[SugarTable("BASE_BOMINFO")]
public class BaseBomInfo
{
/// <summary>
/// 主键标识
///</summary>
[SugarColumn(ColumnName = "OBJID", IsPrimaryKey = true, IsIdentity = true)]
public int ObjId { get; set; }
[SugarColumn(ColumnName = "BOM_CODE")]
public string bomCode { get; set; }
}
}

@ -1,59 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
namespace HighWayIot.Repository.domain
{
/// <summary>
/// 设备信息
///</summary>
[SugarTable("base_deviceInfo")]
public class BaseDeviceinfo
{
/// <summary>
/// 主键标识
///</summary>
[SugarColumn(ColumnName="objId" ,IsPrimaryKey = true ,IsIdentity = true )]
public int ObjId { get; set; }
/// <summary>
/// 机台编号
///</summary>
[SugarColumn(ColumnName="process_Id" )]
public int? ProcessId { get; set; }
/// <summary>
/// 位置编号
///</summary>
[SugarColumn(ColumnName="position_Id" )]
public int? PositionId { get; set; }
/// <summary>
/// 设备编号
///</summary>
[SugarColumn(ColumnName="device_Id" )]
public int? DeviceId { get; set; }
/// <summary>
/// 设备名称
///</summary>
[SugarColumn(ColumnName="device_Name" )]
public string DeviceName { get; set; }
/// <summary>
/// 设备 IP
///</summary>
[SugarColumn(ColumnName="device_Ip" )]
public string DeviceIp { get; set; }
/// <summary>
/// 设备端口
///</summary>
[SugarColumn(ColumnName="device_Port" )]
public int? DevicePort { get; set; }
/// <summary>
/// 设备天线
///</summary>
[SugarColumn(ColumnName="device_Ant" )]
public int? DeviceAnt { get; set; }
/// <summary>
/// 设备类型
///</summary>
[SugarColumn(ColumnName="device_Type" )]
public string DeviceType { get; set; }
}
}

@ -0,0 +1,28 @@
using SqlSugar;
using System;
namespace HighWayIot.Repository.domain
{
[SugarTable("rfid_content")]
public class RFIDContent
{
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int ID { get; set; }
[SugarColumn(ColumnName = "content")]
public string Content { get; set; }
[SugarColumn(ColumnName = "deviceno")]
public int DeviceNo { get; set; }
[SugarColumn(ColumnName = "readkind")]
public string ReadKind { get; set; }
[SugarColumn(ColumnName = "logtime")]
public DateTime LogTime { get; set; }
}
}

@ -0,0 +1,22 @@
using SqlSugar;
using System;
namespace HighWayIot.Repository.domain
{
[SugarTable("rfid_heartbeat")]
public class RFIDHeartbeat
{
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int ID { get; set; }
[SugarColumn(ColumnName = "deviceno")]
public int DeviceNo { get; set; }
[SugarColumn(ColumnName = "beattime")]
public DateTime BeatTime { get; set; }
}
}

@ -0,0 +1,24 @@
using SqlSugar;
using System;
namespace HighWayIot.Repository.domain
{
[SugarTable("rfid_state")]
public class RFIDState
{
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int ID { get; set; }
[SugarColumn(ColumnName = "deviceno")]
public int DeviceNo { get; set; }
[SugarColumn(ColumnName = "devicestate")]
public bool DeviceState { get; set; }
[SugarColumn(ColumnName = "logtime")]
public DateTime LogTime { get; set; }
}
}

@ -1,37 +0,0 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.domain
{
/// <summary>
/// 用户信息
///</summary>
[SugarTable("sys_user")]
public class SysUserInfo
{
/// <summary>
/// 用户Id自增主键
///</summary>
[SugarColumn(ColumnName = "user_id", IsPrimaryKey = true, IsIdentity = true)]
public int userId { get; set; }
/// <summary>
/// 用户名称
///</summary>
[SugarColumn(ColumnName = "user_name")]
public string userName { get; set; }
/// <summary>
/// 用户密码
///</summary>
[SugarColumn(ColumnName = "password")]
public string password { get; set; }
}
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SqlSugar" version="5.1.4.130" targetFramework="net48" />
</packages>

@ -1,14 +0,0 @@
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service
{
public interface IBaseBomInfoService
{
List<BaseBomInfo> GetBomInfos();
}
}

@ -7,13 +7,19 @@ using System.Threading.Tasks;
namespace HighWayIot.Repository.service
{
public interface ISysUserInfoService
public interface IContentService
{
/// <summary>
/// 获取用户列表
/// 获取RFID信息列表
/// </summary>
/// <returns></returns>
List<SysUserInfo> GetUserInfos( );
List<RFIDContent> GetContentInfos( );
/// <summary>
/// 新增一条信息
/// </summary>
/// <param name="content"></param>
void AddContentInfo(RFIDContent content);
}
}

@ -0,0 +1,33 @@
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service
{
public interface IHeartbeatService
{
/// <summary>
/// 获取RFID心跳状态列表
/// </summary>
/// <returns></returns>
List<RFIDHeartbeat> GetHeartbeatInfos();
/// <summary>
/// 新增一条心跳
/// </summary>
/// <param name="content"></param>
void AddHeartbeatInfo(RFIDHeartbeat heartbeat);
/// <summary>
/// 更新对应ID的心跳
/// </summary>
/// <param name="deviceno"></param>
/// <returns>影响的行数</returns>
int UpdateHeartbeatInfo(int deviceno);
}
}

@ -7,14 +7,19 @@ using System.Threading.Tasks;
namespace HighWayIot.Repository.service
{
public interface IBaseDeviceinfoService
public interface IStateService
{
/// <summary>
/// 根据工序编号获取设备集合
/// 获取RFID状态列表
/// </summary>
/// <param name="ProcessId"></param>
/// <returns></returns>
List<BaseDeviceinfo> GetDeviceInfoListByProcessId(int ProcessId);
List<RFIDState>GetStateInfos();
/// <summary>
/// 新增一条状态
/// </summary>
/// <param name="content"></param>
void AddStateInfo(RFIDState state);
}
}

@ -1,30 +0,0 @@
using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service.Impl
{
public class BaseBomInfoServiceImpl:IBaseBomInfoService
{
Repository<BaseBomInfo> _bomInfoRepository => new Repository<BaseBomInfo>("aucma_mes");
private LogHelper logHelper = LogHelper.Instance;
public List<BaseBomInfo> GetBomInfos()
{
try
{
var info = _bomInfoRepository.GetList();
return info;
}catch(Exception ex)
{
logHelper.Error("获取BOM集合异常", ex);
return null;
}
}
}
}

@ -0,0 +1,42 @@
using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service.Impl
{
public class BaseContentServiceImpl : IContentService
{
private LogHelper log = LogHelper.Instance;
Repository<RFIDContent> _repository => new Repository<RFIDContent>("mysql");
public List<RFIDContent> GetContentInfos()
{
try
{
List<RFIDContent> deviceInfo = _repository.GetList();
return deviceInfo;
}catch (Exception ex)
{
log.Error("RFID内容信息获取异常", ex);
return null;
}
}
public void AddContentInfo(RFIDContent content)
{
try
{
_repository.Insert(content);
}
catch (Exception ex)
{
log.Error("RFID内容信息插入异常", ex);
}
}
}
}

@ -1,23 +0,0 @@
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service.Impl
{
public class BaseDeviceinfoServiceImpl : IBaseDeviceinfoService
{
Repository<BaseDeviceinfo> _deviceInfoRepository => new Repository<BaseDeviceinfo>("mysql");
public List<BaseDeviceinfo> GetDeviceInfoListByProcessId(int ProcessId)
{
Expression<Func<BaseDeviceinfo, bool>> exp = s1 => s1.ProcessId == ProcessId;
List<BaseDeviceinfo> deviceinfos = _deviceInfoRepository.GetList(exp);
return deviceinfos;
}
}
}

@ -0,0 +1,55 @@
using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service.Impl
{
public class BaseHeartbeatServiceImpl : IHeartbeatService
{
private LogHelper log = LogHelper.Instance;
Repository<RFIDHeartbeat> _repository => new Repository<RFIDHeartbeat>("mysql");
public List<RFIDHeartbeat> GetHeartbeatInfos()
{
try
{
List<RFIDHeartbeat> deviceInfo = _repository.GetList();
return deviceInfo;
}catch (Exception ex)
{
log.Error("RFID心跳信息获取异常", ex);
return null;
}
}
public void AddHeartbeatInfo(RFIDHeartbeat heartbeat)
{
try
{
_repository.Insert(heartbeat);
}
catch (Exception ex)
{
log.Error("RFID心跳信息插入异常", ex);
}
}
public int UpdateHeartbeatInfo(int deviceno)
{
try
{
return _repository.AsUpdateable().SetColumns(x => x.BeatTime == DateTime.Now).Where(x => x.DeviceNo == deviceno).ExecuteCommand();
}
catch(Exception ex)
{
log.Error("RFID心跳信息更新异常", ex);
return -1;
}
}
}
}

@ -0,0 +1,42 @@
using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service.Impl
{
public class BaseStateServiceImpl : IStateService
{
private LogHelper log = LogHelper.Instance;
Repository<RFIDState> _repository => new Repository<RFIDState>("mysql");
public List<RFIDState> GetStateInfos()
{
try
{
List<RFIDState> deviceInfo = _repository.GetList();
return deviceInfo;
}catch (Exception ex)
{
log.Error("RFID状态信息获取异常", ex);
return null;
}
}
public void AddStateInfo(RFIDState state)
{
try
{
_repository.Insert(state);
}
catch (Exception ex)
{
log.Error("RFID状态信息插入异常", ex);
}
}
}
}

@ -1,30 +0,0 @@
using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service.Impl
{
public class BaseSysUserInfoServiceImpl : ISysUserInfoService
{
private LogHelper log = LogHelper.Instance;
Repository<SysUserInfo> _repository => new Repository<SysUserInfo>("mysql");
public List<SysUserInfo> GetUserInfos()
{
try
{
List<SysUserInfo> deviceInfo = _repository.GetList();
return deviceInfo;
}catch (Exception ex)
{
log.Error("用户信息获取异常", ex);
return null;
}
}
}
}

@ -0,0 +1,69 @@
using HighWayIot.Repository.domain;
using HighWayIot.Repository.service.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.TouchSocket
{
public class BufferAnalysis
{
/// <summary>
/// 心跳报文分析
/// </summary>
/// <param name="bytes"></param>
public static void HeartbeatSocket(byte[] bytes)
{
string a = Encoding.ASCII.GetString(bytes, 4, 4);
int deviceno;
if(int.TryParse(a, out deviceno))
{
BaseHeartbeatServiceImpl sql = new BaseHeartbeatServiceImpl();
if(sql.UpdateHeartbeatInfo(deviceno) == 0)
{
RFIDHeartbeat heartbeat = new RFIDHeartbeat()
{
DeviceNo = deviceno,
BeatTime = DateTime.Now,
};
sql.AddHeartbeatInfo(heartbeat);
}
}
}
/// <summary>
/// RFID发送设备状态
/// </summary>
/// <param name="bytes"></param>
public static void RFIDStatusSocket(byte[] bytes)
{
}
/// <summary>
/// RFID发送条码
/// </summary>
/// <param name="bytes"></param>
public static void RFIDCodeSocket(byte[] bytes)
{
}
/// <summary>
/// 将一个数组拆成另外一个数组
/// </summary>
/// <param name="originbyte">原始数组,被拆分的数组</param>
/// <param name="oringinstartindex">从原始数组第几个元素开始</param>
/// <param name="destbytelength">目标数组的长度</param>
/// <param name="destbytestartindex">目标数组开始的元素序号默认为0</param>
/// <returns></returns>
public static byte[] SplitByteArray(byte[] originbyte, int oringinstartindex, int destbytelength, int destbytestartindex = 0)
{
byte[] result = new byte[destbytelength];
System.Array.Copy(originbyte, oringinstartindex, result, destbytestartindex, destbytelength);
return result;
}
}
}

@ -51,7 +51,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="SocketConnect.cs" />
<Compile Include="BufferAnalysis.cs" />
<Compile Include="TcpServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@ -61,5 +62,15 @@
<ItemGroup>
<Analyzer Include="..\packages\TouchSocket.Core.2.0.0-beta.253\analyzers\dotnet\cs\TouchSocket.Core.SourceGenerator.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HighWayIot.Log4net\HighWayIot.Log4net.csproj">
<Project>{DEABC30C-EC6F-472E-BD67-D65702FDAF74}</Project>
<Name>HighWayIot.Log4net</Name>
</ProjectReference>
<ProjectReference Include="..\HighWayIot.Repository\HighWayIot.Repository.csproj">
<Project>{d0dc3cfb-6748-4d5e-b56a-76fdc72ab4b3}</Project>
<Name>HighWayIot.Repository</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Sockets;
namespace HighWayIot.TouchSocket
{
public class SocketConnect
{
public void SocketMonitor()
{
var service = new TcpService();
service.Connecting = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在连接
service.Connected = (client, e) => { return EasyTask.CompletedTask; };//有客户端成功连接
service.Disconnecting = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在断开连接,只有当主动断开时才有效。
service.Disconnected = (client, e) => { return EasyTask.CompletedTask; };//有客户端断开连接
service.Received = (client, e) =>
{
//从客户端收到信息
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意数据长度是byteBlock.Len
client.Logger.Info($"已从{client.Id}接收到信息:{mes}");
return EasyTask.CompletedTask;
};
service.Setup(new TouchSocketConfig()//载入配置
.SetListenIPHosts("192.168.11.211:6501", "192.168.11.212:6502", "192.168.11.213:6503", "192.168.11.214:6504")//同时监听两个地址
.ConfigureContainer(a =>//容器的配置顺序应该在最前面
{
a.AddConsoleLogger();//添加一个控制台日志注入注意在maui中控制台日志不可用
})
.ConfigurePlugins(a =>
{
//a.Add();//此处可以添加插件
}));
service.Start();//启动
}
}
}

@ -0,0 +1,142 @@
using HighWayIot.Log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Sockets;
namespace HighWayIot.TouchSocket
{
public class TcpServer
{
private static readonly Lazy<TcpServer> lazy = new Lazy<TcpServer>(() => new TcpServer());
public static TcpServer Instance => lazy.Value;
private static LogHelper logHelper = LogHelper.Instance;
public ServerState State
{
get => service.ServerState;
private set => State = value;
}
TcpService service = new TcpService();
public bool ServerStart(int port)
{
try
{
service.Connecting = (client, e) =>
{
logHelper.Info($"客户端{client.IP}正在连接");
return EasyTask.CompletedTask;
};//有客户端正在连接
service.Connected = (client, e) =>
{
logHelper.Info($"客户端{client.IP}成功连接");
return EasyTask.CompletedTask;
};//有客户端成功连接
service.Disconnecting = (client, e) =>
{
logHelper.Info($"客户端{client.IP}正在断开连接");
return EasyTask.CompletedTask;
};//有客户端正在断开连接,只有当主动断开时才有效。
service.Disconnected = (client, e) =>
{
logHelper.Info($"客户端{client.IP}断开连接");
return EasyTask.CompletedTask;
};//有客户端断开连接
service.Received = (client, e) =>
{
//从客户端收到信息
var mes = Encoding.ASCII.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意数据长度是byteBlock.Len
logHelper.Info($"已从{client.IP}:{client.Port}接收到信息:{mes}");
BufferMemory(BufferAnalysis.SplitByteArray(e.ByteBlock.Buffer, 0, e.ByteBlock.Len));
return EasyTask.CompletedTask;
};
service.Setup(new TouchSocketConfig()//载入配置
.SetListenOptions(option =>
{
option.Add(new TcpListenOption()
{
IpHost = port,
Name = "Server",//名称用于区分监听
ServiceSslOption = null,//可以针对当前监听单独启用ssl加密
Adapter = () => new NormalDataHandlingAdapter(),//可以单独对当前地址监听,配置适配器
//还有其他可配置项,都是单独对当前地址有效。
});
})
.ConfigureContainer(a =>//容器的配置顺序应该在最前面
{
a.AddConsoleLogger();//添加一个控制台日志注入注意在maui中控制台日志不可用
})
.ConfigurePlugins(a =>
{
//a.Add();//此处可以添加插件
}));
service.Start();//启动
logHelper.Info("监听服务启动成功");
return true;
}
catch (Exception ex)
{
logHelper.Error("监听服务启动失败! 错误代码" + ex.ToString());
return false;
}
}
public bool ServerStop()
{
try
{
service.Stop();
logHelper.Info("监听服务关闭成功!");
return true;
}
catch (Exception ex)
{
logHelper.Error("监听服务关闭失败! 错误代码" + ex.ToString());
return false;
}
}
public bool ServerDispose()
{
try
{
service.Dispose();
logHelper.Info("监听服务释放成功!");
return true;
}
catch (Exception ex)
{
logHelper.Error("监听服务释放失败! 错误代码" + ex.ToString());
return false;
}
}
private void BufferMemory(byte[] bytes)
{
byte[] identify = new byte[2] { bytes[1], bytes[2] };
if (identify[0] == 0x30 && identify[1] == 0x31)
{
BufferAnalysis.HeartbeatSocket(bytes);
}
else if (identify[0] == 0x30 && identify[1] == 0x34)
{
BufferAnalysis.RFIDStatusSocket(bytes);
}
else if (identify[0] == 0x35 && identify[1] == 0x33)
{
BufferAnalysis.RFIDCodeSocket(bytes);
}
}
}
}

@ -6,6 +6,18 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.1.0.0" newVersion="8.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.116.0" newVersion="1.0.116.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.122.21.1" newVersion="4.122.21.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

@ -25,6 +25,10 @@
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.122.21.1" newVersion="4.122.21.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

@ -1,6 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.1.0.0" newVersion="8.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.116.0" newVersion="1.0.116.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.122.21.1" newVersion="4.122.21.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

@ -28,20 +28,152 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.SetPort = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.Port212Text = new System.Windows.Forms.TextBox();
this.dataGridView2 = new System.Windows.Forms.DataGridView();
this.MonitorOnOff = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.MonitorState = new System.Windows.Forms.Label();
this.TableTimer = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(12, 129);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersWidth = 51;
this.dataGridView1.RowTemplate.Height = 27;
this.dataGridView1.Size = new System.Drawing.Size(458, 923);
this.dataGridView1.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.SetPort);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.Port212Text);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(260, 111);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "端口设置";
//
// SetPort
//
this.SetPort.Location = new System.Drawing.Point(63, 55);
this.SetPort.Name = "SetPort";
this.SetPort.Size = new System.Drawing.Size(130, 50);
this.SetPort.TabIndex = 6;
this.SetPort.Text = "确认端口号";
this.SetPort.UseVisualStyleBackColor = true;
this.SetPort.Click += new System.EventHandler(this.SetPort_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(28, 29);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(52, 15);
this.label1.TabIndex = 1;
this.label1.Text = "端口号";
//
// Port212Text
//
this.Port212Text.Location = new System.Drawing.Point(86, 24);
this.Port212Text.MaxLength = 6;
this.Port212Text.Name = "Port212Text";
this.Port212Text.Size = new System.Drawing.Size(144, 25);
this.Port212Text.TabIndex = 0;
this.Port212Text.Text = "1234";
//
// dataGridView2
//
this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView2.Location = new System.Drawing.Point(476, 12);
this.dataGridView2.Name = "dataGridView2";
this.dataGridView2.RowHeadersWidth = 51;
this.dataGridView2.RowTemplate.Height = 27;
this.dataGridView2.Size = new System.Drawing.Size(458, 1040);
this.dataGridView2.TabIndex = 2;
//
// MonitorOnOff
//
this.MonitorOnOff.Location = new System.Drawing.Point(278, 12);
this.MonitorOnOff.Name = "MonitorOnOff";
this.MonitorOnOff.Size = new System.Drawing.Size(192, 57);
this.MonitorOnOff.TabIndex = 7;
this.MonitorOnOff.Text = "启动监听";
this.MonitorOnOff.UseVisualStyleBackColor = true;
this.MonitorOnOff.Click += new System.EventHandler(this.MonitorOnOff_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(321, 92);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(82, 15);
this.label4.TabIndex = 8;
this.label4.Text = "监听状态:";
//
// MonitorState
//
this.MonitorState.AutoSize = true;
this.MonitorState.BackColor = System.Drawing.Color.Transparent;
this.MonitorState.Location = new System.Drawing.Point(400, 92);
this.MonitorState.Name = "MonitorState";
this.MonitorState.Size = new System.Drawing.Size(22, 15);
this.MonitorState.TabIndex = 9;
this.MonitorState.Text = "关";
//
// TableTimer
//
this.TableTimer.Enabled = true;
this.TableTimer.Interval = 1000;
this.TableTimer.Tick += new System.EventHandler(this.TableTimer_Tick);
//
// RFIDSocket
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1643, 1064);
this.ClientSize = new System.Drawing.Size(949, 1064);
this.Controls.Add(this.MonitorState);
this.Controls.Add(this.label4);
this.Controls.Add(this.MonitorOnOff);
this.Controls.Add(this.dataGridView2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.dataGridView1);
this.Name = "RFIDSocket";
this.Text = "小件日志";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.RFIDSocket_FormClosing);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button SetPort;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox Port212Text;
private System.Windows.Forms.DataGridView dataGridView2;
private System.Windows.Forms.Button MonitorOnOff;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label MonitorState;
private System.Windows.Forms.Timer TableTimer;
}
}

@ -1,20 +1,108 @@
using System;
using HighWayIot.TouchSocket;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TouchSocket.Sockets;
namespace RFIDSocket
{
public partial class RFIDSocket : Form
{
private static TcpServer Server = TcpServer.Instance;
int Port;
public RFIDSocket()
{
InitializeComponent();
InitAction();
}
private void InitAction()
{
if (Server.State != ServerState.Running)
{
MonitorState.Text = "关";
MonitorState.BackColor = Color.Yellow;
}
else if (Server.State == ServerState.Running)
{
MonitorState.Text = "开";
MonitorState.BackColor = Color.LightGreen;
}
Port = Convert.ToInt32(Port212Text.Text);
}
private void MonitorOnOff_Click(object sender, EventArgs e)
{
if (Server.State != ServerState.Running)
{
if (Server.ServerStart(Port))
{
MessageBox.Show("监听服务启动成功!");
}
else
{
MessageBox.Show("监听服务启动失败!");
}
}
else if (Server.State == ServerState.Running)
{
if (Server.ServerStop())
{
MessageBox.Show("监听服务关闭成功!");
}
else
{
MessageBox.Show("监听服务关闭失败!");
}
}
}
private void SetPort_Click(object sender, EventArgs e)
{
Port = Convert.ToInt32(Port212Text.Text);
}
private void TableTimer_Tick(object sender, EventArgs e)
{
if (Server.State != ServerState.Running)
{
MonitorOnOff.Text = "启动监听";
MonitorState.Text = "关";
MonitorState.BackColor = Color.Yellow;
}
else if (Server.State == ServerState.Running)
{
MonitorOnOff.Text = "关闭监听";
MonitorState.Text = "开";
MonitorState.BackColor = Color.LightGreen;
}
}
private void RFIDSocket_FormClosing(object sender, FormClosingEventArgs e)
{
if (Server.State == ServerState.Running)
{
if (!Server.ServerStop())
{
MessageBox.Show("监听服务关闭失败! 请成功关闭后再退出");
e.Cancel = true;
}
if (!Server.ServerDispose())
{
MessageBox.Show("监听服务释放失败! 请再次尝试退出");
e.Cancel = true;
}
}
}
}
}

@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -44,6 +47,12 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="TouchSocket, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5f39d7da98dac6a9, processorArchitecture=MSIL">
<HintPath>..\packages\TouchSocket.2.0.0-beta.253\lib\net45\TouchSocket.dll</HintPath>
</Reference>
<Reference Include="TouchSocket.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d6c415a2f58eda72, processorArchitecture=MSIL">
<HintPath>..\packages\TouchSocket.Core.2.0.0-beta.253\lib\net45\TouchSocket.Core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="RFIDSocket.cs">
@ -66,6 +75,7 @@
<EmbeddedResource Include="RFIDSocket.resx">
<DependentUpon>RFIDSocket.cs</DependentUpon>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -79,5 +89,14 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HighWayIot.TouchSocket\HighWayIot.TouchSocket.csproj">
<Project>{DD18A634-1F9C-409A-8C32-C3C81B1B55B5}</Project>
<Name>HighWayIot.TouchSocket</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\TouchSocket.Core.2.0.0-beta.253\analyzers\dotnet\cs\TouchSocket.Core.SourceGenerator.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="TableTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net48" />
<package id="TouchSocket" version="2.0.0-beta.253" targetFramework="net48" />
<package id="TouchSocket.Core" version="2.0.0-beta.253" targetFramework="net48" />
</packages>
Loading…
Cancel
Save