nodyang@aliyun.com 1 month ago
parent 1077c0cf75
commit 17cfa5bcca

@ -47,13 +47,13 @@
<Version>1.1.1</Version> <Version>1.1.1</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions"> <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
<Version>8.0.1</Version> <Version>8.0.2</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions"> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions">
<Version>8.0.1</Version> <Version>8.0.2</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Npgsql"> <PackageReference Include="Npgsql">
<Version>8.0.4</Version> <Version>8.0.5</Version>
</PackageReference> </PackageReference>
<Reference Include="System" /> <Reference Include="System" />
<PackageReference Include="System.Buffers"> <PackageReference Include="System.Buffers">
@ -80,7 +80,7 @@
<Version>8.0.0</Version> <Version>8.0.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="System.Text.Json"> <PackageReference Include="System.Text.Json">
<Version>8.0.4</Version> <Version>8.0.5</Version>
</PackageReference> </PackageReference>
<PackageReference Include="System.Threading.Channels"> <PackageReference Include="System.Threading.Channels">
<Version>8.0.0</Version> <Version>8.0.0</Version>

@ -1,6 +1,6 @@
namespace RfidWeb namespace RfidWeb
{ {
partial class Form1 partial class FrmMain
{ {
/// <summary> /// <summary>
/// 必需的设计器变量。 /// 必需的设计器变量。
@ -28,31 +28,19 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// button1 // FrmMain
// //
this.button1.Location = new System.Drawing.Point(662, 241); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(137, 97);
this.button1.TabIndex = 0;
this.button1.Text = "初始化数据库";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1770, 830); this.ClientSize = new System.Drawing.Size(1180, 553);
this.Controls.Add(this.button1); this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "Form1"; this.Name = "FrmMain";
this.Text = "Form1"; this.Text = "主程序";
this.ResumeLayout(false); this.ResumeLayout(false);
}
private System.Windows.Forms.Button button1; }
#endregion #endregion
} }

@ -16,21 +16,22 @@ using DB.Entity;
using NewLife.Data; using NewLife.Data;
using NewLife.Log; using NewLife.Log;
using Tool; using Tool;
using HslCommunication;
namespace RfidWeb namespace RfidWeb
{ {
public partial class Form1 : Form public partial class FrmMain : Form
{ {
private ILogNet logNet = ILogNetFactory.GetLogNet; private ILogNet logNet = ILogNetFactory.GetLogNet;
public Form1() public FrmMain()
{ {
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
InitializeComponent(); InitializeComponent();
// 如果所有的日志在记录之前需要在控制台显示出来 // 如果所有的日志在记录之前需要在控制台显示出来
logNet.BeforeSaveToFile += (object sender, HslEventArgs e) => logNet.BeforeSaveToFile += (object sender, HslEventArgs e) =>
{ {
@ -38,6 +39,37 @@ namespace RfidWeb
}; };
logNet.ConsoleOutput = true; logNet.ConsoleOutput = true;
logNet.WriteInfo("nihao"); logNet.WriteInfo("nihao");
Init();
}
private void Init()
{
//if (this.FormBorderStyle == FormBorderStyle.None)
//{
// this.FormBorderStyle = FormBorderStyle.FixedSingle;
// this.WindowState = FormWindowState.Normal;
//}
//else
//{
// this.FormBorderStyle = FormBorderStyle.None;
// this.WindowState = FormWindowState.Maximized;
//}
// 当前写入操作的代码 The code for the current write operation
OperateResult write = PlcConnect.Instance.Write("A1", short.Parse("4"));
if (write.IsSuccess)
{
Console.WriteLine("Write [A1] success");
}
else
{
Console.WriteLine("Write [A1] failed: " + write.Message);
}
} }

@ -14,9 +14,11 @@ namespace RfidWeb
[STAThread] [STAThread]
static void Main() static void Main()
{ {
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); Application.Run(new FrmMain());
} }
} }
} }

@ -56,17 +56,17 @@
<Version>1.1.1</Version> <Version>1.1.1</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions"> <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
<Version>8.0.1</Version> <Version>8.0.2</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions"> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions">
<Version>8.0.1</Version> <Version>8.0.2</Version>
</PackageReference> </PackageReference>
<Reference Include="Microsoft.VisualBasic" /> <Reference Include="Microsoft.VisualBasic" />
<PackageReference Include="Newtonsoft.Json"> <PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version> <Version>13.0.3</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Npgsql"> <PackageReference Include="Npgsql">
<Version>8.0.4</Version> <Version>8.0.5</Version>
</PackageReference> </PackageReference>
<Reference Include="System" /> <Reference Include="System" />
<PackageReference Include="System.Buffers"> <PackageReference Include="System.Buffers">
@ -95,7 +95,7 @@
<Version>8.0.0</Version> <Version>8.0.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="System.Text.Json"> <PackageReference Include="System.Text.Json">
<Version>8.0.4</Version> <Version>8.0.5</Version>
</PackageReference> </PackageReference>
<PackageReference Include="System.Threading.Channels"> <PackageReference Include="System.Threading.Channels">
<Version>8.0.0</Version> <Version>8.0.0</Version>
@ -118,16 +118,16 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Form1.cs"> <Compile Include="FrmMain.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Form1.Designer.cs"> <Compile Include="FrmMain.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>FrmMain.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx"> <EmbeddedResource Include="FrmMain.resx">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>FrmMain.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>

@ -1,4 +1,6 @@
using System; using System;
using System.Net.Http;
using NewLife.Http;
using RestSharp; using RestSharp;
namespace Tool namespace Tool
@ -13,7 +15,7 @@ namespace Tool
/// <param name="url"></param> /// <param name="url"></param>
/// <param name="obj"></param> /// <param name="obj"></param>
/// <returns></returns> /// <returns></returns>
public static string PostJson(string url, object obj) public static (bool b,string msg) PostJson(string url, object obj)
{ {
try try
{ {
@ -23,13 +25,15 @@ namespace Tool
request.Method = Method.Post; request.Method = Method.Post;
request.Timeout = TimeSpan.FromMinutes(2); request.Timeout = TimeSpan.FromMinutes(2);
request.AddBody(obj, ContentType.Json); request.AddBody(obj, ContentType.Json);
var response = client.Execute(request); var response = client.Execute(request);
return response.Content; return (response.IsSuccessful, response.IsSuccessful ? response.Content : response.ErrorMessage);
} }
catch (Exception e) catch (Exception e)
{ {
ILogNetFactory.GetLogNet.WriteError(e.Message); ILogNetFactory.GetLogNet.WriteError(e.Message);
return e.Message; return (false, e.Message);
} }
} }
} }

@ -21,15 +21,24 @@ namespace Tool
private AllenBradleyNet CreateAb() private AllenBradleyNet CreateAb()
{ {
var rfidSetting = RfidSetting.Current; var rfidSetting = RfidSetting.Current;
AllenBradleyNet ab = new AllenBradleyNet(); AllenBradleyNet plc = new AllenBradleyNet();
ab.IpAddress = rfidSetting.PlcIp; plc.Slot = 0;
ab.Port = rfidSetting.Port; plc.CommunicationPipe = new HslCommunication.Core.Pipe.PipeTcpNet(rfidSetting.PlcIp, 44818)
ab.ConnectServer(); {
return ab; ConnectTimeOut = 5000, // 连接超时时间,单位毫秒
ReceiveTimeOut = 10000, // 接收设备数据反馈的超时时间
SleepTime = 0,
SocketKeepAliveTime = -1,
IsPersistentConnection = true,
};
return plc;
} }
public OperateResult Write(string db, string value) public OperateResult Write(string db, string value)
{ {
return Instance.Write(db, value); return Instance.Write(db, value);

@ -16,7 +16,7 @@ namespace Tool
public string Db { get; set; } = "server=127.0.0.1;database=gaosu;uid=postgres;pwd=123456"; public string Db { get; set; } = "server=127.0.0.1;database=gaosu;uid=postgres;pwd=123456";
public string PlcIp { get; set; } = "127.0.0.1"; public string PlcIp { get; set; } = "192.168.1.100";
public int Port { get; set; }=44818; public int Port { get; set; }=44818;

Loading…
Cancel
Save