ruscito / pycomm

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

Pycomm to micro 820 #59

Closed clemansta closed 4 years ago

clemansta commented 5 years ago

I am trying to use the pycomm to speak with a micro 820. The error I am receiving is: Read in Values: A session need to be registered before to call forward open The code I am using is directly from the examples CLX code see below:

from pycomm.ab_comm.clx import Driver as ClxDriver
import logging

from time import *

if __name__ == '__main__':

    logging.basicConfig(
        filename="ClxDriver.log",
        format="%(levelname)-10s %(asctime)s %(message)s",
        level=logging.DEBUG
    )
    c = ClxDriver()

    print c['port']

    if c.open('10.1.0.6', direct_connection=True):
        print("Open Connection")
        while 1:
            try:
                print("Read in Values:")
                print(c.read_tag(['Controls']))
                print(c.read_tag(['Control_Points_1[1]', 'Control_Points_1[2]', 'Control_Points_1[3]',
                                  'Control_Points_1[4]']))

                print("Write out values:")
                print(c.write_tag('Sensor_Active', 3, 'DINT'))
                print(c.write_tag(('Sensor_Active_1', 1, 'DINT')))
                print(c.write_tag([('Control_Points_2[1]', 4.0, 'real'), ('Control_Points_2[3]', 6.0, 'real'),
                                   ('Control_Points_2[5]', 8.0, 'real'), ('Control_Points_2[7]', 10.0, 'real')]))
                time.sleep(1)

            except Exception as e:
                c.close()
                print e
                pass

        # To read an array
        r_array = c.read_array("Sensor_Value", 1750)
        print("Print an array:")
        for tag in r_array:
            print (tag)

        c.close()

Any help would be appreciated.

clemansta commented 5 years ago

Added

c = ClxDriver()
c.register_session()

Now the errors are:

Traceback (most recent call last):
  File "/TEMS_Software_V_1_1/API/Comm_CIP.py", line 15, in <module>
    c.register_session()
  File "/usr/local/lib/python2.7/dist-packages/pycomm/cip/cip_base.py", line 656, in register_session
    self._send()
  File "/usr/local/lib/python2.7/dist-packages/pycomm/cip/cip_base.py", line 801, in _send
    raise CommError(e)
pycomm.cip.cip_base.CommError: 'NoneType' object has no attribute 'send'

Am I missing something?