#!/usr/bin/python #05aug2022 edited file path for etabs # and placed it in ~/linuxcnc/nc_files NOT liuxcnc-dev # # located in ~/linuxcnc/nc_files ELSE YOUR BEING FOOLED # M122, test reading EtabUNS given M122 P999999xx Qnn # prints out the etab data from file, on line Qnn # TODO: assign values to hardware devices # before assigning, the containers must exist import sys, subprocess # next is where you keep your etabs ncfileprefix="/home/tomp/linuxcnc-dev/tomp/etabs4haledm/" ns=(sys.argv)[1] nf=float(ns) etabnum=int(nf) etabname=ncfileprefix+(str(etabnum))+(".ENC") # ns is better called nr as in the NR field of database ns=(sys.argv)[2] nf=float(ns) ni=int(nf) # if i said m122 P99999932 Q25, i'd want the 1st data line which is 2nd line of file, but index #25, so 25 becomes 2 EtabNR=27-ni # i want talk 'like' gimme nr 25 and get 2nd line from file, so i ask for 25 ( pass 25 ) and calc the index like so: 27-25 = 2 fhndl=open(etabname, 'r') econds=fhndl.readlines() fhndl.close() # fields in etab file NR IP HV GV ON OFF SV AJD ET AR P NA VE RA VW RAD STPA CODE BXGV ISO XJMP AUX5 AUX6 # fields used on 1st gladevcp NR IPk On Off Rad Pol TCut TJump # indices 0 1 4 5 15 10 7 8 ns = str.split(econds[EtabNR])[0] nf = float(ns) NR = int(nf) ns = str.split(econds[EtabNR])[1] nf = float(ns) IPk = int(nf) ns = str.split(econds[EtabNR])[4] nf = float(ns) nf = nf * 4 OnT = int(nf) ns = str.split(econds[EtabNR])[5] nf = float(ns) nf = nf * 4 OfT = int(nf) ns = str.split(econds[EtabNR])[15] Rad = float(ns) ns = str.split(econds[EtabNR])[10] nf = float(ns) Pol = int(nf) ns = str.split(econds[EtabNR])[7] TCut = float(ns) ns = str.split(econds[EtabNR])[8] TJump = float(ns) # only for etab line 2 which is RawRad Rad = RawRad - 2.54 # this macro only prints the data set asked for, # it does parse out the pieces of data on the line # TODO set real hardware using the lookedup data print "Epack ",etabnum," Econd ",NR," Ipeak ", IPk," On ", OnT," Off ", OfT," Rad ", Rad, " Pol ", Pol, " TCut ", TCut, " TJump ", TJump # EOF