ruscito / pycomm

pycomm is a package that includes a collection of modules used to communicate with PLCs
MIT License
139 stars 85 forks source link

self.forward_open() #27

Closed redmeters-sshah closed 7 years ago

redmeters-sshah commented 7 years ago

Hey, I am trying to run test_slc_only.py but I am getting an error in line build_common_packet_format(DATA_ITEM['Unconnected'], ''.join(forward_open_msg),ADDRESS_ITEM['UCMM'],)): Can you please help me in resolving it.

ruscito commented 7 years ago

could you post the error message and the source code?

redmeters-sshah commented 7 years ago

I am trying to run the exact code which you have posted with the changed IP address.

redmeters-sshah commented 7 years ago

capture

ruscito commented 7 years ago

It looks like you didn't connect with the PLC

redmeters-sshah commented 7 years ago

So in "cip_base.py" code in forward_open function do i need to change Connection parameter from default to PLC?

ruscito commented 7 years ago

I don't think so. I tested the connection with different PLCs including SLC and MicroLogix and I noticed that PLC always responded to the 'Default' parameter. Therefor before make any changes I would first make sure the PLC is available (can you ping it, is the Ethernet port available with a reasonable configuration, how do you go online with RSLogix?)

Ago

On Wed, Jul 5, 2017 at 8:56 AM, shah-s notifications@github.com wrote:

So in "cip_base.py" code in forward_open function do i need to change Connection parameter from default to PLC?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-313110237, or mute the thread https://github.com/notifications/unsubscribe-auth/ABL5oRziq2zmrZLFPmr3BPUfIMgEIQfdks5sK5XxgaJpZM4OK8i3 .

redmeters-sshah commented 7 years ago

Yes, I am able to ping to the IP address where PLC is connected. So what can be the issue for this error?

ruscito commented 7 years ago

Difficult to help without a log file. Delete the existing log file, execute the script again and send or post the log

On Wed, Jul 5, 2017 at 10:03 AM, shah-s notifications@github.com wrote:

Yes, I am able to ping to the IP address where PLC is connected. So what can be the issue for this error?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-313130357, or mute the thread https://github.com/notifications/unsubscribe-auth/ABL5oU_V0iIdFEyM6RoR2-kFlMmdr3Kzks5sK6W_gaJpZM4OK8i3 .

redmeters-sshah commented 7 years ago

I did not understood which log file you are talking about. As i am using the exact code of yours for now. Can you please explain which log file you want me to execute again? thanks

ruscito commented 7 years ago

In the directory were you are executing the script there is a file "SlcDriver.log" which contains debug information and the data packets exchanged. You need to delete this file, and execute the python script again. Once you do so the log file will be recreated with the latest debug information

redmeters-sshah commented 7 years ago

Here is the new log file image

redmeters-sshah commented 7 years ago

image

ruscito commented 7 years ago

it looks like it fail during forward_open but i'm not sure from the image you posted. It is possible to get the entire log file

redmeters-sshah commented 7 years ago

Should I send the images of log file?

redmeters-sshah commented 7 years ago

here is the pdf version of the log file doc.pdf

ruscito commented 7 years ago

As I suspected the forward_open failed. Which PLC model are you trying to connect and what's the tag you are trying to read?

redmeters-sshah commented 7 years ago

PLC model is Micro820 and Tag I am trying to read is DV

ruscito commented 7 years ago

Harggg! I should ask this question at the beginning. Micro models are totally different beast :) So they respond as "Out of Connections" (0x0113 is the status I read from your log)
Anyhow to work you need to set the parameter "direct_connection" to True when you open the connection

c.open(172.16.2.167, direct_connection=True):

redmeters-sshah commented 7 years ago

Thank you, it worked. I am getting 22 as output, what does that signifies?

ruscito commented 7 years ago

it should be the value of your tag. Make sure to import "pycomm.ab_comm.clx" and not "pycomm.ab_comm.slc"

redmeters-sshah commented 7 years ago

okay. thanks a lot for your help!

ruscito commented 7 years ago

No problem

redmeters-sshah commented 7 years ago

One last thing, When i Interrupt the program i get the following as a result. image And can you explain me how to read data from log file? image We will get the readings of PLC on log file right?

redmeters-sshah commented 7 years ago

One last thing, When i Interrupt the program i get the following as a result. [image: image] https://user-images.githubusercontent.com/29803896/27967949-fde385c6-6312-11e7-839a-ce5abf158c76.png And can you explain me how to read data from log file? [image: image] https://user-images.githubusercontent.com/29803896/27967980-2cf50a74-6313-11e7-9f0c-affd204db591.png We will get the readings of PLC on log file right?

On Fri, Jul 7, 2017 at 11:52 AM, Agostino Ruscito notifications@github.com wrote:

No problem

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-313720702, or mute the thread https://github.com/notifications/unsubscribe-auth/AcbFeBX1H8M3NAVDmmoTGdSAYg-K7pm9ks5sLlRXgaJpZM4OK8i3 .

--

Saurabh Shah Information Technology Intern, Red Meters Direct | +1 407-337-0110 redmeters.com http://www.redmeters.com/ | s.shah@redmeters.com The RM Series Technology & Specifications http://www.redmeters.com/technology/

ruscito commented 7 years ago

For the first question: the reason you are getting the error is because you interrupted the process with ctrl-c without close the connection. The example you are using is not the best "strategy", what you really want is to exit the reading/writing loop and then call the "close" method to clean-up the connection with the PLC (foward_close)

For the second question: the log file is just debug purpose only; at the beginning in the example file we set the log level to "DEBUG", but if you set it to "WARNING" then the log file will contain only errors or warnings. There is are lots of information in the log file and the majority is protocol related that wrap around the value you are trying to read

redmeters-sshah commented 7 years ago

So how to read value from log file?

ruscito commented 7 years ago

You don't! You read value returned by the read_tag() method and you write using the write_tag() method

redmeters-sshah commented 7 years ago

Can you explain what each print statement signifies in "test_slc_only.py" program. I am trying to read data from PLC Micro820. It is connected with multiple appliance so is there any way we can filter out data of particular appliance?

On Fri, Jul 7, 2017 at 3:16 PM, Agostino Ruscito notifications@github.com wrote:

You don't! You read value returned by the read_tag() method and you write using the write_tag() method

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-313769683, or mute the thread https://github.com/notifications/unsubscribe-auth/AcbFeOAhIrEgUtFITh7pnWvWyTtzTqh9ks5sLoQmgaJpZM4OK8i3 .

--

Saurabh Shah Information Technology Intern, Red Meters Direct | +1 407-337-0110 redmeters.com http://www.redmeters.com/ | s.shah@redmeters.com The RM Series Technology & Specifications http://www.redmeters.com/technology/

redmeters-sshah commented 7 years ago

How to solve the error of forward_close returned False image

ruscito commented 7 years ago

That's not an error. When you connect for the first time pycomm try to execute the foward_close to close any nonactive connection ( a connection that was not closed correctly could stay active reducing the number of resource ) In this case it returned false just because there wasn't opened connections

redmeters-sshah commented 7 years ago

Can you explain what each print statement signifies in "test_slc_only.py" program. I am trying to read data from PLC Micro820. It is connected with multiple appliance so is there any way we can filter out data of particular appliance?

redmeters-sshah commented 7 years ago

can you explain how u made readtags() in program and from where we can read the values returned by the readtag()

ruscito commented 7 years ago

readtags() return the value, and you will need to write a program that put the returned values wherever you need it. You will need some programming skills to do so

On Tue, Jul 11, 2017 at 12:00 PM, shah-s notifications@github.com wrote:

can you explain how u made readtags() in program and from where we can read the values returned by the readtag()

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-314508113, or mute the thread https://github.com/notifications/unsubscribe-auth/ABL5oQRBnIb7i5AcmUOMDijgg2pvKtT9ks5sM6pCgaJpZM4OK8i3 .

redmeters-sshah commented 7 years ago

So the readtags() created by you in the programs would not help me? as my projects matches exactly with your example. I am trying to read the value from PLC from the remote desktop.

redmeters-sshah commented 7 years ago

So the readtags() created by you in the programs would not help me? as my projects matches exactly with your example. I am trying to read the value from PLC from the remote desktop.

patrickjmcd commented 7 years ago

If you're trying using a micro820, you need to use the other example "test_clx_comm.py". As @ruscito mentioned, you'll need to make sure you're enabling the direct connection by using c.open(172.16.2.167, direct_connection=True)

In that example you'll see the line print(c.read_tag(['ControlWord']))

This should print out the value returned from c.read_tag() which is a tuple of (value, tag type).

Storing the value of read_tags() will allow you to access the 0-th member of the tuple to get the value.

redmeters-sshah commented 7 years ago

I got the error "A session need to be registered before to call forward open"

On Thu, Jul 13, 2017 at 11:30 AM, Patrick McDonagh <notifications@github.com

wrote:

If you're trying using a micro820, you need to use the other example "test_clx_comm.py". As @ruscito https://github.com/ruscito mentioned, you'll need to make sure you're enabling the direct connection by using c.open(172.16.2.167, direct_connection=True)

In that example you'll see the line print(c.read_tag(['ControlWord']))

This should print out the value returned from c.read_tag() which is a tuple of (value, tag type).

Storing the value of read_tags() will allow you to access the 0-th member of the tuple to get the value.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315113922, or mute the thread https://github.com/notifications/unsubscribe-auth/AcbFeN7rOjaYgFxOJv2hf1DVBFyVyfNyks5sNjgvgaJpZM4OK8i3 .

--

Saurabh Shah Information Technology Intern, Red Meters Direct | +1 407-337-0110 redmeters.com http://www.redmeters.com/ | s.shah@redmeters.com The RM Series Technology & Specifications http://www.redmeters.com/technology/

patrickjmcd commented 7 years ago

It would really help us to see the exact code you're using.

redmeters-sshah commented 7 years ago

For now using the exact code which is there in "test_clx_comm.py" As I am in learning phase.

On Thu, Jul 13, 2017 at 12:39 PM, Patrick McDonagh <notifications@github.com

wrote:

It would really help us to see the exact code you're using.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315133785, or mute the thread https://github.com/notifications/unsubscribe-auth/AcbFePZlAmTdrK85Z3pK1CBN9u7HzHk2ks5sNkhAgaJpZM4OK8i3 .

--

Saurabh Shah Information Technology Intern, Red Meters Direct | +1 407-337-0110 redmeters.com http://www.redmeters.com/ | s.shah@redmeters.com The RM Series Technology & Specifications http://www.redmeters.com/technology/

patrickjmcd commented 7 years ago

You’re changing the IP address to reflect the IP address of your PLC, right? Please post the EXACT code you’re using.

redmeters-sshah commented 7 years ago

image I am using this code. Thank you

redmeters-sshah commented 7 years ago

Can you see the code and let me know if i need to make any changes in that or not.

On Fri, Jul 14, 2017 at 12:30 AM, Patrick McDonagh <notifications@github.com

wrote:

You’re changing the IP address to reflect the IP address of your PLC, right? Please post the EXACT code you’re using.

On July 13, 2017 at 11:42:29 AM, shah-s (notifications@github.com) wrote:

For now using the exact code which is there in "test_clx_comm.py" As I am in learning phase.

On Thu, Jul 13, 2017 at 12:39 PM, Patrick McDonagh < notifications@github.com

wrote:

It would really help us to see the exact code you're using.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315133785, or mute the thread < https://github.com/notifications/unsubscribe-auth/ AcbFePZlAmTdrK85Z3pK1CBN9u7HzHk2ks5sNkhAgaJpZM4OK8i3

.

--

Saurabh Shah Information Technology Intern, Red Meters Direct | +1 407-337-0110 <(407)%20337-0110> redmeters.com http://www.redmeters.com/ | s.shah@redmeters.com The RM Series Technology & Specifications http://www.redmeters.com/technology/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315134564, or mute the thread https://github.com/notifications/unsubscribe-auth/ACX6EIzZUcVAiVeRXh_ 0ixnxCjg_p6yfks5sNkjzgaJpZM4OK8i3

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315267090, or mute the thread https://github.com/notifications/unsubscribe-auth/AcbFeLSUkAmQ0C9e__-aMiSRNU6MRuuoks5sNu7mgaJpZM4OK8i3 .

--

Saurabh Shah Information Technology Intern, Red Meters Direct | +1 407-337-0110 redmeters.com http://www.redmeters.com/ | s.shah@redmeters.com The RM Series Technology & Specifications http://www.redmeters.com/technology/

patrickjmcd commented 7 years ago

Do you have a tag named “ControlWord” in your Micro800?

What model of Micro800 are you using? 820? 850?

On July 17, 2017 at 7:53:54 AM, shah-s (notifications@github.com) wrote:

Can you see the code and let me know if i need to make any changes in that or not.

On Fri, Jul 14, 2017 at 12:30 AM, Patrick McDonagh < notifications@github.com

wrote:

You’re changing the IP address to reflect the IP address of your PLC, right? Please post the EXACT code you’re using.

On July 13, 2017 at 11:42:29 AM, shah-s (notifications@github.com) wrote:

For now using the exact code which is there in "test_clx_comm.py" As I am in learning phase.

On Thu, Jul 13, 2017 at 12:39 PM, Patrick McDonagh < notifications@github.com

wrote:

It would really help us to see the exact code you're using.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315133785, or mute the thread < https://github.com/notifications/unsubscribe-auth/ AcbFePZlAmTdrK85Z3pK1CBN9u7HzHk2ks5sNkhAgaJpZM4OK8i3

.

--

Saurabh Shah Information Technology Intern, Red Meters Direct | +1 407-337-0110 <(407)%20337-0110> redmeters.com http://www.redmeters.com/ | s.shah@redmeters.com The RM Series Technology & Specifications http://www.redmeters.com/technology/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315134564, or mute the thread https://github.com/notifications/unsubscribe-auth/ACX6EIzZUcVAiVeRXh_ 0ixnxCjg_p6yfks5sNkjzgaJpZM4OK8i3

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315267090, or mute the thread < https://github.com/notifications/unsubscribe-auth/AcbFeLSUkAmQ0C9e__-aMiSRNU6MRuuoks5sNu7mgaJpZM4OK8i3

.

--

Saurabh Shah Information Technology Intern, Red Meters Direct | +1 407-337-0110 redmeters.com http://www.redmeters.com/ | s.shah@redmeters.com The RM Series Technology & Specifications http://www.redmeters.com/technology/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315746957, or mute the thread https://github.com/notifications/unsubscribe-auth/ACX6EKO2kHKx8Lm_j0giDFSv-ita-Vcwks5sO1ligaJpZM4OK8i3 .

redmeters-sshah commented 7 years ago

Micro 820

patrickjmcd commented 7 years ago

Please post the whole error message you get, including the command used to run the script

redmeters-sshah commented 7 years ago

image

patrickjmcd commented 7 years ago

Can you remove the while loop, so it just runs once and post that output?

redmeters-sshah commented 7 years ago

image

redmeters-sshah commented 7 years ago

Do i need to make any changes in Forward_open() ?

redmeters-sshah commented 7 years ago

How can I solve this error?

On Mon, Jul 17, 2017 at 9:30 AM, Patrick McDonagh notifications@github.com wrote:

Can you remove the while loop, so it just runs once and post that output?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruscito/pycomm/issues/27#issuecomment-315755800, or mute the thread https://github.com/notifications/unsubscribe-auth/AcbFeL4OS1kQHFvSVuZOkd0N26grztopks5sO2HkgaJpZM4OK8i3 .

--

Saurabh Shah Information Technology Intern, Red Meters Direct | +1 407-337-0110 redmeters.com http://www.redmeters.com/ | s.shah@redmeters.com The RM Series Technology & Specifications http://www.redmeters.com/technology/