Hi,
I have an issue when trying to read strings written by Citect to a S7.
The Citect system is already in operation and i cannot change anything in the PLC or Citect. Citect/PSDirect uses a different approach to reading/write strings than Ignition
Citect uses the PSDirect driver.
TAG in PLC:
DB1000, offset 0, String[32]
TAG in Citect
DB1000, offset 2, String[30]
The string appears as empty in the PLC but if if monitor as an array of chars i can see the values.
I have tried reading where Ignition is configured as an OPC UA Client. The value is then returned as an empty string.
I have also tried the S7 driver at both offset 0, len 32 and offset 2, len 30. Still empty.
The only way i found is by scripting but i would prefer to have it in tags and especially OPC UA.
But this works:
def readString(plc, db, offset, length): # In order to be able to use Citect and Ignition to read the same strings at the same time we need to to this manually
opcServer = "Ignition OPC UA Server"
itemPaths = []
stringOut = ""
for i in range(length):
itemPath = "["+plc+"]"+"DB"+str(db)+",C"+str(offset+i)
print(itemPath)
itemPaths.append(itemPath)
qualifiedValues = system.opc.readValues(opcServer, itemPaths)
for qualifiedValue in qualifiedValues:
ascii = qualifiedValue.value
c = chr(ascii)
stringOut += str(c)
#print c
stringOut = stringOut.rstrip('\x00') # Removes null bytes from the right end of the string
return stringOut
def writeString(plc, db, offset, length, stringToWrite):
opcServer = "Ignition OPC UA Server"
itemPaths = []
valuesToWrite = []
# Ensure the string is exactly the length required, padded with null bytes if necessary
stringToWrite = stringToWrite.ljust(length, '\x00') # Pads with null bytes to the right
for i in range(length):
itemPath = "[" + plc + "]" + "DB" + str(db) + ",C" + str(offset + i)
#print(itemPath)
itemPaths.append(itemPath)
# Convert each character of the string to its ASCII value and append to the list
asciiValue = ord(stringToWrite[i])
valuesToWrite.append(asciiValue)
# Write all the values at once after the loop
system.opc.writeValues(opcServer, itemPaths, valuesToWrite)
# Return confirmation of the write operation
return 0