Read Siemens S1500 Date_And_Time value

I try to read a "Date_And_Time" value in PLC
image
I used the datetime tag
image
The quaility is


My colleague said they used LDT to fix the problem. But in my case, the datablock is an interface that means there will be a lot of places need to be changed if I change the type from "Date_And_Time" to LDT. So how can I fix this problem?

Hi @Xiao_Xiao,

Can you try to read the value in long and then use the fromMillis function to convert to a date ?

If you have version 8.1.29 of Ignition you should be able to read the Datetime directly. So the path will be something like DBxyz,DT102

Thank you, my ignition version is 8.1.32 and in my case the PLC is opc server and ignition is the client, so I don't use DB address to find the tag.

Hello, I have tried it. And it doesn't work

Error_TypeConversion("Cannot coerce value '[Ljava.lang.Short;@4add1b3c' into type: class java.lang.Long")

Hi,
If you use OPC UA. You can browse the PLC opc server and import the tag in Ignition. Does that give you also and error ?

Of course, I have done it


But it doen't work.

I was thinking like that.
image


Browse until you find the correct tag and use the arrow to import into ignition. This will create the tag and use the correct data type (if supported). Because with your method, maybe the dateTime data type is not the one you need to use. I don't have a siemens plc running for the moment so i cannot test it by myself.

Follow you steps, I can read the data as short array. But I have no idea how to deal with these shorts......
image
I try to convert these as bit array then convert to datetime, but the date show 987-03-04.....

This is for C# but you can check if it's possible to implement it in Pyhon

hi @Xiao_Xiao ,

#Tagpath datetime Array[8]
tagPaths = '[default]var'
#read value
results=system.tag.readBlocking(tagPaths)
#Check if results
if len(results)>0:
	#Extract value for year
	val = results[0].value[0]
	year = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Check if value is 21th century
	if year <90:
		year +=2000
	else:
		year += 1900
	#Extract value for month
	val = results[0].value[1]
	month = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Extract value for day
	val = results[0].value[2]
	day = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Extract value for hour
	val = results[0].value[3]
	hour = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Extract value for minute
	val = results[0].value[4]
	min = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Extract value for seconds
	val = results[0].value[5]
	sec = ((val & 0xf0) / 16)*10 + (val & 0xf)

	#Convert to time
	from java.util import Calendar
	cal = Calendar.getInstance()
	cal.set(year, month-1, day, hour, min, sec)
	print cal.getTime()

This is a quick code i writed in the script console. It should be quite easy to adapt it for your use. This allow only to read from the PLC not to write back.

Regards

1 Like

The Siemens OPC UA server does not model Date_And_Time types as OPC UA DateTime values, but rather as the internal byte array value.

My generous guess as to why is that this value is essentially a date/time string, pre-rendered, with no fixed timezone or epoch associated with it, so they can't convert it to a UTC DateTime value without potentially converting the value to a different time than was intended.

Its been a while, on a project a few years ago, I managed to find this UDT someone made, and got it working for reading and writing to that data type. Not sure if it will fit your use case.