Skip to content

Instantly share code, notes, and snippets.

@mycroes
Last active March 12, 2020 06:22
Show Gist options
  • Save mycroes/9bdc7cffdef08943edea1918812706a6 to your computer and use it in GitHub Desktop.
Save mycroes/9bdc7cffdef08943edea1918812706a6 to your computer and use it in GitHub Desktop.
Sample S7NetPlus application
bin
obj/
.vs/
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using S7.Net;
using S7.Net.Types;
namespace S7NetPlus.Sample
{
class Program
{
static async Task Main()
{
const string ip = "192.168.1.10";
var dataItems = new List<DataItem>
{
new DataItem {DataType = DataType.DataBlock, DB = 200, StartByteAdr = 4, VarType = VarType.Int},
new DataItem {DataType = DataType.DataBlock, DB = 200, StartByteAdr = 6, VarType = VarType.Int}
};
try
{
var plc = new Plc(CpuType.Logo0BA8, ip, 0, 0);
await plc.OpenAsync();
await plc.ReadMultipleVarsAsync(dataItems);
Console.WriteLine($"DB{dataItems[0].DB},{dataItems[0].VarType}{dataItems[0].StartByteAdr}:");
Console.WriteLine(dataItems[0].Value);
Console.WriteLine($"DB{dataItems[1].DB},{dataItems[1].VarType}{dataItems[1].StartByteAdr}:");
Console.WriteLine(dataItems[1].Value);
plc.Close();
}
catch (Exception e)
{
Console.WriteLine("An error occurred, include the stack trace when copying:");
Console.WriteLine(e.ToString());
}
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="S7NetPlus" Version="0.4.0" />
</ItemGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29102.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "S7NetPlus.Sample", "S7NetPlus.Sample.csproj", "{9970D8F0-7282-49E2-A0E9-182CF1797351}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9970D8F0-7282-49E2-A0E9-182CF1797351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9970D8F0-7282-49E2-A0E9-182CF1797351}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9970D8F0-7282-49E2-A0E9-182CF1797351}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9970D8F0-7282-49E2-A0E9-182CF1797351}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F5DC0C51-3E30-4854-A64E-B80EB09068EE}
EndGlobalSection
EndGlobal
@noumanqaiser
Copy link

Hello, Truly excellent work ad thanks for the code. I am having a bit of hard time finding out the data block number and start byte addresses for Logo OBA8 plcs. In Logo Soft Comfort, its seems address numbers are visible like they are in TIA Portal. Any idea how I could find out the DB Number and start byte address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment