Taylor Turner
Member
I am not the best in python...
"What is a library?" Said structured text.
I am trying to make a simple plot by grabbing tag values from pylogix to y-axis data for pyplot.
I was hoping to store the tag values in an array in python and not the PLC by indexing a delayed for loop.
I have used excel and VB to DDERequest into incrementing rows but I don't trust the timing and it's not fast enough.
Here is some embarrassing python. The indirect addressing is incorrect and the data type for the plot must be a float() and not a "result." Initially I intended the plot being live but if more simple, defining a data set, then displaying the plot would be great too now that I'm thinking about it.
"What is a library?" Said structured text.
I am trying to make a simple plot by grabbing tag values from pylogix to y-axis data for pyplot.
I was hoping to store the tag values in an array in python and not the PLC by indexing a delayed for loop.
I have used excel and VB to DDERequest into incrementing rows but I don't trust the timing and it's not fast enough.
Here is some embarrassing python. The indirect addressing is incorrect and the data type for the plot must be a float() and not a "result." Initially I intended the plot being live but if more simple, defining a data set, then displaying the plot would be great too now that I'm thinking about it.
Code:
[COLOR=#d4d4d4][FONT=Consolas][COLOR=#569cd6]from[/COLOR][COLOR=#d4d4d4] pylogix [/COLOR][COLOR=#569cd6]import[/COLOR][COLOR=#d4d4d4] PLC[/COLOR]
[COLOR=#569cd6]import[/COLOR][COLOR=#d4d4d4] matplotlib.pyplot [/COLOR][COLOR=#569cd6]as[/COLOR][COLOR=#d4d4d4] plt[/COLOR]
[COLOR=#569cd6]import[/COLOR][COLOR=#d4d4d4] numpy [/COLOR][COLOR=#569cd6]as[/COLOR][COLOR=#d4d4d4] np[/COLOR]
[COLOR=#d4d4d4]comm = PLC()[/COLOR]
[COLOR=#d4d4d4]comm.IPAddress = [/COLOR][COLOR=#ce9178]'255.255.255.255'[/COLOR]
[COLOR=#d4d4d4]comm.ProcessorSlot = [/COLOR][COLOR=#b5cea8]0[/COLOR]
[COLOR=#6a9955]#Read single tag[/COLOR]
[COLOR=#d4d4d4]rTag = comm.Read([/COLOR][COLOR=#ce9178]'rTag'[/COLOR][COLOR=#d4d4d4])[/COLOR]
[COLOR=#569cd6]for[/COLOR][COLOR=#d4d4d4] i [/COLOR][COLOR=#569cd6]in[/COLOR][COLOR=#d4d4d4] range([/COLOR][COLOR=#b5cea8]100[/COLOR][COLOR=#d4d4d4])[/COLOR]
[COLOR=#d4d4d4] xpoints = (i)[/COLOR]
[COLOR=#d4d4d4] ypoints[i] = rTag[/COLOR]
[COLOR=#d4d4d4] plt.plot(xpoints, ypoints[i])[/COLOR]
[COLOR=#d4d4d4] plt.show()[/COLOR]
[COLOR=#d4d4d4] plt.pause([/COLOR][COLOR=#b5cea8]0.1[/COLOR][COLOR=#d4d4d4])[/COLOR]
[/FONT][/COLOR]