change - 配方参数设置修改完成,上下传PLC完成

master
SoulStar 4 months ago
parent 22bf65a0f6
commit 8a099ac9b5

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Plc
{
/// <summary>
/// byte和ushort转换
/// </summary>
public static class EndianConvert
{
/// <summary>
/// 将 ushort 转换为 byte[](默认小端序)
/// </summary>
/// <param name="value">要转换的 ushort 值</param>
/// <param name="isBigEndian">是否使用大端序默认false</param>
public static byte[] ToBytes(this ushort value, bool isBigEndian = false)
{
byte[] bytes = BitConverter.GetBytes(value);
// 系统是小端序且需要大端序时,反转字节数组
if (BitConverter.IsLittleEndian && isBigEndian)
{
Array.Reverse(bytes);
}
// 系统是大端序且需要小端序时,反转字节数组
else if (!BitConverter.IsLittleEndian && !isBigEndian)
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 将 byte[] 转换为 ushort默认小端序
/// </summary>
/// <param name="bytes">要转换的字节数组(长度必须 >= 2</param>
/// <param name="isBigEndian">是否使用大端序默认false</param>
/// <exception cref="ArgumentException">输入数组长度不足</exception>
public static ushort FromBytes(this byte[] bytes, bool isBigEndian = false)
{
if (bytes.Length < 2)
{
throw new ArgumentException("字节数组长度必须至少为2", nameof(bytes));
}
// 复制前两个字节以避免修改原始数组
byte[] tempBytes = new byte[2];
Array.Copy(bytes, tempBytes, 2);
// 根据系统字节序和目标字节序决定是否反转
bool systemIsBigEndian = !BitConverter.IsLittleEndian;
if (isBigEndian != systemIsBigEndian)
{
Array.Reverse(tempBytes);
}
return BitConverter.ToUInt16(tempBytes, 0);
}
/// <summary>
/// 安全版本:从指定偏移量开始转换(不抛异常)
/// </summary>
public static bool TryFromBytes(this byte[] bytes, out ushort result, int startIndex = 0, bool isBigEndian = false)
{
result = 0;
if (bytes == null || bytes.Length < startIndex + 2)
{
return false;
}
byte[] tempBytes = new byte[2];
Array.Copy(bytes, startIndex, tempBytes, 0, 2);
bool systemIsBigEndian = !BitConverter.IsLittleEndian;
if (isBigEndian != systemIsBigEndian)
{
Array.Reverse(tempBytes);
}
result = BitConverter.ToUInt16(tempBytes, 0);
return true;
}
}
}

@ -47,9 +47,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DataTypeEnum.cs" />
<Compile Include="EndianConvert.cs" />
<Compile Include="PlcConnect.cs" />
<Compile Include="PlcEntity\RgvStationEnum.cs" />
<Compile Include="PlcHelper\BasePlcHelper.cs" />
<Compile Include="PlcHelper\RecipeParaHelper.cs" />
<Compile Include="PlcHelper\RfidResult.cs" />
<Compile Include="PlcHelper\WorkStationHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@ -63,6 +65,10 @@
<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>
<ItemGroup>
<Folder Include="Impl\" />

@ -52,7 +52,7 @@ namespace HighWayIot.Plc
IsPersistentConnection = true,
};
var reslt = plc.ConnectServer();
logHelper.Info($"Plc连接 信息:[{reslt.Message}] 是否成功:[{reslt.IsSuccess.ToString()}] 错误代码:[{reslt.ErrorCode}]");
logHelper.Info($"Plc连接 信息:[{reslt.Message}] 是否成功:[{(reslt.IsSuccess ? "" : "")}] 错误代码:[{reslt.ErrorCode}]");
if (!reslt.IsSuccess)
{
logHelper.Info("链接失败:"+reslt.Message);
@ -74,9 +74,9 @@ namespace HighWayIot.Plc
get
{
if (MelsecInstance1 == null) return false;
var result = MelsecInstance1.IpAddress;
logHelper.Info($"PLCIP[{result}]");
return !string.IsNullOrEmpty(result);
var result = MelsecInstance1.IpAddressPing();
logHelper.Info($"PLC[{MelsecInstance1.IpAddress}]连接:[{(result == System.Net.NetworkInformation.IPStatus.Success ? "" : "")}]");
return result == System.Net.NetworkInformation.IPStatus.Success;
}
}
@ -88,9 +88,9 @@ namespace HighWayIot.Plc
get
{
if (MelsecInstance2 == null) return false;
var result = MelsecInstance2.IpAddress;
logHelper.Info($"PLCIP[{result}]");
return !string.IsNullOrEmpty(result);
var result = MelsecInstance2.IpAddressPing();
logHelper.Info($"PLC[{MelsecInstance2.IpAddress}]连接:[{(result == System.Net.NetworkInformation.IPStatus.Success ? "" : "")}]");
return result == System.Net.NetworkInformation.IPStatus.Success;
}
}
@ -104,6 +104,10 @@ namespace HighWayIot.Plc
public static OperateResult PlcWrite1(string address, object value, DataTypeEnum type)
{
var result = new OperateResult() { IsSuccess = false };
if(value == null)
{
return result;
}
try
{
switch (type)
@ -138,6 +142,9 @@ namespace HighWayIot.Plc
case DataTypeEnum.Double:
result = MelsecInstance1.Write(address, Convert.ToDouble(value));
break;
case DataTypeEnum.String:
result = MelsecInstance1.Write(address, Convert.ToString(value));
break;
default:
throw new ArgumentException($"Unsupported data type: {type}");
}
@ -165,9 +172,9 @@ namespace HighWayIot.Plc
{
switch (type)
{
case DataTypeEnum.Bool:
result = MelsecInstance2.Write(address, Convert.ToBoolean(value));
break;
//case DataTypeEnum.Bool:
// result = MelsecInstance2.Write(address, Convert.ToBoolean(value));
// break;
//case DataTypeEnum.Byte:
// result = Instance.Write(address, Convert.ToByte(value));
// break;
@ -195,6 +202,9 @@ namespace HighWayIot.Plc
case DataTypeEnum.Double:
result = MelsecInstance2.Write(address, Convert.ToDouble(value));
break;
case DataTypeEnum.String:
result = MelsecInstance2.Write(address, Convert.ToString(value));
break;
default:
throw new ArgumentException($"Unsupported data type: {type}");
}
@ -207,6 +217,56 @@ namespace HighWayIot.Plc
return result;
}
/// <summary>
/// 字符串读取1
/// </summary>
/// <param name="address"></param>
/// <param name="length"></param>
/// <returns></returns>
public static string ReadString1(string address, ushort length)
{
OperateResult<string> result = new OperateResult<string>();
try
{
result = MelsecInstance1.ReadString(address, length);
}
catch (Exception ex)
{
logHelper.Error($"PLC1读取String发生错误address:[{address}]", ex);
return default;
}
if (!result.IsSuccess)
{
return default;
}
return result.Content;
}
/// <summary>
/// 字符串读取2
/// </summary>
/// <param name="address"></param>
/// <param name="length"></param>
/// <returns></returns>
public static string ReadString2(string address, ushort length)
{
OperateResult<string> result = new OperateResult<string>();
try
{
result = MelsecInstance2.ReadString(address, length);
}
catch (Exception ex)
{
logHelper.Error($"PLC2读取String发生错误address:[{address}]", ex);
return default;
}
if (!result.IsSuccess)
{
return default;
}
return result.Content;
}
/// <summary>
/// 读取bool
/// </summary>
@ -623,6 +683,7 @@ namespace HighWayIot.Plc
public static double ReadDouble2(string address)
{
OperateResult<double> result = new OperateResult<double>();
try
{
result = MelsecInstance2.ReadDouble(address);

@ -0,0 +1,268 @@
using HighWayIot.Repository.domain;
using HslCommunication;
using HslCommunication.Profinet.Panasonic.Helper;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Plc.PlcHelper
{
public class RecipeParaHelper
{
/// <summary>
/// 数据下传到PLC
/// </summary>
/// <param name="paraEntity"></param>
/// <param name="positionParaEntity"></param>
/// <returns></returns>
public bool UploadToPLC(ZxRecipeParaEntity paraEntity, List<ZxRecipePositionParaEntity> positionParaEntity)
{
//SPEC编号写入
try
{
if (!PlcConnect.PlcWrite1("D206", uint.Parse(paraEntity.SpecCode), DataTypeEnum.UInt32).IsSuccess)
return false;
}
catch
{
return false;
}
//SPEC名称写入
if (!PlcConnect.PlcWrite1("D290", paraEntity.SpecName, DataTypeEnum.String).IsSuccess)
return false;
//工位参数写入
foreach (ZxRecipePositionParaEntity e in positionParaEntity)
{
if (!SelectSetPositionPara(e))
return false;
}
//公共参数写入
byte[] bitDatas = new byte[2];
bitDatas[0] = bitDatas[0].SetBoolByIndex(0, paraEntity.S0 ?? false);
bitDatas[0] = bitDatas[0].SetBoolByIndex(1, paraEntity.S1 ?? false);
bitDatas[0] = bitDatas[0].SetBoolByIndex(2, paraEntity.S2 ?? false);
bitDatas[0] = bitDatas[0].SetBoolByIndex(3, paraEntity.S3 ?? false);
bitDatas[0] = bitDatas[0].SetBoolByIndex(4, paraEntity.S4 ?? false);
bitDatas[0] = bitDatas[0].SetBoolByIndex(5, paraEntity.S5 ?? false);
bitDatas[0] = bitDatas[0].SetBoolByIndex(6, paraEntity.S6 ?? false);
bitDatas[0] = bitDatas[0].SetBoolByIndex(7, paraEntity.S7 ?? false);
bitDatas[1] = bitDatas[1].SetBoolByIndex(0, paraEntity.S8 ?? false);
bitDatas[1] = bitDatas[1].SetBoolByIndex(1, paraEntity.S9 ?? false);
ushort bitData = bitDatas.FromBytes();
if(!PlcConnect.PlcWrite1("D390", bitData, DataTypeEnum.UInt16).IsSuccess) return false;
if (!PlcConnect.PlcWrite1("D391", paraEntity.RimInch ?? 0, DataTypeEnum.UInt16).IsSuccess)
return false;
if (!PlcConnect.PlcWrite1("D392", paraEntity.LightWidth ?? 0, DataTypeEnum.UInt16).IsSuccess)
return false;
if (!PlcConnect.PlcWrite1("D393", paraEntity.SlowDistance ?? 0, DataTypeEnum.UInt16).IsSuccess)
return false;
if (!PlcConnect.PlcWrite1("D394", paraEntity.StopDistance ?? 0, DataTypeEnum.UInt16).IsSuccess)
return false;
if (!PlcConnect.PlcWrite1("D398", paraEntity.TireWeight ?? 0, DataTypeEnum.Float).IsSuccess)
return false;
return true;
}
/// <summary>
/// 分类工位确定点位写入
/// </summary>
/// <param name=""></param>
/// <returns></returns>
private bool SelectSetPositionPara(ZxRecipePositionParaEntity entity)
{
if (entity.Position == 1)
{
if (!SetPositionPara(entity, 310))
return false;
}
else if (entity.Position == 2)
{
if (!SetPositionPara(entity, 320))
return false;
}
else if (entity.Position == 31)
{
if (!SetPositionPara(entity, 330))
return false;
}
else if (entity.Position == 32)
{
if (!SetPositionPara(entity, 340))
return false;
}
else if (entity.Position == 41)
{
if (!SetPositionPara(entity, 350))
return false;
}
else if (entity.Position == 42)
{
if (!SetPositionPara(entity, 360))
return false;
}
else if (entity.Position == 51)
{
if (!SetPositionPara(entity, 370))
return false;
}
else if (entity.Position == 52)
{
if (!SetPositionPara(entity, 380))
return false;
}
else
{
return false;
}
return true;
}
/// <summary>
/// 工位参数写入PLC
/// </summary>
/// <param name="entity"></param>
/// <param name="add"></param>
/// <returns></returns>
private bool SetPositionPara(ZxRecipePositionParaEntity entity, int add)
{
for (int i = 1; i <= 10; i++)
{
var prop = entity.GetType().GetProperty($"E{i}");
// 检查属性是否存在
if (prop == null)
return false;
// 获取属性值
object value = prop.GetValue(entity);
// 处理可空类型的null值情况
if (value == null)
{
// 根据业务需求选择返回false或使用默认值例如0
if (!PlcConnect.PlcWrite1($"D{add}", 0, DataTypeEnum.UInt16).IsSuccess)
return false;
}
// 尝试转换值
ushort valueToWrite;
try
{
valueToWrite = Convert.ToUInt16(value);
}
catch
{
// 转换失败(如类型不匹配)
return false;
}
// 写入PLC并检查结果
if (!PlcConnect.PlcWrite1($"D{add}", valueToWrite, DataTypeEnum.UInt16).IsSuccess)
return false;
add++;
}
return true;
}
/// <summary>
/// 从PLC中读取数据
/// </summary>
public List<ZxRecipePositionParaEntity> DownLoadFormPlc(ref ZxRecipeParaEntity paraEntity)
{
//读取SPEC编号
paraEntity.SpecCode = PlcConnect.ReadUInt321("D206").ToString();
//读取SPEC名称
paraEntity.SpecName = PlcConnect.ReadString1("D290", 10).Trim();
//读取工位参数
List<ZxRecipePositionParaEntity> positionEntitys = SelectReadPositionPara();
//公共参数读取
ushort bitData = PlcConnect.ReadUInt161($"D390");
byte[] bitDatas = bitData.ToBytes();
paraEntity.S0 = bitDatas[0].GetBoolByIndex(0);
paraEntity.S1 = bitDatas[0].GetBoolByIndex(1);
paraEntity.S2 = bitDatas[0].GetBoolByIndex(2);
paraEntity.S3 = bitDatas[0].GetBoolByIndex(3);
paraEntity.S4 = bitDatas[0].GetBoolByIndex(4);
paraEntity.S5 = bitDatas[0].GetBoolByIndex(5);
paraEntity.S6 = bitDatas[0].GetBoolByIndex(6);
paraEntity.S7 = bitDatas[0].GetBoolByIndex(7);
paraEntity.S8 = bitDatas[1].GetBoolByIndex(0);
paraEntity.S9 = bitDatas[1].GetBoolByIndex(1);
paraEntity.RimInch = PlcConnect.ReadInt161("D391");
paraEntity.LightWidth = PlcConnect.ReadInt161("D392");
paraEntity.SlowDistance = PlcConnect.ReadInt161("D393");
paraEntity.StopDistance = PlcConnect.ReadInt161("D394");
paraEntity.TireWeight = PlcConnect.ReadFloat1("D398");
return positionEntitys;
}
/// <summary>
/// 分类工位循环写入
/// </summary>
/// <param name=""></param>
/// <returns></returns>
private List<ZxRecipePositionParaEntity> SelectReadPositionPara()
{
List<ZxRecipePositionParaEntity> e = new List<ZxRecipePositionParaEntity>
{
ReadPositionPara(310),
ReadPositionPara(320),
ReadPositionPara(330),
ReadPositionPara(340),
ReadPositionPara(350),
ReadPositionPara(360),
ReadPositionPara(370),
ReadPositionPara(380)
};
return e;
}
/// <summary>
/// 工位参数读取PLC
/// </summary>
/// <param name="entity"></param>
/// <param name="add"></param>
/// <returns></returns>
private ZxRecipePositionParaEntity ReadPositionPara(int add)
{
ZxRecipePositionParaEntity entity = new ZxRecipePositionParaEntity();
if (add == 310) entity.Position = 1;
if (add == 320) entity.Position = 2;
if (add == 330) entity.Position = 31;
if (add == 340) entity.Position = 32;
if (add == 350) entity.Position = 41;
if (add == 360) entity.Position = 42;
if (add == 370) entity.Position = 51;
if (add == 380) entity.Position = 52;
for (int i = 1; i <= 10; i++)
{
var prop = entity.GetType().GetProperty($"E{i}");
prop.SetValue(entity, (int)PlcConnect.ReadUInt161($"D{add}"));
add++;
}
return entity;
}
}
}

@ -58,7 +58,7 @@ namespace Models
/// 默认值:
///</summary>
[SugarColumn(ColumnName = "tire_weight")]
public int? TireWeight { get; set; }
public float? TireWeight { get; set; }
/// <summary>
/// 备 注:规格名
@ -72,7 +72,7 @@ namespace Models
/// 默认值:
///</summary>
[SugarColumn(ColumnName = "spec_code")]
public int? SpecCode { get; set; }
public string SpecCode { get; set; } = string.Empty;
/// <summary>
/// 备 注:

@ -43,24 +43,6 @@ namespace HighWayIot.Repository.service
}
}
/// <summary>
/// 查询配方字段信息
/// </summary>
/// <returns></returns>
public List<ZxRecipeParaEntity> GetRecipeParaInfoByRecipeCode()
{
try
{
List<ZxRecipeParaEntity> entity = _repository.GetList();
return entity;
}
catch (Exception ex)
{
log.Error("配方信息获取异常", ex);
return null;
}
}
/// <summary>
/// 根据配方号查询配方字段信息
/// </summary>
@ -91,7 +73,7 @@ namespace HighWayIot.Repository.service
{
return _repository.Update(entity);
}
catch(Exception ex)
catch (Exception ex)
{
log.Error("配方字段信息修改异常", ex);
return false;
@ -133,5 +115,53 @@ namespace HighWayIot.Repository.service
return false;
}
}
/// <summary>
/// 清除脏数据
/// </summary>
/// <returns></returns>
public bool DeleteDirtyData()
{
try
{
var entities = _repository.GetList();
entities = _repository.GetList().Where(x => x.RecipeCode == null || x.RecipeCode == string.Empty).ToList();
foreach (var entity in entities)
{
if (!DeleteRecipeParaInfoById(entity.Id))
{
return false;
}
}
entities = _repository.GetList();
foreach (var e in entities.GroupBy(x => x.RecipeCode).ToList())
{
var l = e.ToList();
if (l.Count > 1)
{
l.Remove(l.Where(x => x.Id == l.Min(y => y.Id)).FirstOrDefault());
foreach (var entity in l)
{
if (!DeleteRecipeParaInfoById(entity.Id))
{
return false;
}
}
}
}
return true;
}
catch (Exception ex)
{
log.Error("工位配方字段信息删除异常", ex);
return false;
}
}
}
}

@ -134,5 +134,57 @@ namespace HighWayIot.Repository.service
return false;
}
}
/// <summary>
/// 清除脏数据
/// </summary>
/// <returns></returns>
public bool DeleteDirtyData()
{
try
{
var entities = _repository.GetList();
entities = _repository.GetList().Where(x => x.Position == null || (x.RecipeCode == null || x.RecipeCode == string.Empty)).ToList();
foreach (var entity in entities)
{
if (!DeleteRecipePositionParaInfoById(entity.Id))
{
return false;
}
}
entities = _repository.GetList();
foreach(var e in entities.GroupBy(x => x.RecipeCode).ToList())
{
foreach(var en in e.GroupBy(x => x.Position).ToList())
{
var l = en.ToList();
if(l.Count > 1)
{
l.Remove(l.Where(x => x.Id == l.Min(y => y.Id)).FirstOrDefault());
foreach (var entity in l)
{
if (!DeleteRecipePositionParaInfoById(entity.Id))
{
return false;
}
}
}
}
}
return true;
}
catch (Exception ex)
{
log.Error("工位配方字段信息删除异常", ex);
return false;
}
}
}
}

@ -61,6 +61,10 @@
<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>

@ -34,7 +34,7 @@ namespace HighWayIot.TouchSocket
public async Task<bool> CreateTcpClient(string ip, string port)
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connecting = (client, e) =>
{
return EasyTask.CompletedTask;
@ -75,8 +75,12 @@ namespace HighWayIot.TouchSocket
Result result = Result.Default; //不断尝试重连
do
{
_logHelper.Info($"连接{ip}:{port}");
result = await tcpClient.TryConnectAsync();
await Task.Run(async () =>
{
_logHelper.Info($"连接{ip}:{port}");
result = await tcpClient.TryConnectAsync();
await Task.Delay(2000);
});
}
while (!result.IsSuccess);
_logHelper.Info($"{ip}:{port}连接成功");

@ -116,5 +116,7 @@ namespace HighWayIot.Winform.Business
DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
return descriptionAttribute.Description;
}
}
}

@ -1,4 +1,7 @@
using HighWayIot.Repository.domain;
using HighWayIot.Log4net;
using HighWayIot.Plc;
using HighWayIot.Plc.PlcHelper;
using HighWayIot.Repository.domain;
using HighWayIot.Repository.service;
using HighWayIot.Winform.Business;
using HighWayIot.Winform.MainForm;
@ -15,6 +18,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Schema;
namespace HighWayIot.Winform.UserControlPages
{
@ -53,12 +57,7 @@ namespace HighWayIot.Winform.UserControlPages
/// <summary>
/// 工位配方字段实例
/// </summary>
private ZxRecipePositionParaEntity zxRecipePositionParaEntity = new ZxRecipePositionParaEntity();
/// <summary>
/// 配方字段实例剪切板
/// </summary>
private ZxRecipeParaEntity zxRecipeParaEntityCut;
private List<ZxRecipePositionParaEntity> zxRecipePositionParaEntity = new List<ZxRecipePositionParaEntity>();
/// <summary>
/// 称重DataGridView数据源
@ -80,6 +79,26 @@ namespace HighWayIot.Winform.UserControlPages
/// </summary>
private string NowRecipeCode;
/// <summary>
/// 配方字段剪切板
/// </summary>
private ZxRecipeParaEntity ParaCopyBoard = new ZxRecipeParaEntity();
/// <summary>
/// 工位全部配方字段剪切板
/// </summary>
private List<ZxRecipePositionParaEntity> PositionParaCopyBoard = new List<ZxRecipePositionParaEntity>();
/// <summary>
/// 工位单个配方字段剪切板
/// </summary>
private ZxRecipePositionParaEntity SingalPositionParaCopyBoard;
/// <summary>
/// PLC实例
/// </summary>
private RecipeParaHelper recipeParaHelper = new RecipeParaHelper();
public RecipeConfigPage()
{
InitializeComponent();
@ -97,9 +116,17 @@ namespace HighWayIot.Winform.UserControlPages
RecipeDataGridView.DataSource = RecipeLists;
NowRecipeCode = RecipeDataGridView.Rows[0].Cells["RecipeCode"].Value.ToString();
InitPositionEntities();
//读取SPEC编号
PlcSpecNoLabel.Text = PlcConnect.ReadUInt321("D206").ToString();
//读取SPEC名称
PlcSpecNameLabel.Text = PlcConnect.ReadString1("D290", 10).Trim();
}
#region 配方信息
/// <summary>
/// 添加配方信息
/// </summary>
@ -232,6 +259,10 @@ namespace HighWayIot.Winform.UserControlPages
RecipeDataGridView.DataSource = RecipeLists;
}
#endregion
#region 称量信息
/// <summary>
/// 添加称量信息
/// </summary>
@ -371,199 +402,6 @@ namespace HighWayIot.Winform.UserControlPages
WeightDataGridView.DataSource = weightDataSourceEntities;
}
/// <summary>
/// 参数保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveParaButton_Click(object sender, EventArgs e)
{
//if (MessageBox.Show($"确定要保存配方编号为 [{s}] 的配方的参数?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
//{
// return;
//}
//获取前端的值
GetParaValue();
//搜索配方字段
var paraData = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(NowRecipeCode);
int flag = GetSelectIndex();
var positionParaData = zxRecipePositionParaService.GetRecipePositionParaInfos(x => x.RecipeCode == NowRecipeCode && x.Position == flag);
//获得对应工位号
bool isSuccess = false;
//公共参数
//没有就插入
if (paraData.Count == 0)
{
if(zxRecipeParaService.InsertRecipeParaInfo(zxRecipeParaEntity))
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
//有就更改
else if (paraData.Count == 1)
{
zxRecipeParaEntity.Id = paraData[0].Id;
if (zxRecipeParaService.UpdateRecipeParaInfo(zxRecipeParaEntity))
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
else
{
MessageBox.Show("存在多条未删除的相同公共参数!请检查数据库。");
return;
}
//贴合参数
//没有就插入
if (positionParaData.Count == 0)
{
if (zxRecipePositionParaService.InsertRecipePositionParaInfo(zxRecipePositionParaEntity))
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
//有就更改
else if (positionParaData.Count == 1)
{
zxRecipePositionParaEntity.Id = positionParaData[0].Id;
if (zxRecipePositionParaService.UpdateRecipePositionParaInfo(zxRecipePositionParaEntity))
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
else
{
MessageBox.Show("存在多条未删除的相同贴合参数!请检查数据库。");
return;
}
if (isSuccess)
{
BaseForm.LogRefreshAction.Invoke("保存成功" + DateTime.Now.ToString());
}
else
{
BaseForm.LogRefreshAction.Invoke("保存失败" + DateTime.Now.ToString());
}
}
/// <summary>
/// 参数复制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CopyParaButton_Click(object sender, EventArgs e)
{
//zxRecipeParaEntityCut = GetParaValue();
NowCopyLabel.Text = NowRecipeCode;
}
/// <summary>
/// 参数粘贴
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PasteParaButton_Click(object sender, EventArgs e)
{
if (zxRecipeParaEntityCut == null)
{
MessageBox.Show("剪切板为空!");
return;
}
//SetParaValue(zxRecipeParaEntityCut);
}
/// <summary>
/// 参数清空
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ClearCutBoradButton_Click(object sender, EventArgs e)
{
zxRecipeParaEntityCut = null;
NowCopyLabel.Text = "N/A";
if (MessageBox.Show("是否要清空前端数据", "", MessageBoxButtons.YesNo) == DialogResult.OK)
{
//SetParaValue(new ZxRecipeParaEntity());
}
}
/// <summary>
/// 所选配方内容更改事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RecipeDataGridView_SelectionChanged(object sender, EventArgs e)
{
int a = RecipeDataGridView.CurrentRow.Index;
NowRecipeCode = RecipeDataGridView.Rows[a].Cells["RecipeCode"].Value.ToString();
WeightLists = zxWeightService.GetWeightInfos(NowRecipeCode);
WeightToDataSource();
WeightDataGridView.DataSource = null;
WeightDataGridView.DataSource = weightDataSourceEntities;
//设置参数
var paraData = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(NowRecipeCode);
int flag = GetSelectIndex();
var positionParaData = zxRecipePositionParaService.GetRecipePositionParaInfos(x => x.RecipeCode == NowRecipeCode && x.Position == flag);
//没有就全0
if (paraData.Count == 0)
{
SetPublicParaValue(new ZxRecipeParaEntity());
}
//有就显示
else if (paraData.Count == 1)
{
SetPublicParaValue(paraData[0]);
}
//有多条设为第一条
else
{
MessageBox.Show("存在多条未删除的相同配方字段信息!将设置为第一条,请检查数据库。");
SetPublicParaValue(paraData[0]);
}
//没有就全0
if (positionParaData.Count == 0)
{
SetPrivateParaValue(new ZxRecipePositionParaEntity());
}
//有就显示
else if (positionParaData.Count == 1)
{
SetPrivateParaValue(positionParaData[0]);
}
//有多条设为第一条
else
{
MessageBox.Show("存在多条未删除的相同配方字段信息!将设置为第一条,请检查数据库。");
SetPrivateParaValue(positionParaData[0]);
}
}
/// <summary>
/// 称重数据关联物料数据
/// </summary>
@ -605,6 +443,212 @@ namespace HighWayIot.Winform.UserControlPages
}
}
#endregion
/// <summary>
/// 所选配方内容更改事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RecipeDataGridView_SelectionChanged(object sender, EventArgs e)
{
int a = RecipeDataGridView.CurrentRow.Index;
NowRecipeCode = RecipeDataGridView.Rows[a].Cells["RecipeCode"].Value.ToString();
SpecNoLabel.Text = RecipeDataGridView.Rows[a].Cells["RecipeSpecCode"].Value.ToString();
SpecNameLabel.Text = RecipeDataGridView.Rows[a].Cells["RecipeSpecName"].Value.ToString();
//初始化工位参数类
InitPositionEntities();
WeightLists = zxWeightService.GetWeightInfos(NowRecipeCode);
WeightToDataSource();
WeightDataGridView.DataSource = null;
WeightDataGridView.DataSource = weightDataSourceEntities;
//设置参数
var paraData = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(NowRecipeCode);
int flag = GetSelectIndex();
var positionParaData = zxRecipePositionParaService.GetRecipePositionParaInfos(x => x.RecipeCode == NowRecipeCode);
//没有就全0
if (paraData.Count == 0)
{
SetPublicParaValue(new ZxRecipeParaEntity());
zxRecipeParaEntity = new ZxRecipeParaEntity();
}
//有就显示
else if (paraData.Count == 1)
{
SetPublicParaValue(paraData[0]);
zxRecipeParaEntity = paraData[0];
}
//有多条设为第一条
else
{
MessageBox.Show("存在多条未删除的相同公共配方字段信息!将设置为第一条。点击清除脏数据");
SetPublicParaValue(paraData[0]);
zxRecipeParaEntity = paraData[0];
}
//没有就全0
if (positionParaData.Count == 0)
{
SetPrivateParaValue(new ZxRecipePositionParaEntity());
}
else
{
foreach (var item in positionParaData)
{
ChangePositionEntities(item);
}
SetPrivateParaValue(zxRecipePositionParaEntity.Where(x => x.Position == flag).FirstOrDefault());
}
}
#region 参数设置
/// <summary>
/// 参数保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveParaButton_Click(object sender, EventArgs e)
{
if (MessageBox.Show($"确定要保存配方编号为 [{NowRecipeCode}] 的配方的参数?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
var index = GetSelectIndex();
//从前端更新值
GetPublicParaValue();
GetPrivateParaValue(index);
//查重
var paraEntity = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(NowRecipeCode);
var positionParaEntity = zxRecipePositionParaService.GetRecipePositionParaInfoByRecipeCode(NowRecipeCode);
zxRecipeParaEntity.RecipeCode = NowRecipeCode;
//保存公共参数
var flag1 = true;
if (paraEntity.Count == 0) //没有就插入
{
flag1 = zxRecipeParaService.InsertRecipeParaInfo(zxRecipeParaEntity);
}
else if (paraEntity.Count == 1) //有就更新
{
zxRecipeParaEntity.Id = paraEntity[0].Id;
flag1 = zxRecipeParaService.UpdateRecipeParaInfo(zxRecipeParaEntity);
}
else //多条更新第一条
{
zxRecipeParaEntity.Id = paraEntity[0].Id;
flag1 = zxRecipeParaService.UpdateRecipeParaInfo(zxRecipeParaEntity);
MessageBox.Show("存在多条未删除的相同公共配方字段信息!将设置为第一条。点击清除脏数据");
}
//保存贴合参数
var flag2 = true;
foreach (var item in zxRecipePositionParaEntity)
{
item.RecipeCode = NowRecipeCode;
var count = positionParaEntity.Count(x => x.Position == item.Position);
//如果没有
if (count == 0)
{
flag2 = zxRecipePositionParaService.InsertRecipePositionParaInfo(item);
}
else //有 多条存第一条
{
item.Id = positionParaEntity.FirstOrDefault(x => x.Position == item.Position).Id;
flag2 = zxRecipePositionParaService.UpdateRecipePositionParaInfo(item);
if (count != 1) //多条提示
{
MessageBox.Show("存在多条未删除的相同公共配方字段信息!将设置为第一条。点击清除脏数据");
}
}
if (!flag2) break;
}
if (flag1 && flag2)
{
BaseForm.LogRefreshAction.Invoke("更新成功");
}
else
{
BaseForm.LogRefreshAction.Invoke("更新失败");
}
//保存贴合参数
}
/// <summary>
/// 初始化工位参数
/// </summary>
private void InitPositionEntities()
{
zxRecipePositionParaEntity.Clear();
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 1
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 2
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 31
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 32
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 41
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 42
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 51
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 52
});
}
/// <summary>
/// 替换工位信息中的元素
/// </summary>
/// <param name="entity"></param>
private void ChangePositionEntities(ZxRecipePositionParaEntity entity)
{
int index = zxRecipePositionParaEntity.FindIndex(x => x.Position == entity.Position);
if (index == -1)
{
BaseForm.LogRefreshAction.Invoke("数据保存失败,请重新启动页面");
return;
}
zxRecipePositionParaEntity[index] = entity;
}
/// <summary>
/// 设置显示的贴合参数字段值
/// </summary>
@ -621,7 +665,6 @@ namespace HighWayIot.Winform.UserControlPages
E8TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E8);
E9TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E9);
E10TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E10);
}
/// <summary>
@ -645,28 +688,41 @@ namespace HighWayIot.Winform.UserControlPages
LightWidthTextBox.Text = GeneralUtils.IntEmptyOrToString(paraEntity.LightWidth);
SlowDistanceTextBox.Text = GeneralUtils.IntEmptyOrToString(paraEntity.SlowDistance);
StopDistanceTextBox.Text = GeneralUtils.IntEmptyOrToString(paraEntity.StopDistance);
TireWeightTextBox.Text = GeneralUtils.IntEmptyOrToString(paraEntity.TireWeight);
TireWeightTextBox.Text = paraEntity.TireWeight == null ? "0" : paraEntity.TireWeight.ToString();
//SpecNoLabel.Text = GeneralUtils.IntEmptyOrToString(paraEntity.SpecCode);
//SpecNameLabel.Text = paraEntity.SpecName;
}
/// <summary>
/// 获取界面上的配方参数
/// 贴合参数获取值 存到实体
/// </summary>
/// <returns>获取到的配方参数值</returns>
private void GetParaValue()
/// <returns></returns>
private void GetPrivateParaValue(int flag)
{
zxRecipePositionParaEntity.E1 = GeneralUtils.StringNullOrToInt(E1TextBox.Text);
zxRecipePositionParaEntity.E2 = GeneralUtils.StringNullOrToInt(E2TextBox.Text);
zxRecipePositionParaEntity.E3 = GeneralUtils.StringNullOrToInt(E3TextBox.Text);
zxRecipePositionParaEntity.E4 = GeneralUtils.StringNullOrToInt(E4TextBox.Text);
zxRecipePositionParaEntity.E5 = GeneralUtils.StringNullOrToInt(E5TextBox.Text);
zxRecipePositionParaEntity.E6 = GeneralUtils.StringNullOrToInt(E6TextBox.Text);
zxRecipePositionParaEntity.E7 = GeneralUtils.StringNullOrToInt(E7TextBox.Text);
zxRecipePositionParaEntity.E8 = GeneralUtils.StringNullOrToInt(E8TextBox.Text);
zxRecipePositionParaEntity.E9 = GeneralUtils.StringNullOrToInt(E9TextBox.Text);
zxRecipePositionParaEntity.E10 = GeneralUtils.StringNullOrToInt(E10TextBox.Text);
zxRecipePositionParaEntity.Position = GetSelectIndex();
zxRecipePositionParaEntity.RecipeCode = NowRecipeCode;
var e = zxRecipePositionParaEntity.FirstOrDefault(x => x.Position == flag);
e.E1 = GeneralUtils.StringNullOrToInt(E1TextBox.Text);
e.E2 = GeneralUtils.StringNullOrToInt(E2TextBox.Text);
e.E3 = GeneralUtils.StringNullOrToInt(E3TextBox.Text);
e.E4 = GeneralUtils.StringNullOrToInt(E4TextBox.Text);
e.E5 = GeneralUtils.StringNullOrToInt(E5TextBox.Text);
e.E6 = GeneralUtils.StringNullOrToInt(E6TextBox.Text);
e.E7 = GeneralUtils.StringNullOrToInt(E7TextBox.Text);
e.E8 = GeneralUtils.StringNullOrToInt(E8TextBox.Text);
e.E9 = GeneralUtils.StringNullOrToInt(E9TextBox.Text);
e.E10 = GeneralUtils.StringNullOrToInt(E10TextBox.Text);
e.Position = GetSelectIndex();
e.RecipeCode = NowRecipeCode;
ChangePositionEntities(e);
}
/// <summary>
/// 公共参数获取值 存到实体
/// </summary>
/// <returns></returns>
private void GetPublicParaValue()
{
zxRecipeParaEntity.S0 = S0Check.Checked;
zxRecipeParaEntity.S1 = S1Check.Checked;
zxRecipeParaEntity.S2 = S2Check.Checked;
@ -681,12 +737,20 @@ namespace HighWayIot.Winform.UserControlPages
zxRecipeParaEntity.LightWidth = GeneralUtils.StringNullOrToInt(LightWidthTextBox.Text);
zxRecipeParaEntity.SlowDistance = GeneralUtils.StringNullOrToInt(SlowDistanceTextBox.Text);
zxRecipeParaEntity.StopDistance = GeneralUtils.StringNullOrToInt(StopDistanceTextBox.Text);
zxRecipeParaEntity.TireWeight = GeneralUtils.StringNullOrToInt(TireWeightTextBox.Text);
zxRecipeParaEntity.RecipeCode = NowRecipeCode;
try
{
zxRecipeParaEntity.TireWeight = float.Parse(TireWeightTextBox.Text == string.Empty ? "0" : TireWeightTextBox.Text);
}
catch
{
MessageBox.Show("胎体重量请输入整数或小数");
}
zxRecipeParaEntity.SpecCode = SpecNoLabel.Text;
zxRecipeParaEntity.SpecName = SpecNameLabel.Text;
}
/// <summary>
/// 工位改变
/// 工位改变 保存现在的,显示换的
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
@ -698,8 +762,9 @@ namespace HighWayIot.Winform.UserControlPages
{
int flag = GetSelectIndex();
SetParaView(flag);
if(flag < 10)
SetPrivateParaValue(zxRecipePositionParaEntity.Where(x => x.Position == flag).FirstOrDefault());
if (flag < 10)
{
BodyRadioButton.Enabled = false;
SideRadioButton.Enabled = false;
@ -712,21 +777,6 @@ namespace HighWayIot.Winform.UserControlPages
}
}
/// <summary>
/// 读取数据库设置贴合参数字段
/// </summary>
/// <param name="flag"></param>
/// <param name="recipeCode"></param>
private void SetParaView(int flag)
{
zxRecipePositionParaEntity = zxRecipePositionParaService.GetRecipePositionParaInfos(x => x.Position == flag && x.RecipeCode == NowRecipeCode).FirstOrDefault();
if (zxRecipePositionParaEntity == null)
{
zxRecipePositionParaEntity = new ZxRecipePositionParaEntity();
}
SetPrivateParaValue(zxRecipePositionParaEntity);
}
/// <summary>
/// 获取选择的工位包边
/// </summary>
@ -784,5 +834,214 @@ namespace HighWayIot.Winform.UserControlPages
return 0;
}
/// <summary>
/// 暂存工位参数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PositionRadioButton_MouseDown(object sender, MouseEventArgs e)
{
int index = GetSelectIndex();
GetPrivateParaValue(index);
BaseForm.LogRefreshAction.Invoke($"[{index.ToString()}] 工位参数已暂存");
}
/// <summary>
/// 公共参数复制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CopyParaButton_Click(object sender, EventArgs e)
{
ParaCopyBoard = zxRecipeParaEntity;
NowCopyLabel.Text = NowRecipeCode;
}
/// <summary>
/// 公共参数粘贴
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PasteParaButton_Click(object sender, EventArgs e)
{
if (ParaCopyBoard == null)
{
MessageBox.Show("剪切板为空!");
return;
}
SetPublicParaValue(ParaCopyBoard);
}
/// <summary>
/// 贴合参数复制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CopyPositionButton_Click(object sender, EventArgs e)
{
var index = GetSelectIndex();
GetPrivateParaValue(index);
SingalPositionParaCopyBoard = zxRecipePositionParaEntity.FirstOrDefault(x => x.Position == index);
PositionCopyBoardLabel.Text = index.ToString() + "|" + NowRecipeCode;
}
/// <summary>
/// 贴合参数粘贴
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PastePositionButton_Click(object sender, EventArgs e)
{
if (SingalPositionParaCopyBoard == null)
{
MessageBox.Show("剪切板为空!");
return;
}
SetPrivateParaValue(SingalPositionParaCopyBoard);
}
/// <summary>
/// 整体复制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CopyAllButton_Click(object sender, EventArgs e)
{
int index = GetSelectIndex();
GetPrivateParaValue(index);
ParaCopyBoard = new ZxRecipeParaEntity()
{
S0 = zxRecipeParaEntity.S0 ?? false,
S1 = zxRecipeParaEntity.S1 ?? false,
S2 = zxRecipeParaEntity.S2 ?? false,
S3 = zxRecipeParaEntity.S3 ?? false,
S4 = zxRecipeParaEntity.S4 ?? false,
S5 = zxRecipeParaEntity.S5 ?? false,
S6 = zxRecipeParaEntity.S6 ?? false,
S7 = zxRecipeParaEntity.S7 ?? false,
S8 = zxRecipeParaEntity.S8 ?? false,
S9 = zxRecipeParaEntity.S9 ?? false,
RimInch = zxRecipeParaEntity.RimInch,
LightWidth = zxRecipeParaEntity.LightWidth,
SlowDistance = zxRecipeParaEntity.SlowDistance,
StopDistance = zxRecipeParaEntity.StopDistance,
TireWeight = zxRecipeParaEntity.TireWeight,
};
PositionParaCopyBoard.Clear();
foreach (var entity in zxRecipePositionParaEntity)
{
var clone = new ZxRecipePositionParaEntity()
{
E1 = entity.E1,
E2 = entity.E2,
E3 = entity.E3,
E4 = entity.E4,
E5 = entity.E5,
E6 = entity.E6,
E7 = entity.E7,
E8 = entity.E8,
E9 = entity.E9,
E10 = entity.E10,
Position = entity.Position,
};
PositionParaCopyBoard.Add(clone);
}
//PositionParaCopyBoard = zxRecipePositionParaEntity;
NowCopyLabel.Text = NowRecipeCode + " 全复制";
PositionCopyBoardLabel.Text = "全复制";
}
/// <summary>
/// 整体粘贴
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PasteAllButton_Click(object sender, EventArgs e)
{
if (zxRecipeParaEntity != null && (zxRecipePositionParaEntity != null || zxRecipePositionParaEntity.Count != 8))
{
zxRecipePositionParaEntity = PositionParaCopyBoard;
zxRecipeParaEntity = ParaCopyBoard;
}
else
{
MessageBox.Show("粘贴失败,请重新复制数据");
}
SetPublicParaValue(zxRecipeParaEntity);
SetPrivateParaValue(zxRecipePositionParaEntity.First(x => x.Position == GetSelectIndex()));
}
/// <summary>
/// 清除脏数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ClearDirtyData_Click(object sender, EventArgs e)
{
if (MessageBox.Show($"确定要清除脏数据?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
if (zxRecipeParaService.DeleteDirtyData() &&
zxRecipePositionParaService.DeleteDirtyData())
{
MessageBox.Show("清除成功");
}
else
{
MessageBox.Show("清除失败");
}
}
/// <summary>
/// 上载到plc
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UploadToPlc_Click(object sender, EventArgs e)
{
if (MessageBox.Show($"是否要将此配方下传到PLC", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
GetPublicParaValue();
GetPrivateParaValue(GetSelectIndex());
if (recipeParaHelper.UploadToPLC(zxRecipeParaEntity, zxRecipePositionParaEntity))
{
MessageBox.Show("下发到PLC成功");
}
else
{
MessageBox.Show("下发到PLC失败");
}
PlcSpecNameLabel.Text = zxRecipeParaEntity.SpecName.Trim();
PlcSpecNoLabel.Text = zxRecipeParaEntity.SpecCode.Trim();
}
/// <summary>
/// 从plc读取
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DownloadFromPlc_Click(object sender, EventArgs e)
{
if (MessageBox.Show($"是否要从PLC读取配方", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
zxRecipePositionParaEntity = recipeParaHelper.DownLoadFormPlc(ref zxRecipeParaEntity);
SetPublicParaValue(zxRecipeParaEntity);
SetPrivateParaValue(zxRecipePositionParaEntity.First(x => x.Position == GetSelectIndex()));
PlcSpecNameLabel.Text = zxRecipeParaEntity.SpecName.Trim();
PlcSpecNoLabel.Text = zxRecipeParaEntity.SpecCode.Trim();
}
#endregion
}
}

@ -150,66 +150,6 @@
<metadata name="WeightIsUse.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="MaterialCode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="MaterialName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="MaterialType.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="MaterialChildType.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="SetThickness.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="SetWidth.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="SetLayer.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="SetWeight.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="SetError.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="WeightIsUse.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RecipeCode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RecipeName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RecipeSpecCode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RecipeSpecName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="SizeKind.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="FixedWidth.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="WeightError.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="IsUse.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

@ -39,6 +39,9 @@
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.PlcShowValue = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.LengthTextBox = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
@ -57,7 +60,7 @@
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(93, 51);
this.button2.TabIndex = 1;
this.button2.Text = "测试";
this.button2.Text = "测试1连接";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
@ -140,11 +143,40 @@
this.PlcShowValue.TabIndex = 11;
this.PlcShowValue.Text = "N/A";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(391, 252);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(29, 12);
this.label4.TabIndex = 13;
this.label4.Text = "长度";
//
// LengthTextBox
//
this.LengthTextBox.Location = new System.Drawing.Point(438, 249);
this.LengthTextBox.Name = "LengthTextBox";
this.LengthTextBox.Size = new System.Drawing.Size(100, 21);
this.LengthTextBox.TabIndex = 12;
//
// button3
//
this.button3.Location = new System.Drawing.Point(344, 57);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(93, 51);
this.button3.TabIndex = 14;
this.button3.Text = "测试2连接";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// TestPage
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ControlLight;
this.Controls.Add(this.button3);
this.Controls.Add(this.label4);
this.Controls.Add(this.LengthTextBox);
this.Controls.Add(this.PlcShowValue);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
@ -176,5 +208,8 @@
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label PlcShowValue;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox LengthTextBox;
private System.Windows.Forms.Button button3;
}
}

@ -6,6 +6,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
@ -48,9 +49,13 @@ namespace HighWayIot.Winform.UserControlPages
}
}
private void button2_Click(object sender, EventArgs e)
private async void button2_Click(object sender, EventArgs e)
{
var res = PlcConnect.IsConnect1;
bool res = false;
await Task.Run(() =>
{
res = PlcConnect.IsConnect1;
});
PlcShowValue.Text = res.ToString();
}
@ -94,6 +99,9 @@ namespace HighWayIot.Winform.UserControlPages
case DataTypeEnum.Double:
res = PlcConnect.ReadDouble1(PlcAddress.Text).ToString();
break;
case DataTypeEnum.String:
res = PlcConnect.ReadString1(PlcAddress.Text, (ushort)(GeneralUtils.StringNullOrToInt(LengthTextBox.Text) ?? 0)).ToString();
break;
default:
res = "不对劲儿奥";
break;
@ -105,17 +113,37 @@ namespace HighWayIot.Winform.UserControlPages
/// <summary>
/// PLC写入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="sender"></param>
/// <param name="e"></param>
private void WriteButton_Click(object sender, EventArgs e)
{
if(!decimal.TryParse(PlcValue.Text, out decimal value))
if ((DataTypeEnum)Convert.ToInt32(PlcType.SelectedValue) != DataTypeEnum.String)
{
MessageBox.Show("类型转换错误!");
if (!decimal.TryParse(PlcValue.Text, out decimal value))
{
MessageBox.Show("类型转换错误!");
}
var result = PlcConnect.PlcWrite1(PlcAddress.Text, value, (DataTypeEnum)Convert.ToInt32(PlcType.SelectedValue));
bool r = result.IsSuccess;
PlcShowValue.Text = r.ToString();
}
var result = PlcConnect.PlcWrite1(PlcAddress.Text, value, (DataTypeEnum)Convert.ToInt32(PlcType.SelectedValue));
bool r = result.IsSuccess;
PlcShowValue.Text = r.ToString();
else
{
string value = PlcValue.Text;
var result = PlcConnect.PlcWrite1(PlcAddress.Text, value, (DataTypeEnum)Convert.ToInt32(PlcType.SelectedValue));
bool r = result.IsSuccess;
PlcShowValue.Text = r.ToString();
}
}
private async void button3_Click(object sender, EventArgs e)
{
bool res = false;
await Task.Run(() =>
{
res = PlcConnect.IsConnect2;
});
PlcShowValue.Text = res.ToString();
}
}
}

Loading…
Cancel
Save