olivier123

Sending boolean with RECV/SEND instructions? [Python&CP1L-EM]

13 posts in this topic

Posted (edited)

Hello everybody,

I have another question! I've made a computer vision program to check if a roller (for conveyers) is defect. The software is written in the Python programming language (with the OpenCV library). What I want to do is: I want to send a boolean (0 or 1) from Python to my Omron CP1L PLC. A few years ago I did this with a Siemens S7 1200 PLC with the socket library. Is that also possible with the Omron PLC in combination with RECV/SEND instructions, if yes how and if no what is a good alternative?

Thanks,

Olivier

 

EDIT: I also need to receive a boolean on the Python side

Edited by olivier123

Share this post


Link to post
Share on other sites

I'm not familiar with OpenCV or Python but I would have to believe the communications will be much more efficient exchanging Bytes or Words. I would dedicate a Word to the Booleans you wish to exchange. 

For reading and writing you would need to perform Logical operations on the Word to extract the Boolean. The CP1L has advanced instructions for this but with Python you'll likely have to do it discretely.

Share this post


Link to post
Share on other sites
43 minutes ago, IO_Rack said:

I'm not familiar with OpenCV or Python but I would have to believe the communications will be much more efficient exchanging Bytes or Words. I would dedicate a Word to the Booleans you wish to exchange. 

For reading and writing you would need to perform Logical operations on the Word to extract the Boolean. The CP1L has advanced instructions for this but with Python you'll likely have to do it discretely.

Using words would be no problem, 0='N' and 1='Y', but using RECV and SEND should work? 

If anyone has more information about how to do that, I would love to hear more about it, thanks!

Share this post


Link to post
Share on other sites
On 31-3-2021 at 5:31 PM, photovoltaic said:

Thanks for your answer, I will take a look at it

 

On 31-3-2021 at 7:29 PM, IO_Rack said:

I was unaware the CP1L-E was capable of Socket Services. This is an option.

Since you are using Python, have a look at the link below. 

https://forums.mrplc.com/index.php?/topic/39456-omron-plc-cs-cj2-read-write-data-over-python/

Also thanks for this option. I will try both and hopefully I'll find a working solution! When i have everything working I will post what I did

Share this post


Link to post
Share on other sites
On 31-3-2021 at 7:29 PM, IO_Rack said:

I was unaware the CP1L-E was capable of Socket Services. This is an option.

Since you are using Python, have a look at the link below. 

https://forums.mrplc.com/index.php?/topic/39456-omron-plc-cs-cj2-read-write-data-over-python/

This link helped me quite a lot, but I still have some problems

1- It looks like that pip install fins didn't fully install the whole library, because I still got some error during running the program. I think that's solved now luckily.
2- After running the software I receive a 'timed out' message, which is probably caused by an incorrect given IP-Address. I have tried many addresses, but it seems like nothing is the correct IP. Maybe this problem has something to do with 'problem' 1 which I stated above.

 

 

Share this post


Link to post
Share on other sites
16 minutes ago, olivier123 said:

I have tried many addresses

Do you know the IP address of the CP1L-E?

Do you have CX Programmer?

I have not tried using the software in the link I provided. The user in the link had success. Also the author has provided his email address. 

Share this post


Link to post
Share on other sites
2 hours ago, IO_Rack said:

Do you know the IP address of the CP1L-E?

Do you have CX Programmer?

I have not tried using the software in the link I provided. The user in the link had success. Also the author has provided his email address. 

Yes, I put the address 192.168.250.2 as IP in the PLC settings, that should be the correct IP, right and I'm using CX-programmer.

I sent an email to the author and he already answered. I should have downloaded the files separately instead of using pip install fins. So that's solved now.

Share this post


Link to post
Share on other sites

Posted (edited)

Nice! Thank you for your results.

I was actually wanting to try this myself as a home project on a Raspberry Pi. I'm glad to see others have success with it.

Edited by IO_Rack

Share this post


Link to post
Share on other sites

Posted (edited)

On 5-4-2021 at 8:09 PM, IO_Rack said:

Nice! Thank you for your results.

I was actually wanting to try this myself as a home project on a Raspberry Pi. I'm glad to see others have success with it.

It looks like it works except I don't have the correct IP-address. See attached image. The 169..... IP address is the one I used. I also used 192.168.250.2, but that didn't work. After running the program with 169... IP nothing changes in the PLC registers, so I think I need to look further into that. 

@Michael Walsh do you have more knowledge about this subject?

 

Image link: https://ibb.co/r60YVJs 

I wasn't able to insert media through this forum...

Edited by olivier123

Share this post


Link to post
Share on other sites

From your drawing it looks like 192.168.250.2 is the correct address.  I am not familiar with the Python side of things.  If I had seen this earlier, I would have suggested that you just write a FINS command (published Omron protocol that can be implemented over Ethernet).  If you let me know what address you want to write to, I can generate a FINS command and Wireshark it and attach the trace for you.  

Share this post


Link to post
Share on other sites

Okay I finally got this working! I used Joseph's Python Library. 

import fins.udp

ip = '192.168.250.1' #the desired ip address
memory_address = fins.FinsPLCMemoryAreas().WORK_WORD #which type of address i want to read/write
data_register = b'\x00\x00\x00' #the actual address, so W0 in this case, use b'\x00\x64\x00' for W100 for example

fins_instance = fins.udp.UDPFinsConnection() #get connection
fins_instance.connect(ip) #connect with the given IP address
fins_instance.dest_node_add=1 #the last octat of your PLC IP address, so 192.168.250.1 is my IP, so it's 1
fins_instance.srce_node_add=10 #the last octat of your PC IP address, so 192.168.250.10 is my IP, so it's 10

This is what I actually did and it works really good. Thanks for all your help, very happy with this result!

If anyone has questions, let me know and hopefully I can answer them.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now