Skip to content

Commit 01c357a

Browse files
committed
Fixes and new project: S7ProjectBlockComparer
1 parent 5fe7e49 commit 01c357a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6963
-2410
lines changed

DotNetSiemensPLCToolBoxLibrary.sln

+17
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackupRestoreBlocks", "Back
6262
EndProject
6363
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleTcpSocket", "SimpleTcpSocket\SimpleTcpSocket.csproj", "{9D996B90-0FA0-441F-A175-1D7A4F2B0762}"
6464
EndProject
65+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "S7ProjectBlockComparer", "S7ProjectBlockComparer\S7ProjectBlockComparer.csproj", "{FBABACF1-5406-4A50-983A-9C6D4B923DFD}"
66+
EndProject
6567
Global
6668
GlobalSection(TestCaseManagementSettings) = postSolution
6769
CategoryFile = DotNetSiemensPLCToolBoxLibrary.vsmdi
@@ -385,6 +387,20 @@ Global
385387
{9D996B90-0FA0-441F-A175-1D7A4F2B0762}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
386388
{9D996B90-0FA0-441F-A175-1D7A4F2B0762}.Release|Mixed Platforms.Build.0 = Release|Any CPU
387389
{9D996B90-0FA0-441F-A175-1D7A4F2B0762}.Release|x86.ActiveCfg = Release|Any CPU
390+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
391+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
392+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Debug|iPhone.ActiveCfg = Debug|Any CPU
393+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
394+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
395+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
396+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Debug|x86.ActiveCfg = Debug|Any CPU
397+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
398+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Release|Any CPU.Build.0 = Release|Any CPU
399+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Release|iPhone.ActiveCfg = Release|Any CPU
400+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
401+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
402+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
403+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD}.Release|x86.ActiveCfg = Release|Any CPU
388404
EndGlobalSection
389405
GlobalSection(SolutionProperties) = preSolution
390406
HideSolutionNode = FALSE
@@ -405,6 +421,7 @@ Global
405421
{E75E7D80-4464-4308-ACE6-076D2AA49EF4} = {A4F11331-531B-4A7C-84B2-E319658AE2B8}
406422
{6622399F-2746-4F63-BAFF-F30230168813} = {A4F11331-531B-4A7C-84B2-E319658AE2B8}
407423
{9D996B90-0FA0-441F-A175-1D7A4F2B0762} = {A4F11331-531B-4A7C-84B2-E319658AE2B8}
424+
{FBABACF1-5406-4A50-983A-9C6D4B923DFD} = {A4F11331-531B-4A7C-84B2-E319658AE2B8}
408425
{EADA891B-F378-4243-B031-9E65667377A2} = {1B6DEB93-FB30-4585-BE77-A8444D86179C}
409426
{3DC74553-0988-4364-8F7D-D13B8FBB16D9} = {1B6DEB93-FB30-4585-BE77-A8444D86179C}
410427
{84E1F59D-29A6-4E1D-A3A8-35CD92B54488} = {1B6DEB93-FB30-4585-BE77-A8444D86179C}

LibNoDaveConnectionLibrary/Communication/PLCConnection.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ You should have received a copy of the GNU Library General Public License
2929
using System.ComponentModel;
3030
using System.Diagnostics;
3131
using System.Net;
32+
using System.Net.Sockets;
3233
using System.Threading;
3334
using System.Timers;
3435
using DotNetSiemensPLCToolBoxLibrary.Communication.LibNoDave;
@@ -163,6 +164,9 @@ public void socket_Thread()
163164
catch (Exception)
164165
{ }
165166

167+
//TcpClient sock = new TcpClient(ip, _configuration.Port);
168+
//_fds.rfd = sock.Client.Handle;
169+
166170
if (ip != null)
167171
_fds.rfd = libnodave.openSocket(_configuration.Port, ip);
168172
else
@@ -177,7 +181,7 @@ public void Connect()
177181
_NeedDispose = true;
178182
//Debugging for LibNoDave
179183
libnodave.daveSetDebug(0x0);
180-
libnodave.daveSetDebug(0x1ffff);
184+
//libnodave.daveSetDebug(0x1ffff);
181185

182186
//_configuration.ReloadConfiguration();
183187

LibNoDaveConnectionLibrary/Communication/PLCTag.cs

+59-8
Original file line numberDiff line numberDiff line change
@@ -549,18 +549,32 @@ public void ParseControlValueFromString(string myValue)
549549
case TagDataType.S5Time:
550550
case TagDataType.Time:
551551
if (myValueStrip.Contains("t#") || myValueStrip.Contains("s5t#"))
552+
{
552553
Controlvalue = Helper.GetTimespanFromS5TimeorTime(myValue);
554+
}
553555
else
554-
try { Controlvalue = TimeSpan.Parse(myValue); } catch (Exception) {}
556+
{
557+
TimeSpan ret;
558+
TimeSpan.TryParse(myValue, out ret);
559+
Controlvalue = ret;
560+
}
555561
break;
556562
case TagDataType.BCDWord:
557563
case TagDataType.Int:
558564
if (myValueStrip.Contains("w#16#") || myValueStrip.Contains("dw#16#"))
565+
{
559566
Controlvalue = Convert.ToInt16(Helper.GetIntFromHexString(myValue));
567+
}
560568
else if (myValue.StartsWith("2#"))
569+
{
561570
Controlvalue = Convert.ToInt16(Helper.GetIntFromBinString(myValue));
571+
}
562572
else
563-
try { Controlvalue = Int16.Parse(myValue); } catch (Exception) {}
573+
{
574+
Int16 ret;
575+
Int16.TryParse(myValue, out ret);
576+
Controlvalue = ret;
577+
}
564578
break;
565579
case TagDataType.BCDDWord:
566580
case TagDataType.Dint:
@@ -569,40 +583,76 @@ public void ParseControlValueFromString(string myValue)
569583
else if (myValue.StartsWith("2#"))
570584
Controlvalue = Convert.ToInt32(Helper.GetIntFromBinString(myValue));
571585
else
572-
try { Controlvalue = Int32.Parse(myValue); } catch (Exception) {}
586+
try
587+
{
588+
if (!string.IsNullOrEmpty(myValue))
589+
Controlvalue = Int32.Parse(myValue);
590+
} catch (Exception) {}
573591
break;
574592
case TagDataType.Byte:
575593
if (myValueStrip.Contains("w#16#") || myValueStrip.Contains("dw#16#"))
594+
{
576595
Controlvalue = Convert.ToByte(Helper.GetIntFromHexString(myValue));
596+
}
577597
else if (myValue.StartsWith("2#"))
598+
{
578599
Controlvalue = Convert.ToByte(Helper.GetIntFromBinString(myValue));
600+
}
579601
else
580-
try { Controlvalue = Byte.Parse(myValue); } catch (Exception) {}
602+
{
603+
Byte ret;
604+
Byte.TryParse(myValue, out ret);
605+
Controlvalue = ret;
606+
}
581607
break;
582608
case TagDataType.BCDByte:
583609
case TagDataType.SByte:
584610
if (myValueStrip.Contains("w#16#") || myValueStrip.Contains("dw#16#"))
611+
{
585612
Controlvalue = Convert.ToSByte(Helper.GetIntFromHexString(myValue));
613+
}
586614
else if (myValue.StartsWith("2#"))
615+
{
587616
Controlvalue = Convert.ToSByte(Helper.GetIntFromBinString(myValue));
617+
}
588618
else
589-
try { Controlvalue = SByte.Parse(myValue); } catch (Exception) {}
619+
{
620+
SByte ret;
621+
SByte.TryParse(myValue, out ret);
622+
Controlvalue = ret;
623+
}
590624
break;
591625
case TagDataType.Word:
592626
if (myValueStrip.Contains("w#16#") || myValueStrip.Contains("dw#16#"))
627+
{
593628
Controlvalue = Convert.ToUInt16(Helper.GetIntFromHexString(myValue));
629+
}
594630
else if (myValue.StartsWith("2#"))
631+
{
595632
Controlvalue = Convert.ToUInt16(Helper.GetIntFromBinString(myValue));
633+
}
596634
else
597-
try { Controlvalue = UInt16.Parse(myValue); } catch (Exception) {}
635+
{
636+
UInt16 ret;
637+
UInt16.TryParse(myValue, out ret);
638+
Controlvalue = ret;
639+
}
598640
break;
599641
case TagDataType.Dword:
600642
if (myValueStrip.Contains("w#16#") || myValueStrip.Contains("dw#16#"))
643+
{
601644
Controlvalue = Convert.ToUInt32(Helper.GetIntFromHexString(myValue));
645+
}
602646
else if (myValue.StartsWith("2#"))
647+
{
603648
Controlvalue = Convert.ToUInt32(Helper.GetIntFromBinString(myValue));
649+
}
604650
else
605-
try { Controlvalue = UInt32.Parse(myValue); } catch (Exception) { }
651+
{
652+
UInt32 ret;
653+
UInt32.TryParse(myValue, out ret);
654+
Controlvalue = ret;
655+
}
606656
break;
607657
case TagDataType.Bool:
608658
if (myValue=="1")
@@ -632,7 +682,8 @@ public void ParseControlValueFromString(string myValue)
632682
else if (!string.IsNullOrEmpty(myValue))
633683
try
634684
{
635-
Controlvalue = DateTime.Parse(myValue);
685+
if (!string.IsNullOrEmpty(myValue))
686+
Controlvalue = DateTime.Parse(myValue);
636687
}
637688
catch (Exception) { }
638689
break;

LibNoDaveConnectionLibrary/DataTypes/Blocks/Step7V5/S7FunctionBlockRow.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,13 @@ public string ToString(bool useSymbol, bool addSemicolonAfterCommand, bool useDa
679679
if (paras.Length > 2) bitAdr = int.Parse(paras[2]);
680680

681681
var dbBlk = fld.GetBlock(paras[0]) as S7DataBlock;
682-
var row = dbBlk.GetDataRowWithAddress(new ByteBitAddress(byteAdr, bitAdr));
683-
if (row != null)
682+
if (dbBlk != null)
684683
{
685-
if (sym != null)
686-
par = "\"" + sym.Symbol + "\"." + row.StructuredName;
684+
var row = dbBlk.GetDataRowWithAddress(new ByteBitAddress(byteAdr, bitAdr));
685+
if (row != null)
686+
{
687+
if (sym != null) par = "\"" + sym.Symbol + "\"." + row.StructuredName;
688+
}
687689
}
688690
}
689691
}

LibNoDaveConnectionLibrary/Projectfiles/SelectProjectPart.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ namespace DotNetSiemensPLCToolBoxLibrary.Projectfiles
99
{
1010
public static class SelectProjectPart
1111
{
12-
public static Step7ProjectFolder SelectBlocksOfflineFolder()
12+
public static BlocksOfflineFolder SelectBlocksOfflineFolder()
1313
{
1414
return SelectBlocksOfflineFolder("");
1515
}
1616

17-
public static Step7ProjectFolder SelectBlocksOfflineFolder(string FileAndProjectInternalFolder)
17+
public static BlocksOfflineFolder SelectBlocksOfflineFolder(string FileAndProjectInternalFolder)
1818
{
1919
SelectProjectPartForm myFrm = new SelectProjectPartForm(FileAndProjectInternalFolder);
2020
myFrm.SelectPart = SelectPartType.BlocksOfflineFolder;
2121
myFrm.ShowDialog();
22-
return (Step7ProjectFolder)myFrm.retVal;
22+
return (BlocksOfflineFolder)myFrm.retVal;
2323
}
2424

2525
public static S7ProgrammFolder SelectS7ProgrammFolder()

S7ProjectBlockComparer/App.xaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="S7ProjectBlockComparer.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
StartupUri="MainWindow.xaml">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>

S7ProjectBlockComparer/App.xaml.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Windows;
7+
8+
namespace S7ProjectBlockComparer
9+
{
10+
/// <summary>
11+
/// Interaction logic for App.xaml
12+
/// </summary>
13+
public partial class App : Application
14+
{
15+
}
16+
}

0 commit comments

Comments
 (0)