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

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

@ -1,6 +1,6 @@
namespace RfidWeb
{
partial class Form1
partial class FrmMain
{
/// <summary>
/// 必需的设计器变量。
@ -28,31 +28,19 @@
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
// FrmMain
//
this.button1.Location = new System.Drawing.Point(662, 241);
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.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1770, 830);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ClientSize = new System.Drawing.Size(1180, 553);
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "FrmMain";
this.Text = "主程序";
this.ResumeLayout(false);
}
private System.Windows.Forms.Button button1;
}
#endregion
}

@ -16,21 +16,22 @@ using DB.Entity;
using NewLife.Data;
using NewLife.Log;
using Tool;
using HslCommunication;
namespace RfidWeb
{
public partial class Form1 : Form
public partial class FrmMain : Form
{
private ILogNet logNet = ILogNetFactory.GetLogNet;
public Form1()
public FrmMain()
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
InitializeComponent();
// 如果所有的日志在记录之前需要在控制台显示出来
logNet.BeforeSaveToFile += (object sender, HslEventArgs e) =>
{
@ -38,6 +39,37 @@ namespace RfidWeb
};
logNet.ConsoleOutput = true;
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]
static void Main()
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new FrmMain());
}
}
}

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

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

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

Loading…
Cancel
Save