Pārlūkot izejas kodu

设备修改

Lishi
pry pirms 2 gadiem
vecāks
revīzija
e3a1fcc38c
9 mainītis faili ar 131 papildinājumiem un 37 dzēšanām
  1. +10
    -9
      HKCardOUT/App.xaml
  2. +1
    -2
      HKCardOUT/Properties/DesignTimeResources.xaml
  3. +1
    -0
      HKCardOUT/Views/RootView.xaml.cs
  4. +24
    -9
      HKControl/Main.cs
  5. +18
    -3
      HKControl/Siemens.cs
  6. +13
    -4
      UHFHelper/UHF_RS485_Helper.cs
  7. +41
    -4
      test/Form1.Designer.cs
  8. +22
    -6
      test/Form1.cs
  9. +1
    -0
      test/test.csproj

+ 10
- 9
HKCardOUT/App.xaml Parādīt failu

@@ -1,18 +1,19 @@
<Application x:Class="HKCardOUT.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:HKCardOUT">
<Application
x:Class="HKCardOUT.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:HKCardOUT"
xmlns:s="https://github.com/canton7/Stylet">
<Application.Resources>
<s:ApplicationLoader>
<s:ApplicationLoader.Bootstrapper>
<local:Bootstrapper/>
<local:Bootstrapper />
</s:ApplicationLoader.Bootstrapper>

<s:ApplicationLoader.MergedDictionaries>
<hc:ThemeResources/>
<hc:Theme/>
<hc:ThemeResources />
<hc:Theme />
</s:ApplicationLoader.MergedDictionaries>
</s:ApplicationLoader>
</Application.Resources>


+ 1
- 2
HKCardOUT/Properties/DesignTimeResources.xaml Parādīt failu

@@ -1,5 +1,4 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:hc="https://handyorg.github.io/handycontrol">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:hc="https://handyorg.github.io/handycontrol">
<ResourceDictionary.MergedDictionaries>
<hc:IntellisenseResources Source="/HandyControl;Component/DesignTime/DesignTimeResources.xaml" />
</ResourceDictionary.MergedDictionaries>


+ 1
- 0
HKCardOUT/Views/RootView.xaml.cs Parādīt failu

@@ -18,6 +18,7 @@ namespace HKCardOUT.Views
private void RootView_Loaded(object sender, RoutedEventArgs e)
{
(this.DataContext as RootViewModel).Main = this;
HKControl.Main.GetInstance.Init();
}
}
}

+ 24
- 9
HKControl/Main.cs Parādīt failu

@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using HKHelper;
using S7.Net;

@@ -63,9 +64,9 @@ namespace HKControl
if (!SiemensDicitonary.ContainsKey(item.DeviceNum)) { SiemensDicitonary.TryAdd(item.DeviceNum, new Siemens()); }
ThreadManage.GetInstance().Start(new Action(() =>
{
SiemensDicitonary[item.DeviceNum].Connect(CpuType.S7200Smart, item.IpAddress);
SiemensDicitonary[item.DeviceNum].ConnectOk = new Action(() =>
{
Debug.WriteLine($"{item.DeviceNum}:连接成功");
ThreadManage.GetInstance().StartLong(new Action(() =>
{
var res = SiemensDicitonary[item.DeviceNum].Read<byte>("MB7");
@@ -86,6 +87,7 @@ namespace HKControl
Thread.Sleep(100);
}), $"{item.DeviceNum} 号设备监听");
});
SiemensDicitonary[item.DeviceNum].Connect(CpuType.S7200Smart, item.IpAddress);
}), $"{item.DeviceNum} 号设备连接初始化");

});
@@ -103,22 +105,28 @@ namespace HKControl
switch (carNum)
{
case 1:
SiemensDicitonary[1].Write("M6.0", true);
//SiemensDicitonary[1].Write("M6.0", true);
Control(1, "M6.0");
break;
case 2:
SiemensDicitonary[1].Write("M6.1", true);
//SiemensDicitonary[1].Write("M6.1", true);
Control(1, "M6.1");
break;
case 3:
SiemensDicitonary[2].Write("M6.0", true);
//SiemensDicitonary[2].Write("M6.0", true);
Control(2, "M6.0");
break;
case 4:
SiemensDicitonary[2].Write("M6.1", true);
//SiemensDicitonary[2].Write("M6.1", true);
Control(2, "M6.1");
break;
case 5:
SiemensDicitonary[3].Write("M6.0", true);
//SiemensDicitonary[3].Write("M6.0", true);
Control(3, "M6.0");
break;
case 6:
SiemensDicitonary[3].Write("M6.1", true);
//SiemensDicitonary[3].Write("M6.1", true);
Control(3, "M6.1");
break;

default:
@@ -130,6 +138,13 @@ namespace HKControl
}), "开始运行设备");
}

private void Control(int num, string add)
{
SiemensDicitonary[num].Write(add, true);
Thread.Sleep(1000);
SiemensDicitonary[num].Write(add, false);
}

private void DataInit()
{
Json<CommunicationPar>.Read();
@@ -140,7 +155,7 @@ namespace HKControl
Json<CommunicationPar>.Data.CommunicationModels.Add(new CommunicationModel()
{
IpAddress = "192.168.0.1",
DeviceNum = 1
DeviceNum = 3
});

Json<CommunicationPar>.Data.CommunicationModels.Add(new CommunicationModel()
@@ -152,7 +167,7 @@ namespace HKControl
Json<CommunicationPar>.Data.CommunicationModels.Add(new CommunicationModel()
{
IpAddress = "192.168.0.3",
DeviceNum = 3
DeviceNum = 1
});

Json<CommunicationPar>.Save();


+ 18
- 3
HKControl/Siemens.cs Parādīt failu

@@ -1,6 +1,7 @@
using S7.Net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -20,10 +21,24 @@ namespace HKControl
/// <param name="port">plc 端口号</param>
/// <param name="rack">PLC 机架号</param>
/// <param name="solt"> PLC 插槽号</param>
public void Connect(CpuType cpuType, string ip, int port = 102, short rack = 0, short solt = 2)
public void Connect(CpuType cpuType, string ip, int port = 102, short rack = 0, short solt = 0)
{
myPlc = new Plc(cpuType, ip, port, rack, solt);
myPlc.Open();
try
{
myPlc = new Plc(cpuType, ip, port, rack, solt);
myPlc.Open();
if (myPlc.IsConnected)
{
ConnectOk?.Invoke();
Debug.WriteLine($"设备{ip}连接成功");
}
}
catch (Exception ex)
{
Debug.WriteLine($"设备连接出错:{ip}");
//Debug.WriteLine(ex.ToString());
}

}

/// <summary>


+ 13
- 4
UHFHelper/UHF_RS485_Helper.cs Parādīt failu

@@ -26,10 +26,19 @@ namespace UHFHelper
/// <param name="param"></param>
public void Open(SerialParam param)
{
_serialParam = param;
_serialPort = new SerialPort(_serialParam.PortName, _serialParam.BaudRate, _serialParam.PortParity, _serialParam.DataBits);
_serialPort.Open();
if (SerialPort.GetPortNames().Contains(param.PortName))
{
_serialParam = param;
_serialPort = new SerialPort(_serialParam.PortName, _serialParam.BaudRate, _serialParam.PortParity, _serialParam.DataBits);
try
{
_serialPort.Open();
}
catch (Exception)
{
}
}
}
/// <summary>
/// 获取串口状态


+ 41
- 4
test/Form1.Designer.cs Parādīt failu

@@ -44,8 +44,11 @@
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.button9 = new System.Windows.Forms.Button();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.button9 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button11 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
@@ -191,6 +194,10 @@
//
this.columnHeader2.Text = "号码";
//
// columnHeader3
//
this.columnHeader3.Text = "次数";
//
// button9
//
this.button9.Location = new System.Drawing.Point(88, 387);
@@ -201,15 +208,42 @@
this.button9.UseVisualStyleBackColor = true;
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// columnHeader3
// button10
//
this.columnHeader3.Text = "次数";
this.button10.Location = new System.Drawing.Point(126, 517);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(127, 37);
this.button10.TabIndex = 14;
this.button10.Text = "PLC 初始化";
this.button10.UseVisualStyleBackColor = true;
this.button10.Click += new System.EventHandler(this.button10_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(270, 472);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(127, 23);
this.textBox2.TabIndex = 15;
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
//
// button11
//
this.button11.Location = new System.Drawing.Point(270, 517);
this.button11.Name = "button11";
this.button11.Size = new System.Drawing.Size(127, 37);
this.button11.TabIndex = 16;
this.button11.Text = "开始出餐";
this.button11.UseVisualStyleBackColor = true;
this.button11.Click += new System.EventHandler(this.button11_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.ClientSize = new System.Drawing.Size(1075, 589);
this.Controls.Add(this.button11);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
this.Controls.Add(this.listView1);
this.Controls.Add(this.button8);
@@ -253,5 +287,8 @@
private ColumnHeader columnHeader2;
private Button button9;
private ColumnHeader columnHeader3;
private Button button10;
private TextBox textBox2;
private Button button11;
}
}

+ 22
- 6
test/Form1.cs Parādīt failu

@@ -61,7 +61,7 @@ namespace test
add.Add(02);
}
UHF_RS485_Helper uHF_RS485_Helper;
private void button5_Click(object sender, EventArgs e)
private void button5_Click(object sender, EventArgs e)
{
// 初始化
UHF_RS485_Helper.GetInstance().Open(new SerialParam
@@ -76,11 +76,11 @@ namespace test
}
}

private void button6_Click(object sender, EventArgs e)
private void button6_Click(object sender, EventArgs e)
{
if (UHF_RS485_Helper.GetInstance().GetSerialPortState())
{
var oldss = UHF_RS485_Helper.GetInstance().ReadCard(01);
var oldss = UHF_RS485_Helper.GetInstance().ReadCard(01);
var sss = oldss?.ResData;
textBox4.Text = sss;
label2.Text = sss;
@@ -99,7 +99,7 @@ namespace test
ti.Elapsed += Ti_Elapsed;
ti.Start();
}
private void Ti_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
foreach (var item in add)
@@ -111,7 +111,7 @@ namespace test
//this.listView1.Items.Add(lvi);
this.Invoke(() =>
{
if (listView1.Items.Count==0)
if (listView1.Items.Count == 0)
{
ListViewItem lvi = new ListViewItem();
lvi.SubItems.Add(oldss.ResData ?? "无");
@@ -146,7 +146,23 @@ namespace test
ListViewItem lvi = new ListViewItem("1");
lvi.SubItems.Add("第1列,第1行");
lvi.SubItems.Add("第2列,第2行");

}

private void button10_Click(object sender, EventArgs e)
{
HKControl.Main.GetInstance.Init();
}

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void button11_Click(object sender, EventArgs e)
{
int num = Convert.ToInt32(textBox2.Text.Trim());
HKControl.Main.GetInstance.Start(num);
}
}
}

+ 1
- 0
test/test.csproj Parādīt failu

@@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HKControl\HKControl.csproj" />
<ProjectReference Include="..\UHFHelper\UHFHelper.csproj" />
</ItemGroup>



Notiek ielāde…
Atcelt
Saglabāt