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.

New Here? Please read this important info!!!


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

Reply
 
Thread Tools Display Modes
Old October 16th, 2014, 04:05 PM   #16
Thomas_v2
Member
Germany

Thomas_v2 is offline
 
Join Date: Apr 2009
Location: Ger
Posts: 441
Just play around with the functions, and read the documentation.

You can read all different types. I would recommend to pack the data you want to send into a struct of a datablock. Then you can use this struct as parameter for the Tsend function.

On python side you have to convert the data into python types, using unpack. Keep in mind that the S7 uses big endian.

In the attached PDF I've shown how to convert a struct with a Word (2 Bytes), an Int (2 Byte) and a Real (4 Byte) value. Overall 8 bytes you have to send and receive.
Attached Files
File Type: pdf S71200-TconPassive-Demo-TIA-V11-Div.pdf (32.8 KB, 90 views)
  Reply With Quote
Old October 17th, 2014, 07:34 AM   #17
DiegoE
Member
Brazil

DiegoE is offline
 
Join Date: Sep 2014
Location: 98280000
Posts: 21
Hi Thomas_v2
I have to send a value x of my Python script to the PLC and he read this value in a Word or Int?

Thanks for everything so far!!
  Reply With Quote
Old October 24th, 2014, 06:57 AM   #18
DiegoE
Member
Brazil

DiegoE is offline
 
Join Date: Sep 2014
Location: 98280000
Posts: 21
??
  Reply With Quote
Old October 24th, 2014, 09:21 AM   #19
boneless
Lifetime Supporting Member + Moderator
United States

boneless is offline
 
Join Date: Feb 2008
Location: OKC
Posts: 1,599
Snap7 is a library used for communication with step7. You might want to check that out:


http://snap7.sourceforge.net/
  Reply With Quote
Old October 27th, 2014, 08:20 AM   #20
DiegoE
Member
Brazil

DiegoE is offline
 
Join Date: Sep 2014
Location: 98280000
Posts: 21
Hi boneless
Snap 7 is not useful for me, so I'm creating a system itself. But anyway thank you!
  Reply With Quote
Old November 3rd, 2014, 08:09 AM   #21
DiegoE
Member
Brazil

DiegoE is offline
 
Join Date: Sep 2014
Location: 98280000
Posts: 21
??
  Reply With Quote
Old December 11th, 2014, 05:46 AM   #22
DiegoE
Member
Brazil

DiegoE is offline
 
Join Date: Sep 2014
Location: 98280000
Posts: 21
Hi Thomas_v2
Its I send a string to the PLC and he assign the value to a variable of type INT or WORD, the envez to be in CHAR?
  Reply With Quote
Old December 12th, 2014, 11:19 AM   #23
Thomas_v2
Member
Germany

Thomas_v2 is offline
 
Join Date: Apr 2009
Location: Ger
Posts: 441
I guess you want to send a char array to the plc, and convert this into an integer value.

At first you have to convert the char-array into a string. There is a library function "Chars_TO_Strg" for this.
Then you can use the Function "STR_VAL" and convert the string into an integer, if the string contains valid chars for an integer.

Using strings inside a plc is much more complicated as in any other language like python. Why don't you use my example and send direct the binary integer values from your python script to the plc?
  Reply With Quote
Old February 9th, 2015, 08:55 AM   #24
DiegoE
Member
Brazil

DiegoE is offline
 
Join Date: Sep 2014
Location: 98280000
Posts: 21
Hi Thomas_v2,
Sorry to leave the topic so much time off, is that I am very involved at the time this project, well, what I need is to send the Python script an integer value to the PLC, send more than one character.
Ex: Python sends to the PLC the value of 123456

Thanks!!

Last edited by DiegoE; February 9th, 2015 at 09:00 AM.
  Reply With Quote
Old February 9th, 2015, 12:46 PM   #25
Thomas_v2
Member
Germany

Thomas_v2 is offline
 
Join Date: Apr 2009
Location: Ger
Posts: 441
Open a socket and send:

sock.send(b"123456")

Then you've got this as char-array in your plc, and could convert it into the datatype you need.

I don't understand why you want to use Python and sockets, when you have neither knowledge in Python programming, nor in the basics of TCP sockets.
  Reply With Quote
Old February 23rd, 2015, 07:52 AM   #26
DiegoE
Member
Brazil

DiegoE is offline
 
Join Date: Sep 2014
Location: 98280000
Posts: 21
Hi Thomas_v2,
I have knowledge in Python, just never made a communication between Python and PLC, so my doubt, I was in doubt whether it would have to change something in Python to receive a Int in the PLC, and have to use Python as the current project currently underway only accepts Python!

Thanks!
  Reply With Quote
Old March 6th, 2020, 06:39 AM   #27
Bhargav Patel
Member
India

Bhargav Patel is offline
 
Join Date: Feb 2020
Location: Gandhinagar
Posts: 1
Quote:
Originally Posted by Thomas_v2 View Post
I've used Python 2. Unfortunately Python 2 and Python 3 are not fully compatible.

Change the last two lines of my example to:
Code:
import socket

address = "192.168.1.191"
port = 2000
sock = socket.socket()
sock.connect((address, port))
sock.send(b"hello")



>>
Traceback (most recent call last):
File "D:\BHARGAV PATEL\DOC\Temp\python\6mar_pypl.py", line 6, in <module>
sock.connect((address, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
<<
it shows like this, what is the solution of it buddy..?? (i am using.. TIA v14, LAN cable, siemens CPU 1214C DC/DC/DC, Thonny 3.2.6 IDE for python code)

Last edited by Bhargav Patel; March 6th, 2020 at 06:44 AM.
  Reply With Quote
Old March 6th, 2020, 10:05 AM   #28
Thomas_v2
Member
Germany

Thomas_v2 is offline
 
Join Date: Apr 2009
Location: Ger
Posts: 441
Quote:
Originally Posted by Bhargav Patel View Post
File "D:\BHARGAV PATEL\DOC\Temp\python\6mar_pypl.py", line 6, in <module>
sock.connect((address, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
<<
it shows like this, what is the solution of it buddy..?? (i am using.. TIA v14, LAN cable, siemens CPU 1214C DC/DC/DC,

Does your CPU has the same IP address as in the example (192.168.1.191)? Can you ping the IP address?


Also check the status value returned from the TCON block in the S7 program.
  Reply With Quote
Old March 6th, 2020, 03:14 PM   #29
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 1,431
Quote:
Originally Posted by Bhargav Patel View Post
>>
Traceback (most recent call last):
File "D:\BHARGAV PATEL\DOC\Temp\python\6mar_pypl.py", line 6, in <module>
sock.connect((address, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
<<
it shows like this, what is the solution of it buddy..?? (i am using.. TIA v14, LAN cable, siemens CPU 1214C DC/DC/DC, Thonny 3.2.6 IDE for python code)



That error messages usually* means there is no device on the internet at TCP/IP address 192.168.1.191 listening on port 2000.


It does tell you that the system running Python is able to get to the 192.168.1.x or 192.168.x.x. network via an ethernet interface that thinks is it on that network.


Could you supply some more information, please:


- what is the hardware, software and network configuration on the PC running Python? It looks like it is windows, so a dump of the command [ipconfig /all]** would be useful; if it is Linux then a dump of [/sbin/ifconfig -a] would be useful.


- The output of the command [arp -a] would also be useful.



- what is the network configuration of the PLC to which the python script is trying to connect? You may need to look for the Mac address on the hardware (twelve hexadecimal characters such as 0123456789abc or 01-23-45-67-89-0a-bc or 01:23:...), and then find it's TCP/IP address assignment in the TCP/IP router's DHCP web page (probably at http://192.168.1.1 or similar). A better question might be to find out how the PLC is getting its IP address.




If all of this terminology is confusing to you, then you may need to find your network administrator.




* I say "usually" because there could be a device that is ignoring the source TCP/IP system that is runing the Python script.


** strip the square brackets from those commands and issue them from a command line (e.g. [Win + R] => [cmd], or a shell window in Linux)

Last edited by drbitboy; March 6th, 2020 at 03:19 PM. Reason: fix typos
  Reply With Quote
Old March 7th, 2020, 03:41 PM   #30
memding
Banned User
Australia

memding is offline
 
Join Date: Nov 2019
Location: London
Posts: 11
Can you tell me more about Tsend, TRecv?
  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
PC and PLC Communication DiegoE LIVE PLC Questions And Answers 6 September 30th, 2014 08:56 AM
Universal PLC Monitor Nitay LIVE PLC Questions And Answers 11 August 15th, 2014 05:11 AM
PC <-> PLC & real time communication DINT2 LIVE PLC Questions And Answers 1 February 11th, 2014 03:21 PM
Communication between Simotion and Linux wim_ LIVE PLC Questions And Answers 1 April 16th, 2010 04:41 AM
A communication problem between a PLC and a PC through WLAN Decamber LIVE PLC Questions And Answers 3 October 15th, 2008 08:45 AM


All times are GMT -4. The time now is 03:19 AM.


.