|
|
@ -32,6 +32,8 @@ namespace PunchAndWeld |
|
|
|
private string oneBarCode = "", stationNo ="", stationId = ""; |
|
|
|
private DataTable _collectParamTable = new DataTable(); |
|
|
|
|
|
|
|
private DataRow _plcReceiveDr = null; |
|
|
|
|
|
|
|
public FrmProScreenBumperS() |
|
|
|
{ |
|
|
|
InitializeComponent(); |
|
|
@ -48,6 +50,9 @@ namespace PunchAndWeld |
|
|
|
Thread t = new Thread(new ThreadStart(TimeGo)); |
|
|
|
t.Start(); |
|
|
|
|
|
|
|
DataTable table = new DataTable(); |
|
|
|
_plcReceiveDr = table.NewRow(); |
|
|
|
|
|
|
|
if (stationNo != "ZP70") |
|
|
|
{ |
|
|
|
textBox1.TabIndex = 0; |
|
|
@ -87,6 +92,7 @@ namespace PunchAndWeld |
|
|
|
opcHelper.opcItems1.DefaultIsActive = true; |
|
|
|
|
|
|
|
DataTable dt = bll.SearchInfo(ConfigurationManager.AppSettings["DeviceNo"], 0);//读 0:读 1:写
|
|
|
|
|
|
|
|
_collectParamTable = bll.SearchExtendInfo(ConfigurationManager.AppSettings["StationNo"], 0); |
|
|
|
|
|
|
|
|
|
|
@ -95,10 +101,12 @@ namespace PunchAndWeld |
|
|
|
if (dt != null && dt.Rows.Count > 0) |
|
|
|
{ |
|
|
|
opcHelper.opcItemm1 = new OPCItem[dt.Rows.Count]; |
|
|
|
if (stationNo == "ZP66") |
|
|
|
|
|
|
|
if (stationNo == "ZP66" || stationNo == "ZP81") |
|
|
|
{ |
|
|
|
opcHelper.opcItemm1 = new OPCItem[dt.Rows.Count + _collectParamTable.Rows.Count]; |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++) |
|
|
|
{ |
|
|
|
opcHelper.opcItemm1[i] = opcHelper.opcItems1.AddItem(dt.Rows[i]["Address"].ToString(), i); |
|
|
@ -113,7 +121,26 @@ namespace PunchAndWeld |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(dr["Address"].ToString())) |
|
|
|
{ |
|
|
|
opcHelper.opcItemm1[k] = opcHelper.opcItems1.AddItem(dr["Address"].ToString(), k); |
|
|
|
opcHelper.opcItemm1[k] = opcHelper.opcItems1.AddItem(dr["Address"].ToString(), int.Parse( dr["Hd"].ToString())); |
|
|
|
} |
|
|
|
k++; |
|
|
|
} |
|
|
|
catch(Exception ee) |
|
|
|
{ |
|
|
|
throw ee; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (stationNo == "ZP81") |
|
|
|
{ |
|
|
|
int k = dt.Rows.Count;//延续原有参数数量
|
|
|
|
foreach (DataRow dr in _collectParamTable.Rows) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(dr["Address"].ToString())) |
|
|
|
{ |
|
|
|
opcHelper.opcItemm1[k] = opcHelper.opcItems1.AddItem(dr["Address"].ToString(), int.Parse(dr["Hd"].ToString())); |
|
|
|
} |
|
|
|
k++; |
|
|
|
} |
|
|
@ -667,6 +694,7 @@ namespace PunchAndWeld |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private string _scanBarCode = string.Empty; |
|
|
|
public void CheckPartAndProduct_New() |
|
|
|
{ |
|
|
|
textBox1.SelectAll(); |
|
|
@ -1766,10 +1794,17 @@ namespace PunchAndWeld |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
DataTable table = new DataTable(); |
|
|
|
DataRow dr = table.NewRow(); |
|
|
|
|
|
|
|
|
|
|
|
if (NumItems > 0) |
|
|
|
{ |
|
|
|
LogHelper.WriteLog(" PLC接收配置信号: " + $"opcHelper.opcItemm1.Len=" + opcHelper.opcItemm1.Count() + "_collectParamTable.Rows.Count =" + _collectParamTable.Rows.Count + " ClientHandles.Length=" + ClientHandles.Length + "ItemValues.Len=" + ItemValues.Length); |
|
|
|
} |
|
|
|
string ss = string.Empty; |
|
|
|
int j = 0; |
|
|
|
for (int i = 1; i <= NumItems; i++) |
|
|
|
{ |
|
|
|
j++; |
|
|
|
int handle = 0; |
|
|
|
string value = ""; |
|
|
|
string address = ""; |
|
|
@ -1778,11 +1813,18 @@ namespace PunchAndWeld |
|
|
|
handle = Convert.ToInt32(ClientHandles.GetValue(i).ToString().Trim()); |
|
|
|
value = ItemValues.GetValue(i).ToString(); |
|
|
|
address = opcHelper.opcItemm1[(Convert.ToInt32(ClientHandles.GetValue(i)))].ItemID; |
|
|
|
ss = "ItemID=" + address+ ";handle ="+ handle + ";value="+ value ; |
|
|
|
|
|
|
|
//LogHelper.WriteLog("读取PLC返回信息:"+ss);
|
|
|
|
//if (handle == 0 && (value == "1" || value.ToUpper() == "TRUE"))
|
|
|
|
//{
|
|
|
|
// LogHelper.WriteLog("读取PLC完成信号:handle=" + ss);
|
|
|
|
//}
|
|
|
|
|
|
|
|
} |
|
|
|
catch(Exception exx) |
|
|
|
{ |
|
|
|
|
|
|
|
LogHelper.WriteLog("读取PLC返回信息解析失败:" + exx.Message); |
|
|
|
} |
|
|
|
|
|
|
|
#region 原因功能
|
|
|
@ -1792,6 +1834,67 @@ namespace PunchAndWeld |
|
|
|
{ |
|
|
|
lbFinish.Text = "运行完成"; |
|
|
|
|
|
|
|
#region 测试 250425
|
|
|
|
//int jj = 0;
|
|
|
|
//try
|
|
|
|
//{
|
|
|
|
// int len = opcHelper.opcItemm1.Count();
|
|
|
|
// for (int j = 12; j <= len; j++)
|
|
|
|
// {
|
|
|
|
// jj = j;
|
|
|
|
// int handle2 = 0;
|
|
|
|
// string value2 = "";
|
|
|
|
// string address2 = "";
|
|
|
|
// if(ClientHandles.Length> j - 12)
|
|
|
|
// {
|
|
|
|
// handle2 = Convert.ToInt32(ClientHandles.GetValue(j - 12).ToString().Trim());
|
|
|
|
// value2 = ItemValues.GetValue(j - 12).ToString();
|
|
|
|
// address2 = opcHelper.opcItemm1[handle2].ItemID;
|
|
|
|
// foreach (DataRow collectRow in _collectParamTable.Rows)
|
|
|
|
// {
|
|
|
|
// if (collectRow["Address"].ToString() == address2 && address2.Contains("we"))
|
|
|
|
// {
|
|
|
|
// string[] args = address2.Split('.');
|
|
|
|
// if (args.Length == 3)
|
|
|
|
// {
|
|
|
|
// string columnName = args[2];
|
|
|
|
// if (dr.Table.Columns.Contains(columnName) == false)
|
|
|
|
// {
|
|
|
|
// dr.Table.Columns.Add(columnName);
|
|
|
|
// dr[columnName] = value2;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (dr.Table.Columns.Contains("DeviceCode") == false)
|
|
|
|
// {
|
|
|
|
// dr.Table.Columns.Add("DeviceCode");
|
|
|
|
// dr["DeviceCode"] = ConfigurationManager.AppSettings["DeviceNo"];
|
|
|
|
// }
|
|
|
|
// if (dr.Table.Columns.Contains("StationNo") == false)
|
|
|
|
// {
|
|
|
|
// dr.Table.Columns.Add("StationNo");
|
|
|
|
// dr["StationNo"] = ConfigurationManager.AppSettings["StationNo"];
|
|
|
|
// }
|
|
|
|
// if (dr.Table.Columns.Contains("ScreenMode") == false)
|
|
|
|
// {
|
|
|
|
// dr.Table.Columns.Add("ScreenMode");
|
|
|
|
// dr["ScreenMode"] = ConfigurationManager.AppSettings["ProScreenMode"];
|
|
|
|
// }
|
|
|
|
// bll.AddDeviceRecord(dr);
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
//catch (Exception ex)
|
|
|
|
//{
|
|
|
|
// MessageBox.Show("测试异常" + ex.Message);
|
|
|
|
//}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
@ -1844,7 +1947,6 @@ namespace PunchAndWeld |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (handle == 5) |
|
|
|
{ |
|
|
|
if (value == "1" || value.ToUpper() == "TRUE") |
|
|
@ -1859,11 +1961,6 @@ namespace PunchAndWeld |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 保存采集数据
|
|
|
|
if (NumItems > 100) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
foreach (DataRow collectRow in _collectParamTable.Rows) |
|
|
|
{ |
|
|
|
if (collectRow["Address"].ToString() == address && address.Contains("we")) |
|
|
@ -1872,49 +1969,68 @@ namespace PunchAndWeld |
|
|
|
if (args.Length == 3) |
|
|
|
{ |
|
|
|
string columnName = args[2]; |
|
|
|
if (dr.Table.Columns.Contains(columnName) == false) |
|
|
|
if (_plcReceiveDr.Table.Columns.Contains(columnName) == false) |
|
|
|
{ |
|
|
|
dr.Table.Columns.Add(columnName); |
|
|
|
dr[columnName] = value; |
|
|
|
_plcReceiveDr.Table.Columns.Add(columnName); |
|
|
|
_plcReceiveDr[columnName] = value; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
if (handle == 0 && (value == "1" || value.ToUpper() == "TRUE")) |
|
|
|
{ |
|
|
|
LogHelper.WriteLog("数据保存1 _plcReceiveDr.Columns.Count=" + _plcReceiveDr.Table.Columns.Count); |
|
|
|
j = 0; |
|
|
|
if (_plcReceiveDr.Table.Columns.Contains("DeviceCode") == false) |
|
|
|
{ |
|
|
|
_plcReceiveDr.Table.Columns.Add("DeviceCode"); |
|
|
|
_plcReceiveDr["DeviceCode"] = ConfigurationManager.AppSettings["DeviceNo"]; |
|
|
|
} |
|
|
|
catch(Exception ex) |
|
|
|
if (_plcReceiveDr.Table.Columns.Contains("StationNo") == false) |
|
|
|
{ |
|
|
|
|
|
|
|
_plcReceiveDr.Table.Columns.Add("StationNo"); |
|
|
|
_plcReceiveDr["StationNo"] = ConfigurationManager.AppSettings["StationNo"]; |
|
|
|
} |
|
|
|
if (_plcReceiveDr.Table.Columns.Contains("ScreenMode") == false) |
|
|
|
{ |
|
|
|
_plcReceiveDr.Table.Columns.Add("ScreenMode"); |
|
|
|
_plcReceiveDr["ScreenMode"] = ConfigurationManager.AppSettings["ProScreenMode"]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
if (NumItems > 100) |
|
|
|
{ |
|
|
|
if (dr.Table.Columns.Contains("DeviceCode") == false) |
|
|
|
if (_plcReceiveDr.Table.Columns.Contains("PartCode") == false) |
|
|
|
{ |
|
|
|
dr.Table.Columns.Add("DeviceCode"); |
|
|
|
dr["DeviceCode"] = ConfigurationManager.AppSettings["DeviceNo"]; |
|
|
|
_plcReceiveDr.Table.Columns.Add("PartCode"); |
|
|
|
_plcReceiveDr["PartCode"] = zcPartNo; |
|
|
|
} |
|
|
|
if (dr.Table.Columns.Contains("StationNo") == false) |
|
|
|
if (_plcReceiveDr.Table.Columns.Contains("SjBarCode") == false) |
|
|
|
{ |
|
|
|
dr.Table.Columns.Add("StationNo"); |
|
|
|
dr["StationNo"] = ConfigurationManager.AppSettings["StationNo"]; |
|
|
|
_plcReceiveDr.Table.Columns.Add("SjBarCode"); |
|
|
|
_plcReceiveDr["SjBarCode"] = oneBarCode; |
|
|
|
} |
|
|
|
if (dr.Table.Columns.Contains("ScreenMode") == false) |
|
|
|
LogHelper.WriteLog("数据保存2 _plcReceiveDr.Columns.Count=" + _plcReceiveDr.Table.Columns.Count); |
|
|
|
bll.AddDeviceRecord(_plcReceiveDr); |
|
|
|
LogHelper.WriteLog("数据保存3 _plcReceiveDr.Columns.Count=" + _plcReceiveDr.Table.Columns.Count); |
|
|
|
|
|
|
|
DataTable dtt = new DataTable(); |
|
|
|
_plcReceiveDr = dtt.NewRow(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch(Exception ee) |
|
|
|
{ |
|
|
|
dr.Table.Columns.Add("ScreenMode"); |
|
|
|
dr["ScreenMode"] = ConfigurationManager.AppSettings["ProScreenMode"]; |
|
|
|
LogHelper.WriteLog("PLC信号保存异常,原因:" + ee.Message); |
|
|
|
} |
|
|
|
bll.AddDeviceRecord(dr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
MessageBox.Show("接收数据处理时异常,异常原因:" + ex.Message); |
|
|
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); |
|
|
|
} |
|
|
|
} |
|
|
@ -2207,6 +2323,8 @@ namespace PunchAndWeld |
|
|
|
|
|
|
|
private void label10_Click(object sender, EventArgs e) |
|
|
|
{ |
|
|
|
return; |
|
|
|
|
|
|
|
if (MessageBox.Show("确认保存焊接机返回结果?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) |
|
|
|
return; |
|
|
|
|
|
|
@ -2219,6 +2337,8 @@ namespace PunchAndWeld |
|
|
|
if (collectRow["Address"].ToString().Contains("deep")) |
|
|
|
{ |
|
|
|
ItemValuesStr[i] = GetDecimalRodom().ToString(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else if (collectRow["Address"].ToString().Contains("energy")) |
|
|
|
{ |
|
|
@ -2237,18 +2357,50 @@ namespace PunchAndWeld |
|
|
|
ItemValuesStr[i] = GetIntRodom().ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
i++; |
|
|
|
if (opcHelper.opcItemm1.Length >= i + 11) |
|
|
|
{ |
|
|
|
opcHelper.opcItemm1[i + 11].Write(ItemValuesStr[i]); |
|
|
|
} |
|
|
|
// int handle = Convert.ToInt32(ClientHandles.GetValue(i).ToString().Trim());
|
|
|
|
//string value = ItemValues.GetValue(i).ToString();
|
|
|
|
//string address = opcHelper.opcItemm1[(Convert.ToInt32(ClientHandles.GetValue(i)))].ItemID;
|
|
|
|
|
|
|
|
i++; |
|
|
|
} |
|
|
|
|
|
|
|
Array ClientHandlers = ClientHandlersInt; |
|
|
|
Array ItemValues = ItemValuesStr; |
|
|
|
Array c = null; |
|
|
|
Array d = null; |
|
|
|
opcGroup1_DataChange(1, 105, ref ClientHandlers, ref ItemValues, ref c, ref d); |
|
|
|
//Array c = null;
|
|
|
|
//Array d = null;
|
|
|
|
//opcGroup1_DataChange(1, 105, ref ClientHandlers, ref ItemValues, ref c, ref d);
|
|
|
|
|
|
|
|
|
|
|
|
int[] ClientHandlersInt2 = new int[2]; |
|
|
|
ClientHandlersInt2[0] = 1; |
|
|
|
ClientHandlersInt2[1] = 0; |
|
|
|
string[] ItemValuesStr2 = new string[2]; |
|
|
|
ItemValuesStr2[0] = "1"; |
|
|
|
ItemValuesStr2[1] = "1"; |
|
|
|
|
|
|
|
|
|
|
|
Array c2 = null; |
|
|
|
Array d2 = null; |
|
|
|
ClientHandlersInt[0] = 1; |
|
|
|
ClientHandlersInt[1] = 0; |
|
|
|
ItemValuesStr[0] = "1"; |
|
|
|
ItemValuesStr[1] = "1"; |
|
|
|
Array ClientHandlers2 = ClientHandlersInt; |
|
|
|
Array ItemValues2 = ItemValuesStr; |
|
|
|
|
|
|
|
opcGroup1_DataChange(1, 1, ref ClientHandlers2, ref ItemValues2, ref c2, ref d2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (handle == 0)
|
|
|
|
//{
|
|
|
|
// if (value == "1" || value.ToUpper() == "TRUE")
|
|
|
|
// {
|
|
|
|
// lbFinish.Text = "运行完成";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新说明 1:创建表tb_PunchDevice_Records用于记录设备输出结果
|
|
|
|
//2:创建 tb_PunchAddressExtend存储设备参数. 和 和原有配置表tb_PunchAddress共同起作用
|
|
|
|