|
|
@@ -430,6 +430,7 @@ namespace UAS_PLCDataReader
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ Dictionary<string, ModBusTCPClient> client = new Dictionary<string, ModBusTCPClient>();
|
|
|
/// <summary>
|
|
|
/// 轮询执行的业务
|
|
|
/// </summary>
|
|
|
@@ -442,6 +443,7 @@ namespace UAS_PLCDataReader
|
|
|
DataHelper dh = pl.Dh;
|
|
|
string Decode = pl.DeviceCode;
|
|
|
string Dccode = pl.CommandCode;
|
|
|
+ string DpcID = pl.Id.ToString();
|
|
|
DataTable dt = (DataTable)dh.ExecuteSql("select dnc_ip,dnc_port from DEVICENETCONFIG where dnc_decode='" + Decode + "'", "select");
|
|
|
DataTable dt1 = (DataTable)dh.ExecuteSql("select dc_sendcoding,dc_value,dc_receivecoding from devicecommand where dc_code='" + Dccode + "'", "select");
|
|
|
if (dt.Rows.Count > 0)
|
|
|
@@ -458,8 +460,17 @@ namespace UAS_PLCDataReader
|
|
|
Command = dt1.Rows[0]["dc_value"].ToString();
|
|
|
SendCommandByteSize = Encoding.Default.GetBytes(Command.ToCharArray()).Length;
|
|
|
}
|
|
|
+ if (client.ContainsKey(DpcID))
|
|
|
+ {
|
|
|
+ client[DpcID].Send(Command);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ModBusTCPClient modclient = new ModBusTCPClient(dt.Rows[0]["dnc_ip"].ToString(), int.Parse(dt.Rows[0]["dnc_port"].ToString()));
|
|
|
+ client.Add(DpcID, modclient);
|
|
|
+ }
|
|
|
//发送指令
|
|
|
- mbt.Send(IP, SendCoding, ReceiveCoding, Command);
|
|
|
+ //mbt.Send(IP, SendCoding, ReceiveCoding, Command);
|
|
|
//如果不包含该项数据则在键值对中添加
|
|
|
if (!ReturnData.ContainsKey(Decode))
|
|
|
{
|
|
|
@@ -482,12 +493,12 @@ namespace UAS_PLCDataReader
|
|
|
//检测键值对是否发生变化,发生变化时赋予新值
|
|
|
}
|
|
|
//成功返回了信息
|
|
|
- if (mbt.Returnvalue.ContainsKey(IP))
|
|
|
+ if (client[DpcID].Returnvalue.ContainsKey(IP))
|
|
|
{
|
|
|
- int ReceiveCommandByteSize = Encoding.Default.GetBytes(mbt.Returnvalue[IP].ToCharArray()).Length;
|
|
|
+ int ReceiveCommandByteSize = Encoding.Default.GetBytes(client[DpcID].Returnvalue[IP].ToCharArray()).Length;
|
|
|
//存放返回的所有数据
|
|
|
Dictionary<string, string> ItemData = new Dictionary<string, string>();
|
|
|
- int[] Arr = BaseUtil.GetDecimalData(BaseUtil.ASCIIToString(mbt.Returnvalue[IP]), 8);
|
|
|
+ int[] Arr = BaseUtil.GetDecimalData(BaseUtil.ASCIIToString(client[DpcID].Returnvalue[IP]), 8);
|
|
|
for (int i = 0; i < Arr.Length; i++)
|
|
|
{
|
|
|
ItemData.Add("Item" + i, Arr[i].ToString());
|
|
|
@@ -521,7 +532,7 @@ namespace UAS_PLCDataReader
|
|
|
LogicHandler.DoDeviceDataDiffLog(pl.DeviceCode, pl.DeviceName, pl.CommandCode, User.UserName);
|
|
|
}
|
|
|
}
|
|
|
- mbt.Returnvalue.Remove(IP);
|
|
|
+ client[DpcID].Returnvalue.Remove(IP);
|
|
|
//SQL.Clear();
|
|
|
////更新轮询状态
|
|
|
//sql.Clear();
|
|
|
@@ -564,6 +575,7 @@ namespace UAS_PLCDataReader
|
|
|
}
|
|
|
PollSettingPaintRowIndex.Clear();
|
|
|
GridPollingSetting.Focus();
|
|
|
+ client.Clear();
|
|
|
Ptime.Clear();
|
|
|
}
|
|
|
|
|
|
@@ -574,22 +586,14 @@ namespace UAS_PLCDataReader
|
|
|
GridViewPollSetting.SetRowCellValue(e.RowHandle, e.Column, e.Value);
|
|
|
if (GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ENABLE").ToString() == "0")
|
|
|
{
|
|
|
- //DialogResult cancel = XtraMessageBox.Show("确认禁用该轮询?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
|
- //if (cancel.ToString() == "Yes")
|
|
|
- //{
|
|
|
int id = int.Parse(GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ID").ToString());
|
|
|
if (Ptime.ContainsKey(id))
|
|
|
{
|
|
|
Ptime[id].Stop();
|
|
|
Ptime.Remove(id);
|
|
|
+ client.Remove(id.ToString());
|
|
|
PollSettingPaintRowIndex.Remove(e.RowHandle);
|
|
|
}
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // Cancel = false;
|
|
|
- // GridViewPollSetting.SetRowCellValue(e.RowHandle, e.Column, -1);
|
|
|
- //}
|
|
|
}
|
|
|
else
|
|
|
{
|