S7NetPlus / s7netplus

S7.NET+ -- A .NET library to connect to Siemens Step7 devices
MIT License
1.32k stars 586 forks source link

Cannot connect to Siemens Logo 0BA8 #179

Open Zuendelmeister opened 6 years ago

Zuendelmeister commented 6 years ago

Hi all,

I cannot connect to my Logo 0BA8. As far as I know the logo uses CpuType S7200. Here is the code:

Plc plc = new Plc(CpuType.S7200,ip, 0, 2); plc.Open(); I also tried to vary rack and slot but it did not help.

Here is the exception:

S7.Net.PlcException: Couldn't establish the connection to <IP>. Message: TPKT is incomplete / invalid ---> S7.Net.TPKTInvalidException: TPKT is incomplete / invalid at S7.Net.TPKT.Read(Stream stream) in C:\projects\s7netplus-wq17l\S7.Net\TPKT.cs:line 39 at S7.Net.COTP.TPDU.Read(Stream stream) in C:\projects\s7netplus-wq17l\S7.Net\COTP.cs:line 53 at S7.Net.COTP.TSDU.Read(Stream stream) in C:\projects\s7netplus-wq17l\S7.Net\COTP.cs:line 97 at S7.Net.Plc.Open() in C:\projects\s7netplus-wq17l\S7.Net\PlcSynchronous.cs:line 32 --- End of inner exception stack trace --- at S7.Net.Plc.Open() in C:\projects\s7netplus-wq17l\S7.Net\PlcSynchronous.cs:line 40 at ConsoleApp1.Program.Main(String[] args) in <PATH>\ConsoleApp1\Program.cs:line 81

Ideas? Thanks in advance!

Best regards, Zuendelmeister

mycroes commented 6 years ago

Hi @Zuendelmeister,

Are you able to connect using other libraries? Unfortunately we will probably need some pointers to get this working. If you are able to provide a Wireshark dump of some working communication that should also get us somewhere.

Zuendelmeister commented 6 years ago

Hi @mycroes,

thanks for your fast response! I can connect to the logo using node-red. Unfortunately I cannot provide a wireshark log due to regulations. Is there anything else I can provide? Best regards, Zuendelmeister

mycroes commented 6 years ago

Hi @Zuendelmeister,

Could you try with Sally7 if you can connect with local TSAP 01:00 and remote TSAP 02:00? In a quick search those turned up as connection id's for Logo 8, while those are not being used for S7-200. We also don't support override of connection id's (see #153) at this moment, which could provide a workaround in S7NetPlus.

Zuendelmeister commented 6 years ago

I cannot find a code example for Sally7 and I'm not familiar with TSAP and COTP. Sorry but I don't know how to use it.

mycroes commented 6 years ago

I hope this will do (as example):

var conn = new S7Connection("192.168.1.10", new Tsap(1, 0), new Tsap(1, 0));
conn.Open().GetAwaiter().GetResult();

Be sure to replace the IP address with the PLC address.

Zuendelmeister commented 6 years ago

This did not work. I could create a connection with the ConnectionFactory though:

var con = ConnectionFactory.GetConnection(ip, Sally7.Plc.CpuType.S7_200); con.Open();

Opening the connection worked as well. But reading values seems to be very complicated. For reading you need to create an object that implements the IDataItem interface. You even have to write the ReadValue function.

struct dat : IDataItem { public Area Area => throw new NotImplementedException(); public BigEndianShort DbNumber => throw new NotImplementedException(); public Address Address => throw new NotImplementedException(); public BigEndianShort ReadCount => throw new NotImplementedException(); public TransportSize TransportSize => throw new NotImplementedException(); public VariableType VariableType => throw new NotImplementedException(); public void ReadValue(in ReadOnlySpan input) { throw new NotImplementedException(); } public int WriteValue(in Span output) { throw new NotImplementedException(); } }

But as I said the connection could be established.

mycroes commented 6 years ago

@Zuendelmeister Thanks for testing, I was only concerned with the Open() call since that's the call that uses the local / remote TSAP. You can use DataBlockDataItem<TValue> to read / write data (without having to worry about conversion), but feel free to open issues for Sally7 at the respective issues page (I am the author of Sally7 and I will fix your issues if you report them there :wink:).

As far as S7NetPlus is concerned, I'll add initial support for Logo 8 by extending the PlcType enum, that should make it work.

Zuendelmeister commented 6 years ago

Thats great, I'll test it out after you pushed the new version. Thank you so much for your fast help!

mycroes commented 6 years ago

@Zuendelmeister I'm sorry but I didn't properly read 2 messages back. The connection ID's I gave (local 01:00, remote 01:00) are what I thought I saw somewhere, but for S7-200 the ID's are 10:00 (hex; both local and remote, although I'm not sure if local matters, it doesn't for S7-1500 at least). I didn't notice that the 01:00 wasn't working and that you used the ConnectionFactory, so I assumed 01:00 was actually working. The thing is though, that they're configured identically for S7-200 in S7NetPlus and Sally7. There must be some other reason why it's not working. Could you give S7NetPlus another try with S7200 as CPU-type? I will do a comparison of the data sent by S7NetPlus and Sally7, hopefully I can figure a cause there.

mycroes commented 6 years ago

@Zuendelmeister any chance you can fetch the code from #181, build it, and test if it works? There's two queue sizes that are negotiated and S7NetPlus was requesting size 3 for both, while Sally7 requests only 1. Since concurrency is not supported anyway (not now at least) it's fine to set them to 1.

Zuendelmeister commented 6 years ago

Hi @mycroes,

thanks for providing the new code. I tried it out but unfortunately the outcome is the same. TPKT is incomplete / invalid

I tried again different racks and slots like so: 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2

Do you have a clue what the problem could be?

mycroes commented 6 years ago

@Zuendelmeister I did another comparison and found another difference. If you can fetch the latest code from the pull request you can test if it works. Besides that difference the messages from S7NetPlus and Sally7 are equal, so there's hope it works.

As far as rack and slot are considered, those are used for S7-300, 400, 1200 and 1500 only, not for S7-200.

Zuendelmeister commented 6 years ago

I tried to check it out but I get an error:

git checkout -b develop 4c4dde8aeb046ffdf67cc7707a0320863e851b3b fatal: reference is not a tree: 4c4dde8aeb046ffdf67cc7707a0320863e851b3b

So I copied the PLCHelpers.cs into my project from earlier, built it and ised the dll file. Unfortunately the outcome was still the same with the same error.

I added some test code. In the TPKT.cs Read(Stream stream) the length of the stream is zero.

mycroes commented 6 years ago

@Zuendelmeister You need to fetch the commit first:

git fetch origin 4c4dde8aeb046ffdf67cc7707a0320863e851b3b
git checkout -b [branch-name] FETCH_HEAD

Make sure to use the full commit hash for this, not the short hash. Also, -b is to create a new branch, -B allows for a reset of branch to the specified commit.

Anyway, I made some additional changes (still in #181). I was expecting the issue to come from the CommunicationSetup part, but perhaps it is originating in ConnectionRequest after all (just PLC that cuts off the connection a little later though). I checked the differences between Sally7 and S7NetPlus ConnectionRequest and there were some slight differences. I removed the differences in another two commits, I would like you to test both to see if it's perhaps fixed by removing the source reference only. Either way, it would be nice if this would fix the issue.

mycroes commented 6 years ago

Added a third commit to fix the unit tests, you don't really need that for testing though.

Zuendelmeister commented 6 years ago

I'll take a look as soon as I can.

Zuendelmeister commented 6 years ago

Hi again,

I tried to fetch the code but got an error: $ git fetch origin 4c4dde8aeb046ffdf67cc7707a0320863e851b3b error: Server does not allow request for unadvertised object 4c4dde8aeb046ffdf67cc7707a0320863e851b3b

I tried it with 0d99f8fa2f4250cae2bda7511bed38a3aad4d814 though. But also with this commit I had the same problem.

Best regards, Zuendelmeister

mycroes commented 6 years ago

HI @Zuendelmeister,

I found GitHub documentation that states another option (I'm not sure why you're getting the error though, but I can't help it):

git fetch origin pull/179/head:[branch-name]
git checkout [branch-name]

Could you give this a spin and see if that works? It should give you the latest commit in this PR.

Zuendelmeister commented 6 years ago

I don't know why it does not work: $ git fetch origin pull/179/head:develop fatal: Couldn't find remote ref pull/179/head (same for 181) Can you provide a new branch with this commit? In this case I could checkout this one.

Zuendelmeister commented 6 years ago

Anything new that I can try out?

mycroes commented 6 years ago

@Zuendelmeister sorry for my absence on this issue. I was wrong with my fetch command regarding the 179, that of course should have been 181! It's strange that it doesn't work, but you can also download the commit as ZIP: 0d99f8fa...zip. If you can confirm it works I'll merge that PR and do a new release straight away.

Zuendelmeister commented 6 years ago

@mycroes thanks for providing the zip file. I cant get it to build the dll though. The InitializeSourceControlInformationFromSourceControlManager seems to be missing. image

mycroes commented 6 years ago

What VS version are you using? The project is using the newer SDK style .csproj format, which I guess is only supported by newer VS 2017 versions.

Zuendelmeister commented 6 years ago

I'm using a quite new Version image

Zuendelmeister commented 6 years ago

Can you maybe send me the dll for netstandard2.0? This way I can try it out.

Zuendelmeister commented 6 years ago

Anything new?

mycroes commented 6 years ago

Hi @Zuendelmeister,

Sorry for my late response. You should be able to download the AppVeyor build of the PR, you can just extract it to get at the DLL's.

I'm really interested whether this works. Also, I'd be very happy to help you out with this, but not being able to fetch the changes could prove a bit troublesome. Doesn't mean it's an issue on your side, but I don't know a proper solution to that yet either (suggestions welcome).

Zuendelmeister commented 6 years ago

Ok, I retried with the new dll but the outcome is the same.

image

babinc commented 5 years ago

Any update on this issue? I am having the same problem with a 300 series plc. Sally7 works.

mycroes commented 5 years ago

Hi @babinc, is there any chance you could try the code from the develop branch? The issue was fixed in the end, but Sally7 actually still doesn't work for S7-200, because the major issue there seems to be the requested PDU size (which I should probably change in Sally7 as well...).

I didn't get to releasing the changes yet, but if develop does work for you (with S7-300) I'll do a release this week.

Regards, Michael

noumanqaiser commented 5 years ago

Hi Team, I was planning to use s7.net to read and write data to an Siemens logo plc, Can you confirm is S7.net can be used for Siemens Logo plc as of now?

Nouman

mycroes commented 5 years ago

Hi @noumanqaiser, I still need to do that release, but then it should work. I'll try to do it this week, you could however test using the source as well if you don't want to wait for a release.

noumanqaiser commented 5 years ago

Thanks MyCroes, No problem. I can wait for this week and hopefully I can help u with testing aswell on a logo PLC.

mycroes commented 5 years ago

Hi @noumanqaiser, I released 0.4.0 yesterday, let me know if it works! If it doesn't work I want to fix it, but I can't test it myself obviously.

mycroes commented 5 years ago

@noumanqaiser, did you get to testing it yet?

abduIkadir commented 4 years ago

Hello, I had same issue with ET200S IM151-8 PN/DP module and tried connection as logo8 and connected. I connected ET200 series modules as s7300 before. I wrote this here for information.

noumanqaiser commented 4 years ago

HI @mycroes , Sorry for a really late reply. I finally got hold of a Logo OBA8 plc. I wanted to try out reading or wirting to this PLC but I am having a hard time finding out datablock number where I would read/write to. In Siemens Logo Sof Comfort software(software used to modify Logo Programs), it allows you to create basic function blocks and ladder diagram but it doesn't seem to show data block number/address where any data could be accessed/manipulated.

Do you know how I could create a DB/Variable and obtain the DB number/offset value for a specific variable, that could really help.