Domanda

I need to know that it's possible to create CSV file by giving an input not from an other CSV. I have a python script that allow me to read Data Memory from plc giving me a print output. I need to know if it's possible to create CSV file by giving an input like this:

  def main( ):
         plc = OmronPLC( )
         print plc.openFins('ip_address', port)
         print plc.readMemC('D2000', 2)
         print plc.readMemC('D2005', 5)
         plc.close ( )

  if __name__ == "__main__":
         main()

  import csv
  with open ('test.csv', 'w') as fp:
         a = csv.writer(fp, delimiter=',')
         data = [ main( ) ]
         a.writerows(data)

That's a piece of script that read Data Memory from a plc. When launch this script in monitor giving me the output data, but when try to create a CSV File the output in csv file is ""

From plc read the values ​​of the data memory expressed in numbers, then I try to create a CSV like this:

12, 3
25, 54
44, 555

The output when script print to monitor value is like this:

[12, 3,]
[12, 4, 54, 44, 555]

How can I have input data from that definition?

È stato utile?

Soluzione

The main() function as you have written should return the list of values to be written to the CSV file. For e.g.

def main( ):
    plc = OmronPLC( )
    ip = plc.openFins('ip_address', port)
    d2000 = plc.readMemC('D2000', 2)
    d2005 = plc.readMemC('D2005', 5)
    plc.close ( )
    print ip, d2000, d2005
    return [ip, d2000, d2005]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top