Announcement

Collapse
No announcement yet.

PLC using data from a CSV file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts


  • PLC using data from a CSV file

    i have been tasked with getting data from an ERP progrgam managed by our IT department and displaying it on a ViewMarq display. Our IT department would like there program to save the data in a CSV on the network somewhere and whatever i setup to read that data.

    I can think of a few ways that it might work but am open to others.
    I could probably write a script in wonderware and use it to communicate with the ViewMarq
    I might be able to use excel and VBA to pass the data to the PLC.

    How would you go about doing it?


  • #2
    If the goal is to simply display on the viewmarq - and you have a PC (where does the CSV reside), just let the PC dump strings on the viewmarq.
    I haven't tried this, but it should be feasible.

    Comment



    • #3
      Originally posted by kewakl View Post
      If the goal is to simply display on the viewmarq - and you have a PC (where does the CSV reside), just let the PC dump strings on the viewmarq.
      I haven't tried this, but it should be feasible.
      I am probably over thinking this but how would the PC continuously update the viewmarq. I know I would need some sort of software layer in there but am not sure what. I have been been meaning to pick up higher level programming langues and it might not be all that bad to write a small program in python or C to parse out a CSV and send out ascii text on a serial port.

      Comment



      • #4
        I am sure i am missing something stupid but i have written some python code using a modbus library that writes just fine to a productivity 1000. when setup to write to a viewmarq the viewmarq doesn't change from the initial message displaying the com setup and such.

        when using the viewmawq instruction in the productivity 1000 the viewmarq works just fine. when doing manual modbus writes from the p1000 like it shows in the viewmarq manual it dose not change from the startup just like with the modbus library and python.

        the modbus write instruction in the p1000 shows no errors.

        Edit i have the productivity working with the manual modbus write. it was a oversight on how to do the CR at the end.

        i got it working with the python script i had to enable byte and word swap in the viewmarq and set it to write starting at register 10999. if anyone is interested i can post the python script.
        Last edited by z28z34man; 06-07-2019, 06:23 AM.

        Comment



        • #5
          Originally posted by z28z34man View Post
          I am sure i am missing something stupid but i have written some python code using a modbus library that writes just fine to a productivity 1000. when setup to write to a viewmarq the viewmarq doesn't change from the initial message displaying the com setup and such.

          when using the viewmawq instruction in the productivity 1000 the viewmarq works just fine. when doing manual modbus writes from the p1000 like it shows in the viewmarq manual it dose not change from the startup just like with the modbus library and python.

          the modbus write instruction in the p1000 shows no errors.

          Edit i have the productivity working with the manual modbus write. it was a oversight on how to do the CR at the end.

          i got it working with the python script i had to enable byte and word swap in the viewmarq and set it to write starting at register 10999. if anyone is interested i can post the python script.
          Hey, thanks for the update.
          Been having issues of my own -- I should/would have suggested monitoring the data on the wire to check that it signals electrically the same from PLC and PC. That should have indicated the CR issue.

          I would be interested in looking at the script!

          Comment



          • #6
            I am by no means a python expert and just decided to to pick it up a few weeks ago. i know that i need to build in some error handling with try staiments and will work on that next.
            This is the script that sends the initial command string to the ViewMarq copped from the ViewMarq program. i also have a script that updates the variables

            Code:
            # i am using python 3.7
            # make sure you have the pymodbus module installed.
            # in command prompt that is ran as administrator "pip install pymodbus"
            
            from pymodbus.client.sync import ModbusSerialClient as ModbusClient
            from pymodbus.constants import Endian
            from pymodbus.payload import BinaryPayloadBuilder
            
            
            # this is the slave node number of the ViewMarq
            UNIT = 0x1
            
            
            # this is the sub rutine that runs if this is python script is opened directly
            def run_sync_client():
                # this opens a .txt file named ViweMarqINIT.txt saved in the same folder as this script.  it contains the command
                # string to the ViewMarq on the first line.  it saves it in a variable named inittext
                with open('ViweMarqINIT.txt') as f:
                    inittext = f.read()
                # this opens up an modbus RTU client on com port 4 the computer running the script.  it will need to be changed to
                # reflect your settings
                client = ModbusClient(method='rtu', port='COM4', stopbits=1, parity='O', timeout=1, baudrate=9600)
                # this connects to the ViewMarq
                client.connect()
                # the next few lines builds out the packet to the ViewMarq and add a CR to the end
                builder = BinaryPayloadBuilder(byteorder=Endian.Big, wordorder=Endian.Big)
                builder.add_string(inittext)
                builder.add_string('\r')
                payload = builder.build()
                # this is the line that actully sends the packet to the ViewMarq
                client.write_registers(10999, payload, skip_encode=True, unit=UNIT)
                # this closes the connection to the ViewMarq
                client.close()
            
            
            # this checks that we opened the script directly and that it wasn't opened from another script
            if __name__ == "__main__":
                run_sync_client()

            Comment



            • #7
              I doubt that I could make use of it, but it is always nice to add another cat-skinning tool to the arsenal!
              Thanks

              Comment



              • #8
                Not a problem.

                It has more use than just writing to a ViewMarq. With a few minor changes it can take any .txt or .csv updated by an external source and parse out the useful data and send it out over modbus RTU or TCP for use in any device that speaks modbus.

                our IT department works in .txt and .csv files to get relevant data out of there systems. I plan on using a similar script to get material specs on the next product to run on the machine and have the machines auto setup to the correct recipe and set the specs and tolerances in our SPC systems.

                Comment

                Working...
                X