Lists with strings PV2.8

Discuss issues and ideas you have to configuring displays with PowerVision
ADE
Posts: 18
Joined: Mon Oct 06, 2014 7:00 pm

Lists with strings PV2.8

Post by ADE » Mon Apr 04, 2016 8:30 pm

Hey All,

So I attempting to get lists to work in power vision 2.8 as i noticed that it looks like you can save lists to survive power cycles and updates so it look like a useful way to keep a record of users that have logged into the screen recently. Anyways I have been attempting to populate the list but so far i am unable to read(or maybe I haven't successfully written to the list) string values, but i can read ints fine. I have attached my code, it is based on sample code, that worked in 2.7 so I'm not sure if I am just missing something or if there are differences between 1.7 to 1.8 which Im not taking into account. If anyone could have a look over this code and let me know if they can see any issues? I run the CreateEntries method first and then run SetupUserLoginPage method after. I have also attached how I have set up the list.

Code: Select all

int Position;
int MaxItems = 4;
string [] itemStrings =
{
	"Oil Pressure",
	"RPMS",
	"Engine Temp",
	"Batt Volts",
};
void CreateEntries(){

	CustomListData data;
	smWrite(VariableIDs.testPhaseFlag, 1);
	// Only do this one time.
	if (ListManagerGetCount(ListDataType.RecentUsersList) < 1)
	{
		for (int index = 0; index < MaxItems; index++)
		{
			data.WriteInt32(CustomListColumn.RecentUsersList_UserIDs, index);
			data.WriteString(CustomListColumn.RecentUsersList_UserNames, itemStrings[index]);
			
			if (ListManagerAddItem(ListDataType.RecentUsersList, data) < 0)
			{
				// This should let the user know or developer know...
				smWrite(VariableIDs.testPhaseFlag, 3);
				break;
			}else{
				smWrite(VariableIDs.testPhaseFlag, 2);
			}
			ListManagerNext(ListDataType.RecentUsersList, false);
		}
		
		Position = 0;
		ListManagerSetPosition(ListDataType.RecentUsersList, Position);
	}
}

void SetupUserLoginPage(){
	smWrite(VariableIDs.WhichPassword, USER_LOGIN);
	
	CustomListData userLists;
	string userID = 'empty';
	int tempInt;
	ListManagerSetPosition(ListDataType.RecentUsersList, 0);
	ListManagerGetItem(ListDataType.RecentUsersList, 0, userLists);
	userLists.ReadString(CustomListColumn.RecentUsersList_UserNames, userID);
	Print("Name: " + userID);
	cultureSetString(StringIDs.UserOne, userID, true);
	setTextWidgetText(ScreenObjectIDs.lblUserNameOne, userID);
	tempInt = userLists.ReadInt32(CustomListColumn.RecentUsersList_UserIDs);
	userID =  tempInt + "";
	setTextWidgetText(ScreenObjectIDs.lblUserIDOne, userID);
	cultureSetString(StringIDs.UserIDOne, userID, true);
	Print("ID: " + userID);
	
	ListManagerGetItem(ListDataType.RecentUsersList, 1, userLists);
	userLists.ReadString(CustomListColumn.RecentUsersList_UserNames, userID);
	setTextWidgetText(ScreenObjectIDs.lblUserNameTwo, userID);
	Print("Name2: " + userID);
	tempInt = userLists.ReadInt32(CustomListColumn.RecentUsersList_UserIDs);
	userID =  tempInt + "";
	setTextWidgetText(ScreenObjectIDs.lblUserIDTwo, userID);
	Print("ID2: " + userID);
	
	ListManagerGetItem(ListDataType.RecentUsersList, 2, userLists);
	userLists.ReadString(CustomListColumn.RecentUsersList_UserNames, userID);
	setTextWidgetText(ScreenObjectIDs.lblUserNameThree, userID);
	Print("Name3: " + userID);
	tempInt = userLists.ReadInt32(CustomListColumn.RecentUsersList_UserIDs);
	userID =  tempInt + "";
	setTextWidgetText(ScreenObjectIDs.lblUserIDThree, userID);
	Print("ID3: " + userID);
	processScreenApi();
}

PowerVision: 2.8.10365
Screen: PV450
OS: 2.8.10014
App: 2.8.10441
Loader: 2.3.20006
Windows: 7 Professional SP1.
Attachments
ListSetup.PNG
ListSetup.PNG (14.46 KiB) Viewed 145 times
stalley
Enovation Controls Development
Enovation Controls Development
Posts: 618
Joined: Tue Mar 18, 2014 12:57 pm

Re: Lists with strings PV2.8

Post by stalley » Tue Apr 05, 2016 9:26 am

Greetings ADE,

The first thing I see is the use of the setTextWidgetText(). These don't work as expected. You should use the cultureSetString() to display strings.

Be sure to use the Compile All Scripts button. The Create does not compile the scripts, so if you only do create, you won't really know. Compiles are done on the displays.

The major thing I found is that the first column in a List needs to be an int32. When I swapped the columns, it worked. Who knew! I didn't see any documentation that tells me that! I just tried it and it seemed to work.

Also, I think you are overwriting the UserName with the UserID. I think you want to do something like this

Code: Select all

userID += " " + tempInt;
I think you are close to getting it working!
Sara Talley
Software Engineer
Enovation Controls
ADE
Posts: 18
Joined: Mon Oct 06, 2014 7:00 pm

Re: Lists with strings PV2.8

Post by ADE » Tue Apr 05, 2016 9:27 pm

Hey Sara,

Thanks for your response. Changing the order of list so the int32 was first in the list did the trick. Cant say I thought to do that.

You mentioned that the setTextWidgetText() doesnt work as expected, what did you mean by this? It appears to change the text on the screen is is more efficient or reliable to have an overwrite string tied to text widgets and then write to this string?

Also with the writing over the userName that was actually just poorly named variable names, as this was more test code to see how things worked and I hadn't yet structured my code well.

Sincerely,

Michael

Ps Im still waiting on some parts to test the odd logging issue we were having.
ADE
Posts: 18
Joined: Mon Oct 06, 2014 7:00 pm

Re: Lists with strings PV2.8

Post by ADE » Wed Apr 06, 2016 1:13 am

Just posting for anyone who may find this issue as well.

It would appear that there is some sort of issue with whatever value you enter into a list first. I am unable to change this value regardless of if it is a string value or a 32 bit integer.
stalley
Enovation Controls Development
Enovation Controls Development
Posts: 618
Joined: Tue Mar 18, 2014 12:57 pm

Re: Lists with strings PV2.8

Post by stalley » Wed Apr 06, 2016 7:18 am

Hello ADE,

The setTextWidgetText() has an underlying inconsistency that it writes directly to an object on the screen. Other widgets display values from variables, like the text gauge widgets display the value of a numeric variable. Using the cultureStringSetString(), text widgets display the value of reserved string variables.

The setTextWidgetText() is only there for backwards compatibility. As I mentioned it doesn't always work as expected either. I have seen it display only part of the string written to it or every other character, strange things. I strongly recommend not using the setTextWidgetText(), we are no longer supporting it's use.

If you can tell us how to reproduce the problem you have of not being able to write to the first item in the list, I will take a look at it. I am anxious to help make PowerVision Configuration Studio as reliable as possible!

Thanks,
Sara Talley
Software Engineer
Enovation Controls