Closed aetasoul closed 6 years ago
Hi, Maybe you should check your write permission on CPU settings? good luck!
Also confirm that your CPU is mounted on Rack 0 && slot 2 in HW config?
@aetasoul I'm not sure if anyone ever tested writing memory bits, if I look through the code it seems probable that it's broken (the vartype that is parsed from the address doesn't seem to be used anywhere). Can you verify that you have successful communication (read/write) in DB areas?
Hi,
This is my HW configuration:
And this is the DB1 that I create for test:
I have changed my code like this:
using S7.Net;
Plc plc = new Plc(CpuType.S7300,"192.168.1.1",0,2) plc.Open();
if(plc.isConnected && plc.isAvailable){ plc.Write("DB1.DBX2.0",1); bool testRead = (bool)plc.Read("DB1.DBX2.1"); //plc.Write("M20.0",true); //bool testRead = (bool)plc.Read("M20.1"); }
plc.Close();
the error is the same:
TPKT is incomplete / invalid
@jerko1979 the racks and slot are right as yo ucan check in the picture. What do you mean with "Maybe you should check your write permission on CPU settings?"?
@mycroes I have checked this example for start: https://archive.codeplex.com/?p=s7net
Thanks for help guys!
I have only the keyswitch settings checked.
No protection
This is the project, just dearchive it. If you want you can take a look!
Thanks!
Maybe you should use sharp7,library , here is the link how to . I have never used s7net to be honest! https://www.mesta-automation.com/how-to-write-a-siemens-s7-plc-driver-with-c-and-sharp7/
@aetasoul I think you might have an error in the Write
call, I think you need to pass a bool
instead of 1
, although I'm 100% confident it's a problem.
plc.Write("DB1.DBX2.0", true);
bool testRead = (bool)plc.Read("DB1.DBX2.0");
}
Could you perhaps try to read just an int or dint? Also, make sure the exception is originating from the Read
or Write
calls, there have been issues with opening connection as well with some PLC's.
Maybe you should use sharp7 , library here is the link how to . I have never uset s7net to be honest! https://www.mesta-automation.com/how-to-write-a-siemens-s7-plc-driver-with-c-and-sharp7/
@jerko1979 I don't think you're really helping @aetasoul by pointing him to another library (where I'm afraid the support will be far worse than here, since the developer is a C programmer that ported his code to C# following C conventions). You provided some good advice with regards to the settings, we should be able to get this problem solved by diagnosing what's going on.
I found the problem.
using S7.Net;
Plc plc = new Plc(CpuType.S7300,"192.168.1.1",0,2) plc.Open();
if(plc.isConnected && plc.isAvailable){ plc.Write("M20.0",true); bool testRead = (bool)plc.Read("M20.1"); }
plc.Close();
on this code if I remove the "if" statement for check if the plc.IsAvaiable && plc.IsConnected can write the memory bit 20.0 and read from the memory bit 20.1
the working code is this:
Plc plc = new Plc(CpuType.S7300,"192.168.1.1",0,2); plc.Open();
plc.Write("M20.0",true); bool testRead = Convert.ToBoolean(plc.Read("M20.1"));
plc.Close();
Well Done ! 👍
It also works for DB. So you can read/write memory bit and DB.
Thanks all for the help!
If you need any help to test the library, or improve it tell me. I'm interested in it and I have this cpu: 315-2 PN/DP, 315-2 DP, S7-1500, S7-1200, ET200SP, s7-314, 316-2 DP, 317-2 DP
@mycroes if you want to do more test to check why this if statement cause the problem, just tell me.
@aetasoul @jerko1979 Thanks to both of you. The IsAvailable
method has been broken in recent versions, I'll make sure a separate issue covers this.
Just in case. v0.1.8 -0.1.9 IsConnected and IsAvailable work properly. As it should be.
how do you fanilly solve it? what's main problem, is s7.net or plc set wrong?
Hi all,
I'm trying the c# library on visual studio 2017, I have installed it via nuget packages. I'm getting this error when I run my application:
The cpu is S7-300.
This is my code:
I'm getting the error on: plc.Write("M20.0",true)
If I comment the line I get the error on the reading command.
On the PLC I have only the OB1 with one segment.
|-----|M20.0| -------(M20.1)---
Thanks for help!