Every snap7 function returns an integer, if it is zero, it means that the PLC, in accord to the protocol, sent a message saying that the operation was accomplished. This is valid also for functions that don't return values (like dbwrite and writearea).
So simply test the result.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
From the question you asked me, I imagined this answer.
You should speak with the python-snap7 programmer.
I don't know python at all, because I don't like it at all.
Sounds very strange to me that a function does not returns a value and that an exception must be raised also if a return value is not zero.
Snap7 as dll (or .so) does not raise exceptions, it returns an integer that must be checked.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Since you don't have a result, what do you mean for "fail" ?
Do you don't find the values into the DB ?
1 - Try to write the same values using a non-existent DB as db_number param, what happens ?
2 - Are you completely sure that in your user program you don't overwrite that values ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1."fail" means ....when i try to write on PLC 2 ,it is not getting write on that particular Dbaddress
2. when i try to write on PLC 1 with same code it it success ,i can see values on that Dbaddress
3.yes ,after you ask to write same values on non-existent Db number ,it get's Exception that "Address out of range"
4.yes tried lots of different values and diffrent datatype values also,,,,,writing string,int,Dint,....getting "None" for all.....pretty sure not overwrite
Last edit: Sushil Dhote 2020-10-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1.yes, i checked ,Cli_DBWrite () return 0 if it get successufullly write vvalues on PLC.
2.Cli_DBWrite() return the error if it not able to write.
3.the problem i found is when i code below like this
Its because the function is actually wrapped.
the function error_wrap returns the executed function without any return Value.
The function check_error raises an exception in case of any errors.
#thisiswhatthecallactuallylookslike:plc.error_wrap(db_write(db_number=db,start=start,data=result))@error_wrapdefdb_write(self,db_number,start,data):dosomething()deferror_wrap(func):"""Parses a s7 error code returned the decorated function."""deff(*args,**kw):code=func(*args,**kw)check_error(code,context="client")#thisfunctionraisesanexceptionreturnf
@davenardella can you please help
what wrapper (Hi level language) are you using ?
Every snap7 function returns an integer, if it is zero, it means that the PLC, in accord to the protocol, sent a message saying that the operation was accomplished. This is valid also for functions that don't return values (like dbwrite and writearea).
So simply test the result.
@davenardella i am using python language and using python-snap7 wrapper ...
https://github.com/gijzelaerr/python-snap7 this is github link that i am using
in my code i tried
temp = plc.db_write(db_number=db, start=start, data=result)
print("write...success:",temp)
Last edit: Sushil Dhote 2020-10-07
From the question you asked me, I imagined this answer.
You should speak with the python-snap7 programmer.
I don't know python at all, because I don't like it at all.
Sounds very strange to me that a function does not returns a value and that an exception must be raised also if a return value is not zero.
Snap7 as dll (or .so) does not raise exceptions, it returns an integer that must be checked.
yes , i am trying to connect with him ,i thought u may have some idea..OK thanks for rply
As far I can see in write_area (but I'm not an expert):
return self.library.Cli_WriteArea(self.pointer, area, dbnumber, start,
size, wordlen, byref(cdata))
you should see the value returned by the library function
yes right , but i am getting "None" in temp varible as i showned above my above code.
in both the scenirio ....when it success or fail
Since you don't have a result, what do you mean for "fail" ?
Do you don't find the values into the DB ?
1 - Try to write the same values using a non-existent DB as db_number param, what happens ?
2 - Are you completely sure that in your user program you don't overwrite that values ?
1."fail" means ....when i try to write on PLC 2 ,it is not getting write on that particular Dbaddress
2. when i try to write on PLC 1 with same code it it success ,i can see values on that Dbaddress
3.yes ,after you ask to write same values on non-existent Db number ,it get's Exception that "Address out of range"
4.yes tried lots of different values and diffrent datatype values also,,,,,writing string,int,Dint,....getting "None" for all.....pretty sure not overwrite
Last edit: Sushil Dhote 2020-10-07
Cannot happen that a PLC answers "Ok I performed" (and so Result==0) but it didn't write the values.
Into PLC 2 create a new DB similar to previous one , and write into that, or write consecutively into the old DB and into the new one.
I bet that you will find the data into the new DB.
Let me know ;)
1.yes, i checked ,Cli_DBWrite () return 0 if it get successufullly write vvalues on PLC.
2.Cli_DBWrite() return the error if it not able to write.
3.the problem i found is when i code below like this
temp = plc.db_write(db_number=db, start=start, data=result)
print(temp)
"temp" varible not able to get that 0 value,it act as None
when i tried
if (plc.db_write(db_number=db, start=start, data=result));
pass
else:
print("success")
it is working properly.
now the problem is when it not able to write it return error but i also need 1
Sorry I cannot help you on Phyton side...
Its because the function is actually wrapped.
the function error_wrap returns the executed function without any return Value.
The function check_error raises an exception in case of any errors.
Possible Solution:
Last edit: Benjamin Wischer 2020-10-23