20230526提交

master
xiaoguo 2 years ago
parent b09f326df4
commit 1e76977ab2

@ -15,7 +15,7 @@ namespace PLCCommunication
{
get
{
if (pLCCommunicationService == null)
if (pLCCommunicationService == null|| !pLCCommunicationService.isConnected)
{
pLCCommunicationService = new DeltaCommunicationService();
pLCCommunicationService.Connection("192.168.0.50",502);

@ -22,11 +22,11 @@ namespace ZWGXPICK_SYS.SerialPort
/// <summary>
/// 串口名称
/// </summary>
public string ComName { get; private set; }
public string ComName { get; set; }
/// <summary>
/// 波特率
/// </summary>
public int ComBaud { get; private set; }
public int ComBaud { get; set; }
/// <summary>
/// 数据位
/// </summary>
@ -62,7 +62,6 @@ namespace ZWGXPICK_SYS.SerialPort
public static SerialPortUtilsBuilder Builder(string comName)
{
return new SerialPortUtilsBuilder(comName);
}
public class SerialPortUtilsBuilder
@ -132,9 +131,14 @@ namespace ZWGXPICK_SYS.SerialPort
{
try
{
if (SerialPort == null || !SerialPort.IsOpen)
if (SerialPort == null)
{
SerialPort = new System.IO.Ports.SerialPort();
//串口数据接收事件实现
SerialPort.DataReceived += new SerialDataReceivedEventHandler(ReceiveData);
}
if (!SerialPort.IsOpen)
{
SerialPort.PortName = ComName;
SerialPort.BaudRate = ComBaud;
SerialPort.DataBits = DataBits;
@ -142,9 +146,6 @@ namespace ZWGXPICK_SYS.SerialPort
SerialPort.Parity = Parity;
SerialPort.ReceivedBytesThreshold = ReceivedBytesThreshold;
SerialPort.Open();
//串口数据接收事件实现
SerialPort.DataReceived += new SerialDataReceivedEventHandler(ReceiveData);
}
return true;
}
@ -179,6 +180,10 @@ namespace ZWGXPICK_SYS.SerialPort
{
get
{
if (SerialPort == null)
{
return false;
}
return SerialPort.IsOpen;
}
}

@ -17,15 +17,15 @@ namespace ZWGXPICK_SYS.SerialPort
private SerialPortUtils serialPortUtils;
//发送请求
private byte[] sendCode = new byte[] { 0xFF, 0x03, 0x00, 0x00, 0x00, 0x02, 0xD1, 0xD5 };
// private byte[] sendCode = new byte[] { 0xFF, 0x03, 0x00, 0x00, 0x00, 0x02, 0xD1, 0xD5 };
//置零
private byte[] restZero = new byte[] { 0xFF, 0x06, 0x00, 0x07, 0x00, 0x02, 0xAC, 0x14 };
// private byte[] restZero = new byte[] { 0xFF, 0x06, 0x00, 0x07, 0x00, 0x02, 0xAC, 0x14 };
public event EventHandler<MessageEventArgs> MessageSend = null;
public event EventHandler<WeightModel> WeightSend = null;
public WeightEquipment(string comName, int comBaud, int ReceivedBytesThreshold = 9)
public WeightEquipment(string comName, int comBaud, int ReceivedBytesThreshold = 18) : base()
{
serialPortUtils = SerialPortUtils.Builder(comName).ComBaud(comBaud).ReceivedBytesThreshold(ReceivedBytesThreshold).Build();
serialPortUtils.SerialDataReceived += SerialPortUtils_SerialDataReceived;
@ -35,8 +35,16 @@ namespace ZWGXPICK_SYS.SerialPort
/// 打开连接
/// </summary>
/// <returns></returns>
public bool Open()
public bool Open(string comName = "", int comBaud = 0)
{
if (!string.IsNullOrEmpty(comName))
{
serialPortUtils.ComName = comName;
}
if (comBaud != 0)
{
serialPortUtils.ComBaud = comBaud;
}
var val = serialPortUtils.Open();
return val;
}
@ -56,35 +64,42 @@ namespace ZWGXPICK_SYS.SerialPort
/// 置零
/// </summary>
/// <returns></returns>
public bool Rset()
{
return serialPortUtils.SendData(restZero);
}
//public bool Rset()
//{
// return serialPortUtils.SendData(restZero);
//}
public bool Send()
{
return serialPortUtils.SendData(sendCode);
}
//public bool Send()
//{
// return serialPortUtils.SendData(sendCode);
//}
//接收数据
private void SerialPortUtils_SerialDataReceived(object sender, byte[] e)
{
if (e.Length != 9)
if (e.Length != 18)
{
MessageSend?.Invoke(this, new MessageEventArgs(true, $"接收数据长度不正确,长度为{e.Length}字节 "));
return;
}
//是否为重量数据
//var value = Convert.ToInt32(e[2].ToString("x2") + e[3].ToString("x2"), 16);
var weight = Math.Round((e[3] * 16 * 16 + e[4]) / 100m, 2);
WeightSend?.Invoke(this, new WeightModel
//转换为ASCII字符串
var str = ASCIIEncoding.ASCII.GetString(e);
var weightStr = str.Substring(9, 5);
if (!decimal.TryParse(weightStr, out var weight))
{
COMName = serialPortUtils.ComName,
Weight = weight,
Nuit = "克",
});
MessageSend?.Invoke(this, new MessageEventArgs(true, $"数据解析不正确,数据为:{str},重量解析为:{weightStr}"));
return;
}
if (weight > 0)
{
Math.Round(weight, 2);
WeightSend?.Invoke(this, new WeightModel
{
COMName = serialPortUtils.ComName,
Weight = weight,
Nuit = "克",
});
}
}
// 消息提醒
@ -92,15 +107,5 @@ namespace ZWGXPICK_SYS.SerialPort
{
MessageSend?.Invoke(this, e);
}
//触发错误消息事件
/*private void PrintMessage(bool isError, string title, byte[] value = null)
{
string error = $"端口{serialPortUtils.ComName},波特率{serialPortUtils.ComBaud},{title}{(value != null ? ":" + BitConverter.ToString(value) : "")}";
MessageSend?.Invoke(this, new MessageEventArgs(isError: isError, message: error));
}*/
}
}

@ -1,107 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace ZWGXPICK_SYS.SerialPort
{
/// <summary>
/// 称重设备
/// </summary>
public class WeightEquipment
{
private SerialPortUtils serialPortUtils;
//控制指令格式 D+(字符)+0x0D+0x0A
private byte[] controlFormat = new byte[] { Convert.ToByte('D'), 0, 0x0D, 0x0A };
public event EventHandler<MessageEventArgs> MessageSend = null;
public event EventHandler<WeightModel> WeightSend = null;
public WeightEquipment(string comName, int comBaud)
{
serialPortUtils = SerialPortUtils.Builder(comName).ComBaud(comBaud).Build();
serialPortUtils.SerialDataReceived += SerialPortUtils_SerialDataReceived;
serialPortUtils.SerialMessage += SerialPortUtils_SerialMessage;
}
/// <summary>
/// 打开连接
/// </summary>
/// <returns></returns>
public bool Open()
{
var val = serialPortUtils.Open();
return val;
}
/// <summary>
/// 关闭连接
/// </summary>
public void Close()
{
serialPortUtils.Close();
}
/// <summary>
/// 置零
/// </summary>
/// <returns></returns>
public bool Rset()
{
controlFormat[1] = Convert.ToByte('Z');
return serialPortUtils.SendData(controlFormat);
}
//接收数据
private void SerialPortUtils_SerialDataReceived(object sender, byte[] e)
{
if (e.Length != 20)
{
PrintMessage(true, "接收数据长度不正确", e);
}
//是否为重量数据
//获取head1 OL--超载 ST--稳定 US--不稳定
var head1 = new byte[2];
Array.Copy(e, head1, 2);
//获取head2 NT--净重模式 GS--毛重模式
var head2 = new byte[2];
Array.Copy(e, 4, head2, 0, 2);
var head1Str = Encoding.ASCII.GetString(head1);
if (head1Str.Equals("OL") || head1Str.Equals("ST") || head1Str.Equals("US"))
{
//data
var data = new byte[8];
Array.Copy(e, 7, data, 0, 7);
decimal.TryParse(Encoding.ASCII.GetString(data), out var weight);
//unit
var unit = new byte[4];
Array.Copy(e, 15, unit, 0, 4);
WeightSend?.Invoke(this, new WeightModel
{
COMName = serialPortUtils.ComName,
Weight = weight,
Nuit = Encoding.ASCII.GetString(unit),
Head1 = head1Str,
Head2 = Encoding.ASCII.GetString(head2),
});
}
PrintMessage(true, "接收数据", e);
}
// 错误数据
private void SerialPortUtils_SerialMessage(object sender, MessageEventArgs e)
{
MessageSend?.Invoke(this, e);
}
//触发错误消息事件
private void PrintMessage(bool isError, string title, byte[] value = null)
{
string error = $"端口{serialPortUtils.ComName},波特率{serialPortUtils.ComBaud},{title}{(value != null ? ":" + Encoding.ASCII.GetString(value) : "")}";
MessageSend?.Invoke(this, new MessageEventArgs(isError: isError, message: error));
}
}
}

@ -1,186 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZWGXPICK_SYS.SerialPort
{
/// <summary>
/// 重量设备聚合类
/// </summary>
public class WeightEquipmentAggregation
{
private int comBaud;
private string[] comNames;
private decimal standard;
private decimal tolerance;
private decimal range;
private List<WeightEquipment> weightEquipments;
private List<WeightModel> WeightModels;
public event EventHandler<MessageEventArgs> MessageSend;
public event EventHandler<List<WeightModel>> WeightSend;
public event EventHandler<bool> SuccessSend;
public void Init(int comBaud, string[] comNames, decimal standard, decimal tolerance, decimal range)
{
this.comBaud = comBaud;
this.comNames = comNames;
this.standard = standard;
this.tolerance = tolerance;
this.range = range;
int id = 0;
//如果重复初始化,就先关闭连接
if (weightEquipments != null && weightEquipments.Count > 0)
{
Close();
}
weightEquipments = new List<WeightEquipment>();
WeightModels = new List<WeightModel>();
foreach (var comName in comNames)
{
var weightEquipment = new WeightEquipment(comName, comBaud, 9);
weightEquipment.WeightSend += WeightEquipment_WeightSend;
weightEquipment.MessageSend += WeightEquipment_MessageSend;
weightEquipments.Add(weightEquipment);
WeightModels.Add(new WeightModel
{
ID = ++id,
COMName = comName
});
}
WeightSend?.Invoke(this, WeightModels);
}
/// <summary>
/// 打开称重设备连接
/// </summary>
public bool Open()
{
var result = new List<bool>();
weightEquipments?.ForEach(item => result.Add(item.Open()));
return result.Where(f => f).Count() == weightEquipments.Count;
}
/// <summary>
/// 称重设备置零
/// </summary>
public bool Rest()
{
var result = new List<bool>();
weightEquipments?.ForEach(item => result.Add(item.Rset()));
return result.Where(f => f).Count() == weightEquipments.Count;
}
/// <summary>
/// 发送获取重量命令
/// </summary>
/// <returns></returns>
public bool Send()
{
var result = new List<bool>();
weightEquipments?.ForEach(item => result.Add(item.Send()));
return result.Where(f => f).Count() == weightEquipments.Count;
}
/// <summary>
/// 关闭称重设备
/// </summary>
public void Close()
{
weightEquipments?.ForEach(item => item.Close());
}
public bool IsOpen()
{
if (weightEquipments == null || weightEquipments.Count == 0)
{
return false;
}
var result = new List<bool>();
weightEquipments?.ForEach(item => result.Add(item.IsOpen()));
return result.Where(f => f).Count() == weightEquipments.Count;
}
//获取错误信息
private void WeightEquipment_MessageSend(object sender, MessageEventArgs e)
{
MessageSend?.Invoke(this, e);
saveLog(e.Message);
}
//获取重量信息
private void WeightEquipment_WeightSend(object sender, WeightModel e)
{
var weight = WeightModels.Where(f => f.COMName == e.COMName).FirstOrDefault();
if (weight != null)
{
weight.Weight = e.Weight;
weight.Nuit = e.Nuit;
//weight.Head1 = e.Head1;
//weight.Head2 = e.Head2;
}
//如果数据稳定 则进行计算
if (WeightModels.Where(f =>!string.IsNullOrEmpty(f.Nuit)).Count() == WeightModels.Count)
{
var val = Calculation();
//发送重量计算结果
SuccessSend?.Invoke(this, val);
}
WeightSend?.Invoke(this, WeightModels);
}
//根据重量计算是否合格
public bool Calculation()
{
var res = Calculation(WeightModels, standard, tolerance, range);
MessageSend?.Invoke(this, new MessageEventArgs(message: "称重计算结果为:" + res));
return res;
}
public bool Calculation(List<WeightModel> WeightModels, decimal standard, decimal tolerance, decimal range)
{
if (standard > 0 && tolerance >= 0 && range >= 0)
{
//过滤小于0.5的重量数据
var actualWeightModels = WeightModels.Where(f => f.Weight > 0.5m);
//是否均在公差范围之内
if (actualWeightModels.Where(f => f.Weight <= standard + tolerance && f.Weight >= standard - tolerance).Count() == actualWeightModels.Count())
{
//是否在极差范围之内
var maxOne = actualWeightModels.Select(f => f.Weight).Max();
var minOne = actualWeightModels.Select(f => f.Weight).Min();
if (maxOne - minOne <= range)
{
return true;
}
}
}
return false;
}
//记录日志
private void saveLog(string str)
{
string logDir = Environment.CurrentDirectory + "\\Logs\\";
if (Directory.Exists(logDir))
{
Directory.CreateDirectory(logDir);
}
string logFile = $"{logDir}weightEquipments_{DateTime.Today.ToString("yyyy-MM-dd")}.log";
string text = $"【{DateTime.Now.ToLongTimeString()}】{str}{Environment.NewLine}" ;
try
{
File.AppendAllText(logFile, text);
}
catch (Exception ex) { }
}
}
}

@ -30,14 +30,7 @@ namespace ZWGXPICK_SYS.SerialPort
/// </summary>
public string Nuit { get; set; }
//public string Head1 { get; set; }
//public string Head2 { get; set; }
public string Message { get; set; }
//public bool IsGetValue { get; set; }
}
}

@ -49,9 +49,7 @@
<Compile Include="SerialPortUtils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WeightEquipment.cs" />
<Compile Include="WeightEquipmentAggregation.cs" />
<Compile Include="WeightModel.cs" />
<None Include="WeightEquipment.old" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

@ -38,8 +38,8 @@
this.btnYsub = new System.Windows.Forms.Button();
this.btnYplus = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel();
this.RO606 = new System.Windows.Forms.CheckBox();
this.RO605 = new System.Windows.Forms.CheckBox();
this.RO004 = new System.Windows.Forms.CheckBox();
this.RO003 = new System.Windows.Forms.CheckBox();
this.btnMotoOff = new System.Windows.Forms.Button();
this.btnMotoOn = new System.Windows.Forms.Button();
this.btnSetSpeed = new System.Windows.Forms.Button();
@ -215,8 +215,8 @@
// panel3
//
this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel3.Controls.Add(this.RO606);
this.panel3.Controls.Add(this.RO605);
this.panel3.Controls.Add(this.RO004);
this.panel3.Controls.Add(this.RO003);
this.panel3.Controls.Add(this.btnMotoOff);
this.panel3.Controls.Add(this.btnMotoOn);
this.panel3.Controls.Add(this.btnSetSpeed);
@ -225,35 +225,35 @@
this.panel3.Size = new System.Drawing.Size(199, 308);
this.panel3.TabIndex = 233;
//
// RO606
//
this.RO606.Appearance = System.Windows.Forms.Appearance.Button;
this.RO606.FlatAppearance.CheckedBackColor = System.Drawing.Color.Red;
this.RO606.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.RO606.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.RO606.Location = new System.Drawing.Point(3, 228);
this.RO606.Name = "RO606";
this.RO606.Size = new System.Drawing.Size(191, 52);
this.RO606.TabIndex = 240;
this.RO606.Text = "RO606气爪";
this.RO606.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.RO606.UseVisualStyleBackColor = true;
this.RO606.Click += new System.EventHandler(this.RO0_Click);
//
// RO605
//
this.RO605.Appearance = System.Windows.Forms.Appearance.Button;
this.RO605.FlatAppearance.CheckedBackColor = System.Drawing.Color.Red;
this.RO605.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.RO605.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.RO605.Location = new System.Drawing.Point(3, 171);
this.RO605.Name = "RO605";
this.RO605.Size = new System.Drawing.Size(191, 52);
this.RO605.TabIndex = 241;
this.RO605.Text = "RO605真空";
this.RO605.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.RO605.UseVisualStyleBackColor = true;
this.RO605.Click += new System.EventHandler(this.RO0_Click);
// RO004
//
this.RO004.Appearance = System.Windows.Forms.Appearance.Button;
this.RO004.FlatAppearance.CheckedBackColor = System.Drawing.Color.Red;
this.RO004.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.RO004.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.RO004.Location = new System.Drawing.Point(3, 228);
this.RO004.Name = "RO004";
this.RO004.Size = new System.Drawing.Size(191, 52);
this.RO004.TabIndex = 240;
this.RO004.Text = "RO004气爪";
this.RO004.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.RO004.UseVisualStyleBackColor = true;
this.RO004.Click += new System.EventHandler(this.RO0_Click);
//
// RO003
//
this.RO003.Appearance = System.Windows.Forms.Appearance.Button;
this.RO003.FlatAppearance.CheckedBackColor = System.Drawing.Color.Red;
this.RO003.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.RO003.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.RO003.Location = new System.Drawing.Point(3, 171);
this.RO003.Name = "RO003";
this.RO003.Size = new System.Drawing.Size(191, 52);
this.RO003.TabIndex = 241;
this.RO003.Text = "RO003真空";
this.RO003.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.RO003.UseVisualStyleBackColor = true;
this.RO003.Click += new System.EventHandler(this.RO0_Click);
//
// btnMotoOff
//
@ -714,7 +714,7 @@
private System.Windows.Forms.Button btnUplus;
private System.Windows.Forms.Button btnSetSpeed;
private System.Windows.Forms.Button btnRealtimePoint;
private System.Windows.Forms.CheckBox RO606;
private System.Windows.Forms.CheckBox RO605;
private System.Windows.Forms.CheckBox RO004;
private System.Windows.Forms.CheckBox RO003;
}
}

@ -37,6 +37,12 @@
<Reference Include="PCHMI">
<HintPath>..\..\thirdparts\PCHMI.dll</HintPath>
</Reference>
<Reference Include="RICADO.MettlerToledo, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RICADO.MettlerToledo.1.1.0\lib\netstandard2.0\RICADO.MettlerToledo.dll</HintPath>
</Reference>
<Reference Include="RICADO.Sockets, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RICADO.Sockets.1.3.0\lib\netstandard2.0\RICADO.Sockets.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Design" />
@ -164,6 +170,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

@ -59,11 +59,4 @@ txtPointU=0
[weight_RS232]
baud=9600
comEnable0=true
comEnable1=true
comEnable2=true
comEnable3=true
comName0=COM1
comName1=COM2
comName2=COM3
comName3=COM4
comName=COM1

File diff suppressed because it is too large Load Diff

@ -2,6 +2,7 @@
using Maticsoft.DBUtility;
using PCHMI;
using PLCCommunication;
using PLCCommunication.Common;
using System;
using System.Collections.Generic;
@ -72,10 +73,30 @@ namespace ZWGXPICK_SYS
private float Y;
private ZWGXPICK_SYS.Model.PRODUCT_ITEM_CONFIG product = null; //当前选中的产品信息.
//重量设备聚合类
private WeightEquipmentAggregation weightEquipmentAggregation = null;
private DataTable dtWeight = new DataTable();
/// <summary>
/// 重量设类
/// </summary>
private WeightEquipment weightEquipment = null;
/// <summary>
/// 设置单重上限
/// </summary>
private decimal setSingleUpperLimit = 0;
/// <summary>
/// 设置调整上限
/// </summary>
private decimal setAdjustmentUpperLimit = 0;
/// <summary>
/// 设置一个标准重量
/// </summary>
private decimal setStandardWeight = 0;
/// <summary>
/// 设置调整下限
/// </summary>
private decimal setAdjustmentLowerLimit = 0;
/// <summary>
/// 设置单重下限
/// </summary>
private decimal setSingleLowerLimit = 0;
public MainForm()
{
@ -90,7 +111,7 @@ namespace ZWGXPICK_SYS
this.mlbMatrix[row, col] = new GraphicsPath();
}
}
//RICADO.MettlerToledo.MettlerToledoDevice mettlerToledoDevice = new RICADO.MettlerToledo.MettlerToledoDevice(RICADO.MettlerToledo.ConnectionMethod.Ethernet,RICADO.MettlerToledo.ProtocolType.SICS,"111",10);
}
private void setTag(Control cons)
@ -192,16 +213,7 @@ namespace ZWGXPICK_SYS
initTriggerList();
this.createLogDir();
dtWeight.Columns.Add("ID");
dtWeight.Columns.Add("COMName");
dtWeight.Columns.Add("Weight");
dtWeight.Columns.Add("Nuit");
dtWeight.Columns.Add("Message");
dgvWeight.DataSource = dtWeight;
//this.dgvWeight.DefaultCellStyle.ForeColor = Color.Red;
this.dgvWeight.DefaultCellStyle.Font = new Font("Microsoft YaHei", 8, FontStyle.Bold);
this.dgvWeight.ColumnHeadersDefaultCellStyle.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold);
this.dgvWeight.AutoGenerateColumns = false;
}
// 绘制函数.
@ -263,9 +275,9 @@ namespace ZWGXPICK_SYS
this.txt_cleanmode_interval.Text = ini.ReadString("global", "txt_cleanmode_interval", "");
this.txt_continuity_unqualified.Text = ini.ReadString("global", "txt_continuity_unqualified", "");
this.txt_standard_weight.Text = ini.ReadString("global", "txt_standard_weight", "");
this.txt_qualified_allow_error.Text = ini.ReadString("global", "txt_qualified_allow_error", "");
this.txt_single_weight_allow_error.Text = ini.ReadString("global", "txt_single_weight_allow_error", "");
//this.txt_standard_weight.Text = ini.ReadString("global", "txt_standard_weight", "");
//this.txt_qualified_allow_error.Text = ini.ReadString("global", "txt_qualified_allow_error", "");
//this.txt_single_weight_allow_error.Text = ini.ReadString("global", "txt_single_weight_allow_error", "");
this.txt_plan_placed_num.Text = ini.ReadString("global", "txt_plan_placed_num", "1");
if (this.txt_plan_placed_num.Text == "") this.txt_plan_placed_num.Text = "1";
@ -273,11 +285,19 @@ namespace ZWGXPICK_SYS
if ((nSpeed < 5) || (nSpeed > 100)) nSpeed = 5;
this.txt_run_speed.Text = nSpeed.ToString();
//重量设备聚合类 初始化
weightEquipmentAggregation = new WeightEquipmentAggregation();
weightEquipmentAggregation.MessageSend += WeightEquipmentAggregation_MessageSend;
weightEquipmentAggregation.WeightSend += WeightEquipmentAggregation_WeightSend;
weightEquipmentAggregation.SuccessSend += WeightEquipmentAggregation_SuccessSend;
//重量计算参数
setSingleUpperLimit = decimal.Parse(ini.ReadString("weight_RS232", "setSingleUpperLimit", "0"));
setAdjustmentUpperLimit = decimal.Parse(ini.ReadString("weight_RS232", "setAdjustmentUpperLimit", "0"));
setStandardWeight = decimal.Parse(ini.ReadString("weight_RS232", "setStandardWeight", "0"));
setAdjustmentLowerLimit = decimal.Parse(ini.ReadString("weight_RS232", "setAdjustmentLowerLimit", "0"));
setSingleLowerLimit = decimal.Parse(ini.ReadString("weight_RS232", "setSingleLowerLimit", "0"));
//重量设备 初始化
var baud = ini.ReadString("weight_RS232", "baud");
var comName = ini.ReadString("weight_RS232", "comName");
weightEquipment = new WeightEquipment(comName,int.Parse(baud));
weightEquipment.MessageSend += WeightEquipment_MessageSend;
weightEquipment.WeightSend += WeightEquipment_WeightSend;
}
// 写ini配置信息.
@ -2001,90 +2021,49 @@ namespace ZWGXPICK_SYS
form.ShowDialog(this);
}
public void InitWeightEquipmentAggregation()
public void InitWeightEquipment()
{
IniFile ini = new IniFile(PubConstant.config_file);
var txt_standard_weight = ini.ReadString("global", "txt_standard_weight", "");
var txt_qualified_allow_error = ini.ReadString("global", "txt_qualified_allow_error", "");
var txt_single_weight_allow_error = ini.ReadString("global", "txt_single_weight_allow_error", "");
int baud = ini.ReadInteger("weight_RS232", "baud", 9600);
bool comEnable0 = ini.ReadBool("weight_RS232", "comEnable0", true);
bool comEnable1 = ini.ReadBool("weight_RS232", "comEnable1", true);
bool comEnable2 = ini.ReadBool("weight_RS232", "comEnable2", true);
bool comEnable3 = ini.ReadBool("weight_RS232", "comEnable3", true);
string comName0 = ini.ReadString("weight_RS232", "comName0");
string comName1 = ini.ReadString("weight_RS232", "comName1");
string comName2 = ini.ReadString("weight_RS232", "comName2");
string comName3 = ini.ReadString("weight_RS232", "comName3");
List<string> comNames = new List<string>();
if (comEnable0)
{
comNames.Add(comName0);
}
if (comEnable1)
//重量计算参数
setSingleUpperLimit = decimal.Parse(ini.ReadString("weight_RS232", "setSingleUpperLimit", "0"));
setAdjustmentUpperLimit = decimal.Parse(ini.ReadString("weight_RS232", "setAdjustmentUpperLimit", "0"));
setStandardWeight = decimal.Parse(ini.ReadString("weight_RS232", "setStandardWeight" ));
setAdjustmentLowerLimit = decimal.Parse(ini.ReadString("weight_RS232", "setAdjustmentLowerLimit", "0"));
setSingleLowerLimit = decimal.Parse(ini.ReadString("weight_RS232", "setSingleLowerLimit", "0"));
if (!weightEquipment.IsOpen())
{
comNames.Add(comName1);
var baud = ini.ReadInteger("weight_RS232", "baud", 0);
var comName = ini.ReadString("weight_RS232", "comName");
weightEquipment.Open(comName, baud);
}
if (comEnable2)
{
comNames.Add(comName2);
}
if (comEnable3)
{
comNames.Add(comName3);
}
decimal standard_weight = 0, qualified_allow_error = 0, single_weight_allow_error = 0;
decimal.TryParse(txt_standard_weight, out standard_weight);
decimal.TryParse(txt_qualified_allow_error, out qualified_allow_error);
decimal.TryParse(txt_single_weight_allow_error, out single_weight_allow_error);
weightEquipmentAggregation.Init(baud, comNames.ToArray(), standard_weight, qualified_allow_error, single_weight_allow_error);
}
//称重置零
private void WeightRest()
{
InitWeightEquipmentAggregation();
var res = weightEquipmentAggregation.Open();
if (!res)
var result = false;
if (!weightEquipment.IsOpen())
{
return;
InitWeightEquipment();
result = weightEquipment.Open();
}
res = weightEquipmentAggregation.Rest();
if (this.epsonSocket2.IsConnection)
{
string cmd = $"$weightreset;{(res ? 1 : 0)}";
string cmd = $"$weightreset;{(result ? 1 : 0)}";
this.epsonSocket2.tcp_send(cmd);
WeightPrintMessage($"发送【称重置零】命令:{cmd} 【{(result ? "" : "")}】");
WeightPrintMessage($"发送【称重置零】命令:{cmd} 【{(res ? "" : "")}】");
PLCWriteBool("M215", false);
PLCWriteBool("M216", false);
}
}
//获取称重
private void WeightSend()
{
if (!weightEquipmentAggregation.IsOpen())
{
InitWeightEquipmentAggregation();
var res = weightEquipmentAggregation.Open();
if (!res)
{
return;
}
}
var result = weightEquipmentAggregation.Send();
//if (this.epsonSocket2.IsConnection)
//{
// string cmd = "weightsend;" + (result ? 1 : 0).ToString();
// this.epsonSocket2.tcp_send(cmd);
// WeightPrintMessage($"发送【获取重量】命令:{cmd} 成功!");
//}
}
//称重结果返回
private void WeightResult(bool result)
{
var result = CalculatingWeighingResult();
if (this.epsonSocket2.IsConnection)
{
string cmd = $"$weightsend;{(result ? 1 : 0)}";
@ -2092,12 +2071,61 @@ namespace ZWGXPICK_SYS
WeightPrintMessage($"发送【称重结果】命令:{cmd} 【{(result ? "" : "")}】");
//关闭连接
weightEquipmentAggregation.Close();
weightEquipment.Close();
WeightAddToDB(result);
}
}
//计算称重结果
private bool CalculatingWeighingResult()
{
var result = false;
var txtSetStandardWeight = 0m;
this.Invoke(new MethodInvoker(() =>
{
decimal.TryParse(txt_standard_weight.Text.Trim(), out txtSetStandardWeight);
}));
if (txtSetStandardWeight <= 0)
{
return false;
}
//调整下限<实时重量<标准重量返回称重OK给机械手
if (setAdjustmentLowerLimit <= txtSetStandardWeight && txtSetStandardWeight <= setStandardWeight)
{
result = true;
}
//标准重量 < 实时重量 < 调整上限返回称重OK给机械手
else if (setStandardWeight <= txtSetStandardWeight && txtSetStandardWeight <= setAdjustmentUpperLimit)
{
result = true;
}
//单重下限<实时重量<调整下限返回称重OK给机械手同时将PLC M216写TRUE
else if (setSingleLowerLimit <= txtSetStandardWeight && txtSetStandardWeight <= setAdjustmentLowerLimit)
{
result = true;
PLCWriteBool("M216", true);
}
// 调整上限<实时重量<单重上限返回称重OK给机械手同时将PLC M215写TRUE
else if (setAdjustmentUpperLimit <= txtSetStandardWeight && txtSetStandardWeight <= setSingleUpperLimit)
{
result = true;
PLCWriteBool("M215",true);
}
//调实时重量<调整下限返回称重NG给机械手
else if (txtSetStandardWeight <= setAdjustmentLowerLimit)
{
result = false;
}
//调实时重量>调整上限返回称重NG给机械手
else if (txtSetStandardWeight >= setAdjustmentUpperLimit)
{
result = false;
}
return result;
}
//将重量信息添加到数据库
private void WeightAddToDB(bool result)
{
@ -2119,48 +2147,21 @@ namespace ZWGXPICK_SYS
}
//称重设备结果计算是否成功
private void WeightEquipmentAggregation_SuccessSend(object sender, bool e)
{
WeightResult(e);
}
//称重设备返回重量信息
private void WeightEquipmentAggregation_WeightSend(object sender, List<WeightModel> e)
private void WeightEquipment_WeightSend(object sender, WeightModel e)
{
this.Invoke(new Action(() =>
this.Invoke(new MethodInvoker(() =>
{
dtWeight.Rows.Clear();
foreach (var item in e)
{
var dr = dtWeight.NewRow();
dr[nameof(item.ID)] = item.ID;
dr[nameof(item.COMName)] = item.COMName;
dr[nameof(item.Nuit)] = item.Nuit;
dr[nameof(item.Weight)] = item.Weight;
dr[nameof(item.Message)] = item.Message;
dtWeight.Rows.Add(dr);
}
txt_standard_weight.Text = e.Weight.ToString();
}));
}
//称重设备错误信息
private void WeightEquipmentAggregation_MessageSend(object sender, MessageEventArgs e)
private void WeightEquipment_MessageSend(object sender, MessageEventArgs e)
{
WeightPrintMessage(e.Message);
}
//输出称重消息
private void WeightPrintMessage(string message)
{
if (txtWeightMessage.Lines.Length >= 500)
{
txtWeightMessage.Clear();
}
txtWeightMessage.AppendText($"【{DateTime.Now.ToString("HH:mm:ss")}】:{message}{Environment.NewLine}");
}
//称重重置
private void btnWeightRest_Click(object sender, EventArgs e)
{
@ -2175,12 +2176,38 @@ namespace ZWGXPICK_SYS
//称重计算
private void btnWeightCalculate_Click(object sender, EventArgs e)
{
var res = weightEquipmentAggregation.Calculation();
var result = CalculatingWeighingResult();
WeightPrintMessage($"手动称重【称重结果】:【{(result ? "" : "")}】");
}
private void PLCWriteBool(string pointName,bool value)
{
var res = PLCCommunicationFactory.Instance.Write(pointName, value);
var msg = "";
if (res.IsSuccess)
{
msg = $"{pointName} 写入值 {value} 成功!";
}
else
{
msg = $"{pointName} 写入值 {value} 失败!{res.Message}";
}
WeightPrintMessage(msg);
}
//输出称重消息
private void WeightPrintMessage(string message)
{
WeightResult(res);
if (txtWeightMessage.Lines.Length >= 500)
{
txtWeightMessage.Clear();
}
txtWeightMessage.AppendText($"【{DateTime.Now.ToString("HH:mm:ss")}】:{message}{Environment.NewLine}");
}
#endregion
}
}

@ -117,18 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="colID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="colComName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="colWeight.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="colUnit.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Timer_Getstatus.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>181, 17</value>
</metadata>

@ -29,21 +29,21 @@
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtWeightComName0 = new System.Windows.Forms.TextBox();
this.txtWeightComName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.btnOk = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.cbbps = new System.Windows.Forms.ComboBox();
this.txtWeightComName1 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtWeightComName2 = new System.Windows.Forms.TextBox();
this.txtSetSingleUpperLimit = new System.Windows.Forms.TextBox();
this.txtSetAdjustmentUpperLimit = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtWeightComName3 = new System.Windows.Forms.TextBox();
this.txtSetStandardWeight = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.chbEnable0 = new System.Windows.Forms.CheckBox();
this.chbEnable1 = new System.Windows.Forms.CheckBox();
this.chbEnable2 = new System.Windows.Forms.CheckBox();
this.chbEnable3 = new System.Windows.Forms.CheckBox();
this.txtSetAdjustmentLowerLimit = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.txtSetSingleLowerLimit = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
@ -55,25 +55,25 @@
this.label1.TabIndex = 0;
this.label1.Text = "波特率: ";
//
// txtWeightComName0
// txtWeightComName
//
this.txtWeightComName0.Location = new System.Drawing.Point(126, 53);
this.txtWeightComName0.Name = "txtWeightComName0";
this.txtWeightComName0.Size = new System.Drawing.Size(235, 34);
this.txtWeightComName0.TabIndex = 1;
this.txtWeightComName.Location = new System.Drawing.Point(157, 50);
this.txtWeightComName.Name = "txtWeightComName";
this.txtWeightComName.Size = new System.Drawing.Size(235, 34);
this.txtWeightComName.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 56);
this.label2.Location = new System.Drawing.Point(12, 53);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(115, 27);
this.label2.Size = new System.Drawing.Size(103, 27);
this.label2.TabIndex = 2;
this.label2.Text = "设备1端口: ";
this.label2.Text = "设备端口: ";
//
// btnOk
//
this.btnOk.Location = new System.Drawing.Point(199, 223);
this.btnOk.Location = new System.Drawing.Point(157, 307);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(102, 42);
this.btnOk.TabIndex = 5;
@ -83,7 +83,7 @@
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(332, 223);
this.btnCancel.Location = new System.Drawing.Point(290, 307);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(102, 42);
this.btnCancel.TabIndex = 6;
@ -100,119 +100,111 @@
"19200",
"38400",
"115200"});
this.cbbps.Location = new System.Drawing.Point(126, 14);
this.cbbps.Location = new System.Drawing.Point(157, 14);
this.cbbps.Name = "cbbps";
this.cbbps.Size = new System.Drawing.Size(235, 29);
this.cbbps.TabIndex = 0;
//
// txtWeightComName1
//
this.txtWeightComName1.Location = new System.Drawing.Point(126, 93);
this.txtWeightComName1.Name = "txtWeightComName1";
this.txtWeightComName1.Size = new System.Drawing.Size(235, 34);
this.txtWeightComName1.TabIndex = 2;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 96);
this.label3.Location = new System.Drawing.Point(12, 90);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(115, 27);
this.label3.TabIndex = 6;
this.label3.Text = "设备2端口: ";
this.label3.Size = new System.Drawing.Size(137, 27);
this.label3.TabIndex = 7;
this.label3.Text = "设置单重上限:";
//
// txtSetSingleUpperLimit
//
// txtWeightComName2
this.txtSetSingleUpperLimit.Location = new System.Drawing.Point(157, 90);
this.txtSetSingleUpperLimit.Name = "txtSetSingleUpperLimit";
this.txtSetSingleUpperLimit.Size = new System.Drawing.Size(235, 34);
this.txtSetSingleUpperLimit.TabIndex = 8;
//
this.txtWeightComName2.Location = new System.Drawing.Point(126, 133);
this.txtWeightComName2.Name = "txtWeightComName2";
this.txtWeightComName2.Size = new System.Drawing.Size(235, 34);
this.txtWeightComName2.TabIndex = 3;
// txtSetAdjustmentUpperLimit
//
this.txtSetAdjustmentUpperLimit.Location = new System.Drawing.Point(157, 128);
this.txtSetAdjustmentUpperLimit.Name = "txtSetAdjustmentUpperLimit";
this.txtSetAdjustmentUpperLimit.Size = new System.Drawing.Size(235, 34);
this.txtSetAdjustmentUpperLimit.TabIndex = 10;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 136);
this.label4.Location = new System.Drawing.Point(12, 128);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(115, 27);
this.label4.TabIndex = 8;
this.label4.Text = "设备3端口: ";
this.label4.Size = new System.Drawing.Size(152, 27);
this.label4.TabIndex = 9;
this.label4.Text = "设置调整上限:";
//
// txtWeightComName3
// txtSetStandardWeight
//
this.txtWeightComName3.Location = new System.Drawing.Point(126, 173);
this.txtWeightComName3.Name = "txtWeightComName3";
this.txtWeightComName3.Size = new System.Drawing.Size(235, 34);
this.txtWeightComName3.TabIndex = 4;
this.txtSetStandardWeight.Location = new System.Drawing.Point(157, 167);
this.txtSetStandardWeight.Name = "txtSetStandardWeight";
this.txtSetStandardWeight.Size = new System.Drawing.Size(235, 34);
this.txtSetStandardWeight.TabIndex = 12;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 176);
this.label5.Location = new System.Drawing.Point(12, 167);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(115, 27);
this.label5.TabIndex = 10;
this.label5.Text = "设备4端口: ";
//
// chbEnable0
//
this.chbEnable0.AutoSize = true;
this.chbEnable0.Location = new System.Drawing.Point(367, 56);
this.chbEnable0.Name = "chbEnable0";
this.chbEnable0.Size = new System.Drawing.Size(71, 31);
this.chbEnable0.TabIndex = 11;
this.chbEnable0.Text = "启用";
this.chbEnable0.UseVisualStyleBackColor = true;
//
// chbEnable1
//
this.chbEnable1.AutoSize = true;
this.chbEnable1.Location = new System.Drawing.Point(367, 96);
this.chbEnable1.Name = "chbEnable1";
this.chbEnable1.Size = new System.Drawing.Size(71, 31);
this.chbEnable1.TabIndex = 12;
this.chbEnable1.Text = "启用";
this.chbEnable1.UseVisualStyleBackColor = true;
//
// chbEnable2
//
this.chbEnable2.AutoSize = true;
this.chbEnable2.Location = new System.Drawing.Point(367, 136);
this.chbEnable2.Name = "chbEnable2";
this.chbEnable2.Size = new System.Drawing.Size(71, 31);
this.chbEnable2.TabIndex = 13;
this.chbEnable2.Text = "启用";
this.chbEnable2.UseVisualStyleBackColor = true;
//
// chbEnable3
//
this.chbEnable3.AutoSize = true;
this.chbEnable3.Location = new System.Drawing.Point(367, 176);
this.chbEnable3.Name = "chbEnable3";
this.chbEnable3.Size = new System.Drawing.Size(71, 31);
this.chbEnable3.TabIndex = 14;
this.chbEnable3.Text = "启用";
this.chbEnable3.UseVisualStyleBackColor = true;
this.label5.Size = new System.Drawing.Size(137, 27);
this.label5.TabIndex = 11;
this.label5.Text = "设置标准重量:";
//
// txtSetAdjustmentLowerLimit
//
this.txtSetAdjustmentLowerLimit.Location = new System.Drawing.Point(157, 207);
this.txtSetAdjustmentLowerLimit.Name = "txtSetAdjustmentLowerLimit";
this.txtSetAdjustmentLowerLimit.Size = new System.Drawing.Size(235, 34);
this.txtSetAdjustmentLowerLimit.TabIndex = 14;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(12, 207);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(137, 27);
this.label6.TabIndex = 13;
this.label6.Text = "设置调整下限:";
//
// txtSetSingleLowerLimit
//
this.txtSetSingleLowerLimit.Location = new System.Drawing.Point(157, 247);
this.txtSetSingleLowerLimit.Name = "txtSetSingleLowerLimit";
this.txtSetSingleLowerLimit.Size = new System.Drawing.Size(235, 34);
this.txtSetSingleLowerLimit.TabIndex = 16;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(12, 247);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(137, 27);
this.label7.TabIndex = 15;
this.label7.Text = "设置单重下限:";
//
// frmWeightPort
//
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 27F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.ClientSize = new System.Drawing.Size(447, 287);
this.Controls.Add(this.chbEnable3);
this.Controls.Add(this.chbEnable2);
this.Controls.Add(this.chbEnable1);
this.Controls.Add(this.chbEnable0);
this.Controls.Add(this.txtWeightComName3);
this.ClientSize = new System.Drawing.Size(428, 367);
this.Controls.Add(this.txtSetSingleLowerLimit);
this.Controls.Add(this.label7);
this.Controls.Add(this.txtSetAdjustmentLowerLimit);
this.Controls.Add(this.label6);
this.Controls.Add(this.txtSetStandardWeight);
this.Controls.Add(this.label5);
this.Controls.Add(this.txtWeightComName2);
this.Controls.Add(this.txtSetAdjustmentUpperLimit);
this.Controls.Add(this.label4);
this.Controls.Add(this.txtWeightComName1);
this.Controls.Add(this.txtSetSingleUpperLimit);
this.Controls.Add(this.label3);
this.Controls.Add(this.cbbps);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.txtWeightComName0);
this.Controls.Add(this.txtWeightComName);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
@ -230,20 +222,20 @@
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtWeightComName0;
private System.Windows.Forms.TextBox txtWeightComName;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.ComboBox cbbps;
private System.Windows.Forms.TextBox txtWeightComName1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtWeightComName2;
private System.Windows.Forms.TextBox txtSetSingleUpperLimit;
private System.Windows.Forms.TextBox txtSetAdjustmentUpperLimit;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtWeightComName3;
private System.Windows.Forms.TextBox txtSetStandardWeight;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.CheckBox chbEnable0;
private System.Windows.Forms.CheckBox chbEnable1;
private System.Windows.Forms.CheckBox chbEnable2;
private System.Windows.Forms.CheckBox chbEnable3;
private System.Windows.Forms.TextBox txtSetAdjustmentLowerLimit;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox txtSetSingleLowerLimit;
private System.Windows.Forms.Label label7;
}
}

@ -16,10 +16,6 @@ namespace ZWGXPICK_SYS
public frmWeightPort()
{
InitializeComponent();
chbEnable0.CheckedChanged += ChbEnable_CheckedChanged;
chbEnable1.CheckedChanged += ChbEnable_CheckedChanged;
chbEnable2.CheckedChanged += ChbEnable_CheckedChanged;
chbEnable3.CheckedChanged += ChbEnable_CheckedChanged;
}
private void FrmAndroidIP_Load(object sender, EventArgs e)
@ -27,35 +23,20 @@ namespace ZWGXPICK_SYS
ChbEnable_CheckedChanged();
IniFile ini = new IniFile(PubConstant.config_file);
string bps = ini.ReadString("weight_RS232", "baud");
bool comEnable0 = ini.ReadBool("weight_RS232", "comEnable0", true);
bool comEnable1 = ini.ReadBool("weight_RS232", "comEnable1", true);
bool comEnable2 = ini.ReadBool("weight_RS232", "comEnable2", true);
bool comEnable3 = ini.ReadBool("weight_RS232", "comEnable3", true);
string comName0 = ini.ReadString("weight_RS232", "comName0");
string comName1 = ini.ReadString("weight_RS232", "comName1");
string comName2 = ini.ReadString("weight_RS232", "comName2");
string comName3 = ini.ReadString("weight_RS232", "comName3");
this.cbbps.Text = bps;
chbEnable0.Checked = comEnable0;
chbEnable1.Checked = comEnable1;
chbEnable2.Checked = comEnable2;
chbEnable3.Checked = comEnable3;
this.txtWeightComName0.Text = comName0;
this.txtWeightComName1.Text = comName1;
this.txtWeightComName2.Text = comName2;
this.txtWeightComName3.Text = comName3;
this.cbbps.Text = ini.ReadString("weight_RS232", "baud");
this.txtWeightComName.Text = ini.ReadString("weight_RS232", "comName");
this.txtSetSingleUpperLimit.Text = ini.ReadString("weight_RS232", "setSingleUpperLimit");
this.txtSetAdjustmentUpperLimit.Text = ini.ReadString("weight_RS232", "setAdjustmentUpperLimit");
this.txtSetStandardWeight.Text = ini.ReadString("weight_RS232", "setStandardWeight");
this.txtSetAdjustmentLowerLimit.Text = ini.ReadString("weight_RS232", "setAdjustmentLowerLimit");
this.txtSetSingleLowerLimit.Text = ini.ReadString("weight_RS232", "setSingleLowerLimit");
this.CenterToParent();
}
private void ChbEnable_CheckedChanged(object sender = null, EventArgs e = null)
{
txtWeightComName0.Enabled = chbEnable0.Checked;
txtWeightComName1.Enabled = chbEnable1.Checked;
txtWeightComName2.Enabled = chbEnable2.Checked;
txtWeightComName3.Enabled = chbEnable3.Checked;
}
private void btnCancel_Click(object sender, EventArgs e)
@ -65,38 +46,52 @@ namespace ZWGXPICK_SYS
private void btnOK_Click(object sender, EventArgs e)
{
string bps = cbbps.Text;
bool comEnable0 = chbEnable0.Checked;
bool comEnable1 = chbEnable1.Checked;
bool comEnable2 = chbEnable2.Checked;
bool comEnable3 = chbEnable3.Checked;
string comName0 = txtWeightComName0.Text;
string comName1 = txtWeightComName1.Text;
string comName2 = txtWeightComName2.Text;
string comName3 = txtWeightComName3.Text;
if (string.IsNullOrEmpty(bps) ||
(comEnable0 && string.IsNullOrEmpty(comName0)) ||
(comEnable1 && string.IsNullOrEmpty(comName1)) ||
(comEnable2 && string.IsNullOrEmpty(comName2)) ||
(comEnable3 && string.IsNullOrEmpty(comName3)))
if (string.IsNullOrEmpty(this.cbbps.Text.Trim()) || !int.TryParse(this.cbbps.Text.Trim(),out var cbbps) && cbbps>0)
{
MessageBox.Show("【波特率】配置不正确,请输入正确的配置信息!");
return;
}
if (string.IsNullOrEmpty(this.txtWeightComName.Text.Trim()))
{
MessageBox.Show("【设备端口】配置不正确,请输入正确的配置信息!");
return;
}
if (string.IsNullOrEmpty(this.txtSetSingleUpperLimit.Text.Trim()) || !decimal.TryParse(this.txtSetSingleUpperLimit.Text.Trim(), out var setSingleUpperLimit))
{
MessageBox.Show("对不起,称重设备配置不正确,请输入正确的配置信息!");
MessageBox.Show("【设置单重上限】配置不正确,请输入正确的配置信息!");
return;
}
if (string.IsNullOrEmpty(this.txtSetAdjustmentUpperLimit.Text.Trim()) || !decimal.TryParse(this.txtSetAdjustmentUpperLimit.Text.Trim(), out var setAdjustmentUpperLimit))
{
MessageBox.Show("【设置调整上限】配置不正确,请输入正确的配置信息!");
return;
}
if (string.IsNullOrEmpty(this.txtSetStandardWeight.Text.Trim()) || !decimal.TryParse(this.txtSetStandardWeight.Text.Trim(), out var setStandardWeight))
{
MessageBox.Show("【设置标准重量】配置不正确,请输入正确的配置信息!");
return;
}
if (string.IsNullOrEmpty(this.txtSetAdjustmentLowerLimit.Text.Trim()) || !decimal.TryParse(this.txtSetAdjustmentLowerLimit.Text.Trim(), out var setAdjustmentLowerLimit))
{
MessageBox.Show("【设置调整下限】配置不正确,请输入正确的配置信息!");
return;
}
if (string.IsNullOrEmpty(this.txtSetSingleLowerLimit.Text.Trim()) || !decimal.TryParse(this.txtSetSingleLowerLimit.Text.Trim(), out var setSingleLowerLimit))
{
MessageBox.Show("【设置单重下限】配置不正确,请输入正确的配置信息!");
return;
}
// try to initialize the content value item data.
IniFile ini = new IniFile(PubConstant.config_file);
ini.WriteString("weight_RS232", "baud", bps);
ini.WriteBool("weight_RS232", "comEnable0", comEnable0);
ini.WriteBool("weight_RS232", "comEnable1", comEnable1);
ini.WriteBool("weight_RS232", "comEnable2", comEnable2);
ini.WriteBool("weight_RS232", "comEnable3", comEnable3);
ini.WriteString("weight_RS232", "comName0", comName0);
ini.WriteString("weight_RS232", "comName1", comName1);
ini.WriteString("weight_RS232", "comName2", comName2);
ini.WriteString("weight_RS232", "comName3", comName3);
ini.WriteString("weight_RS232", "baud", this.cbbps.Text.Trim());
ini.WriteString("weight_RS232", "comName", this.txtWeightComName.Text.Trim());
ini.WriteString("weight_RS232", "setSingleUpperLimit", this.txtSetSingleUpperLimit.Text.Trim());
ini.WriteString("weight_RS232", "setAdjustmentUpperLimit", this.txtSetAdjustmentUpperLimit.Text.Trim());
ini.WriteString("weight_RS232", "setStandardWeight", this.txtSetStandardWeight.Text.Trim());
ini.WriteString("weight_RS232", "setAdjustmentLowerLimit", this.txtSetAdjustmentLowerLimit.Text.Trim());
ini.WriteString("weight_RS232", "setSingleLowerLimit", this.txtSetSingleLowerLimit.Text.Trim());
this.Close();
}
}

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="RICADO.MettlerToledo" version="1.1.0" targetFramework="net48" />
<package id="RICADO.Sockets" version="1.3.0" targetFramework="net48" />
</packages>
Loading…
Cancel
Save