You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old November 29th, 2017, 12:33 PM   #16
babido10
Member
Morocco

babido10 is offline
 
Join Date: Nov 2017
Location: rabat
Posts: 28
Quote:
Originally Posted by JOLTRON View Post
The print("MW0=" was fitting when reading the value of of a memory location. I don't believe it would be necessary anymore. You should probably replace it with something along the lines of 'Result of writing MW10 = '

WriteFlagValue(0,0 shows what byte, bit you want to write.
So it should be updated to WriteFlagValue(10,0

None))) at the is a pointer to the data that is to be written. You can try insterting an integer or something directly and see if it errors. The example below should write 47 to mw10

I would try something along the lines of:

print("Result of writing MW10 = "+str(prosim.WriteFlagValue(10,0,win32com.client.c onstants.S7_Word, 47)))
I tried but doesn't working

Error mssg:

File "D:\simooo\plc.py", line 9, in <module>
print("Result of writing MW10 = "+str(prosim.WriteFlagValue(0, 0, win32com.client.constants.S7_Word, 47)))
TypeError: WriteFlagValue() takes at most 4 arguments (5 given)
  Reply With Quote
Old November 29th, 2017, 01:27 PM   #17
JOLTRON
Lifetime Supporting Member
United States

JOLTRON is offline
 
JOLTRON's Avatar
 
Join Date: Aug 2006
Location: MI
Posts: 646
Try removing the constant definition. That will reduce the number of arguments by one. But I am not sure if it will accept the actual value of 47 or if it will require an actual pointer.

print("Result of writing MW10 = "+str(prosim.WriteFlagValue(10, 0, 47)))
  Reply With Quote
Old November 29th, 2017, 04:45 PM   #18
Thomas_v2
Member
Germany

Thomas_v2 is offline
 
Join Date: Apr 2009
Location: Ger
Posts: 375
You can't write a single word, and also not a single byte. This problem with Python, pyWin32 and Prosim I have mentioned in my first post.

You can write variable with:

valueToWrite = 1234
prosim.WriteFlagValue(12, 0, valueToWrite)

The parameters don't contain any (visible) size information. But in detail the 3rd argument is a variant. A variant contains information of the data type of the variable. If the datatype is byte, then the function writes one single byte, if it's a word then the function writes a word and so on.
But every Python variable is detected as 32 bit integer variable, you can't force a datatype to be 8 or 16 bit.

You'll get similar problems when you want to write a float value, but this can be solved with struct.unpack.

The only method to write a byte or a word with Python / pywin to prosim I know, is to set/reset every single bit of the variable. But when the bits are set/reset not between the OB1 cycles, then you may read an uncomplete variable inside the plc program.

I'd use another language like C#, or write a C dll which encapsulates the prosim handling, and call the C functions from Python.
  Reply With Quote
Old November 30th, 2017, 04:09 AM   #19
babido10
Member
Morocco

babido10 is offline
 
Join Date: Nov 2017
Location: rabat
Posts: 28
Quote:
Originally Posted by Thomas_v2 View Post
You can't write a single word, and also not a single byte. This problem with Python, pyWin32 and Prosim I have mentioned in my first post.

You can write variable with:

valueToWrite = 1234
prosim.WriteFlagValue(12, 0, valueToWrite)

The parameters don't contain any (visible) size information. But in detail the 3rd argument is a variant. A variant contains information of the data type of the variable. If the datatype is byte, then the function writes one single byte, if it's a word then the function writes a word and so on.
But every Python variable is detected as 32 bit integer variable, you can't force a datatype to be 8 or 16 bit.

You'll get similar problems when you want to write a float value, but this can be solved with struct.unpack.

The only method to write a byte or a word with Python / pywin to prosim I know, is to set/reset every single bit of the variable. But when the bits are set/reset not between the OB1 cycles, then you may read an uncomplete variable inside the plc program.

I'd use another language like C#, or write a C dll which encapsulates the prosim handling, and call the C functions from Python.
i used this script to write M1.4
print("Result of writing MB1 = "+str(prosim.WriteFlagValue(1, 4, True)))
It works very well
but if i tryied to write input point E2.1
print("Result of writing EB2 = "+str(prosim.WriteInputPoint(2, 1, True)))
it does not work

and if u can give a exemple for this methode:
"use another language like C#, or write a C dll which encapsulates the prosim handling, and call the C functions from Python"

Regards!
  Reply With Quote
Old November 30th, 2017, 12:53 PM   #20
Thomas_v2
Member
Germany

Thomas_v2 is offline
 
Join Date: Apr 2009
Location: Ger
Posts: 375
See Plcsim manual. It has sample snippets of how to use the S7Prosim interface from C#, C++ and VB6.
  Reply With Quote
Old December 5th, 2017, 10:16 AM   #21
babido10
Member
Morocco

babido10 is offline
 
Join Date: Nov 2017
Location: rabat
Posts: 28
Quote:
Originally Posted by Thomas_v2 View Post
See Plcsim manual. It has sample snippets of how to use the S7Prosim interface from C#, C++ and VB6.
When I simulated the program it gives me an error

code python(part of main program):

if okLeft: #random.randrange(2):
resultLeft = "OK"
print("Result of writing MB0="+str(prosim.writeFlagValue(0, 1, True)))

else:
resultLeft = "NOK"
print("Result of writing MB0="+str(prosim.writeFlagValue(0, 1, False)))

if okRight: #random.randrange(2):
resultRight = "OK"
print("Result of writing MB0="+str(prosim.writeFlagValue(0, 2, True)))

else:
resultRight = "NOK"
print("Result of writing MB0="+str(prosim.writeFlagValue(0, 2, False)))

return resultLeft,resultRight, imagenesProcesadas

////

error:

else:
^
IdentificationError: unexpected indent

//

if u can help me to resolve this problem

Regards!!
  Reply With Quote
Old December 6th, 2017, 09:49 AM   #22
babido10
Member
Morocco

babido10 is offline
 
Join Date: Nov 2017
Location: rabat
Posts: 28
Quote:
Originally Posted by Thomas_v2 View Post
See Plcsim manual. It has sample snippets of how to use the S7Prosim interface from C#, C++ and VB6.
Hey Thomas, thank u to help me to have solution of this problem

code python:

import snap7
from time import sleep
import struct
import snap7.client as c


plc = snap7.client.Client()
plc.connect("192.168.0.1")

plc.writeMem('QX0.0',True) # write Q0.0 to be true, which will only turn on the output if it isn't connected to any rung in your ladder code
print plc.getMem('MX0.1') # read memory bit M0.1
print plc.getMem('IX0.0') # read input bit I0.0
plc.plc.disconnect()

////

error line ==> plc = snap7.client.Client()

I connected with the plc but the problem stay same
if u can help me to resolve this problem
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Kivy + Python + PLC + RPi DINT2 LIVE PLC Questions And Answers 7 September 9th, 2016 10:28 AM
PLC Update - Back Issues Collection Now Available! Phil Melore LIVE PLC Questions And Answers 11 October 22nd, 2015 02:17 AM
try to connect PLC via intouch wonderware b_e33 LIVE PLC Questions And Answers 1 April 3rd, 2013 08:06 AM
How to connect AC sensor and motor to PLC Zhen LIVE PLC Questions And Answers 5 April 10th, 2009 06:47 AM
how to connect a PLC to an optocoupler Sean Vyar LIVE PLC Questions And Answers 1 April 5th, 2004 10:52 AM


All times are GMT -5. The time now is 10:47 PM.


.