Skip to content

Commit

Permalink
驱动更新
Browse files Browse the repository at this point in the history
  • Loading branch information
18298001496 committed Aug 18, 2022
1 parent 5c65256 commit 1d9473a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
13 changes: 3 additions & 10 deletions src/IOTCS.EdgeGateway.Plugins/ModbusDriver/ModbusTcpDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,7 @@ public string Run(string deviceID, string groupID)
{
List<DataNodeDto> list = new List<DataNodeDto>();
var locations = _dataLocations.Where(w => w.ParentId == groupID);
var cts = new CancellationTokenSource();
Parallel.ForEach(locations, new ParallelOptions
{
CancellationToken = cts.Token,
MaxDegreeOfParallelism = Environment.ProcessorCount,
TaskScheduler = TaskScheduler.Default
},
(d, state) =>
foreach (var d in locations)
{
byte station = 1;
string address = string.Empty;
Expand All @@ -114,7 +107,7 @@ public string Run(string deviceID, string groupID)
case "string":
_busTcpClient.Station = station;
var sResult = _busTcpClient.ReadString(address, Convert.ToUInt16(d.NodeLength));
DataNodeDto stringNode = new DataNodeDto
DataNodeDto stringNode = new DataNodeDto
{
FieldName = d.DisplayName,
NodeId = d.NodeAddress,
Expand Down Expand Up @@ -196,7 +189,7 @@ public string Run(string deviceID, string groupID)
list.Add(floatNode);
break;
}
});
}

result = JsonConvert.SerializeObject(list);
list.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,8 @@ public string Run(string deviceID, string groupID)
{
List<DataNodeDto> list = new List<DataNodeDto>();
var locations = _dataLocations.Where(w => w.ParentId == groupID);
var cts = new CancellationTokenSource();
Parallel.ForEach(locations, new ParallelOptions
foreach (var d in locations)
{
CancellationToken = cts.Token,
MaxDegreeOfParallelism = Environment.ProcessorCount,
TaskScheduler = TaskScheduler.Default
},
(d, state) =>
{
//并行读取所有数据
switch (d.NodeType)
{
case "string":
Expand Down Expand Up @@ -181,7 +173,7 @@ public string Run(string deviceID, string groupID)
list.Add(floatNode);
break;
}
});
}

result = JsonConvert.SerializeObject(list);
list.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,8 @@ public string Run(string deviceID, string groupID)
{
List<DataNodeDto> list = new List<DataNodeDto>();
var locations = _dataLocations.Where(w => w.ParentId == deviceID);
var cts = new CancellationTokenSource();
Parallel.ForEach(locations, new ParallelOptions
foreach (var d in locations)
{
CancellationToken = cts.Token,
MaxDegreeOfParallelism = Environment.ProcessorCount,
TaskScheduler = TaskScheduler.Default
},
(d, state) =>
{
//并行读取所有数据
switch (d.NodeType)
{
case "string":
Expand Down Expand Up @@ -180,7 +172,7 @@ public string Run(string deviceID, string groupID)
list.Add(floatNode);
break;
}
});
}

result = JsonConvert.SerializeObject(list);
list.Clear();
Expand Down

0 comments on commit 1d9473a

Please sign in to comment.