LREAL PLC data type in Ignition

I have a LREAL in a PLC connected to a tag in Ignition. I have this tag in ignition set as a DOUBLE thinking this data type allows the most numbers. When viewing the tag in the tag browser I see the tag correctly showing the full value (eg. 1000000028920.2305). However I want to copy this value to a csv file and with the number being so big it shows it as "1.0000000289202305E12". What can I do to show this entire value without having it convert to an exponent? Is there formatting I can do in the tag script when pulling the value or am I using the wrong data type?

Technically this is the correct number. Where are you viewing this value? This sounds less like an Ignition issue and more like a third party software configuration issue.

Correct, it is the right number. I have a script which simply reads in this value and then once a day I create a csv file with this value in it. It is showing as with the exponential part in it instead of showing me the entire 'real' value with a decimal place. I just created a simple label in my project and without applying a format transform to it it comes up with the exponential part. If I do the format transform which transform it into a number I then see the entire value. This entire value is what I want to display in my csv file, not the exponential value.

As long as you're not doing anything to change the value, I would expect it to work.

Can you show the script that you're using to read the value?

def create_totalizer_csv():
	"""Create flow totalizer csv file with current values at time of csv file creation
	
	Params:
		none
	
	Returns:
		none
	"""

	#establish logger
	logger = system.util.getLogger("Totalizer CSV file")

	##dynamically create list of flow totalizer tag paths including filter to only look at UDT instance tags and AI inputs with FT
	path = '[PLC]AnalogInputs'
	fltr = {'tagType': "UdtInstance", 'name': "*FT*"}
	tags = system.tag.browse(path,fltr)

	#get current time and format
	today = system.date.now()
	formattedTime = system.date.format(today,"MM-dd-yyyy HH:mm")

	#create custom header row
	headerTagPaths = [str(tag['fullPath']) + "/DeviceName" for tag in tags]
	  #reads in device names and creates array for header.  Inserts DATE/TIME header in first index position
	headers = ['DATE/TIME'] + [(str(header.value) + ' in CFT') for header in system.tag.readAll(headerTagPaths)]

	#populate flow totalizer data
	dataTagPaths = [str(tag['fullPath']) + "/TotalizerValue" for tag in tags]
	  #read in tag values and create array for data.  Inserts formatted time in first index position
	totalizers = [str(formattedTime)] + [data.value for data in system.tag.readAll(dataTagPaths)]

	#convert to dataset
	Totdataset = system.dataset.toDataSet(headers, [totalizers])
	
	#write dataset to dataset tag
	TotalizerdatasetTag = '[PLC]TotalizerCSV'
	system.tag.writeBlocking(TotalizerdatasetTag, Totdataset)
	logger.info("Data written to dataset tag")

	#convert dataset to csv file
	csv = system.dataset.toCSV(dataset = Totdataset, showHeaders = True)
	html = system.dataset.dataSetToHTML(True, Totdataset, 'Totalizer Values:')
	
	#define file path and populate file
	filePath = "C:\\DailyCSVFiles\\totalizer.csv"
	system.file.writeFile(filePath, csv)

	if system.file.fileExists("C:\\DailyCSVFiles\\totalizer.csv"):
		logger.info("File written to csv")
	else:
		logger.info("File does not exist!")

The line reading in the value is totalizers=

I also just created another tag within my UDT as a string and it simply takes the TotalizerValue and converts it to a string. This string value is showing up as an exponential value. This value is the same as I am seeing in my csv file.

A couple of things:

  1. formattedTime is already a String, so you shouldn't need to cast it to a string.
  2. system.tag.readAll() has been deprecated, you should be using system.tag.readBlocking()
    (NOTE: system.tag.readAll() still works, and I wouldn't expected it to stop anytime soon, but it's best practice not to use deprecated methods)

If after you generate the list of totalizers you print the list, what prints out? If you print the values from the data set, what is the value for that value, Is it different than when you created the list?

You may need to use the DatasetBuilder class to specifiy specific column types for the dataset, that could be where the conversion is happening.

Here is what I am seeing for the tag values into ignition. This is what is coming out in my csv file

image

The values are a little off because the script to create the csv ran before values changed but you get the idea

Also to your point I am writing the dataset to a dataset tag in the script. This is what I am seeing for the dataset tag. It includes the full values

It seems the dataset is then fine

Sometimes the value displays differently, based on what is interpreting it. For example:

Totdataset = system.dataset.toDataSet(headers, [totalizers])
from pprint import pprint
pprint(Totdataset.getValueAt(0, 0))
print(Totdataset.getValueAt(0, 0))

yields the value each way

1000000028920.2305
1.00000002892e+12

The only way I could get the CSV to have the correctly formatted value was to flag localization

system.dataset.toCSV(Totdataset, localized=True)

which formats it like this: "1,000,000,028,920.2305". Depending on how you're reading the CSV that may be an issue.

EDIT: This was done with readBlocking, instead of readAll. But, as always, it's best to use the most recent, supported functions.

2 Likes

Consider fixing it with formatting in the target application (Excel, whatever), to avoid losing information. LREAL carries 16 significant digits. Totalizers are notorious for needing them.

That did it! Set localized to True and then I did a round(data.value),1 to get it to one decimal place

1 Like

This is a file that will be overwritten each day. I was under the impression you could not set certain properties to the csv file through the system.dataset.toCSV function.