Display ASCII

Discuss issues and ideas you have to configuring displays with PowerVision
snussbaum
Posts: 28
Joined: Thu Jul 07, 2011 12:17 pm

Display ASCII

Post by snussbaum » Tue Aug 02, 2011 4:21 pm

I need my PV450 to be able read a modbus word that contains two ascii characters and display these characters on the screen. Also need to edit the same and send out to the slave.
I am not a savvy script writer so I need real fundamental help here.
Thanks.
Steve
ksaenz
Enovation Controls Development
Enovation Controls Development
Posts: 263
Joined: Thu Aug 19, 2010 7:53 am

Re: Display ASCII

Post by ksaenz » Wed Aug 03, 2011 9:03 am

Hello snussbaum,

You can use a script like the one in the attached sample configuration to put the ASCII values in a string and put that string in a text widget.

The configuration uses the "fire on change" option in the database variables to run the script when the numeric values change.

You can change the numeric values using the two top buttons on either side.

Regards,

ksaenz
Attachments
ASCII.zip
(1.95 MiB) Downloaded 26 times
mbowdich
Posts: 209
Joined: Tue Oct 05, 2010 10:54 am

Re: Display ASCII

Post by mbowdich » Wed Aug 03, 2011 9:33 am

Attached is an example that reads in the Modbus register 40001 from slave 1, shows the characters on the screen, allows changes, and sends out to the Modbus register 40001 on slave 2. It can be changed easily to work with a single slave and any register.

It is written for the PV750, but you should be able to change it to the PV450 once it is open.
Attachments
ModbusASCII.zip
(1.96 MiB) Downloaded 19 times
snussbaum
Posts: 28
Joined: Thu Jul 07, 2011 12:17 pm

Re: Display ASCII

Post by snussbaum » Wed Aug 03, 2011 5:54 pm

Thank you very much ksaenz
snussbaum
Posts: 28
Joined: Thu Jul 07, 2011 12:17 pm

Re: Display ASCII

Post by snussbaum » Wed Aug 03, 2011 7:13 pm

ksaenz,
I took your config file and modified it a little and it seems to do what I need on the read side. This config reads a modbus word from my controller and then I use a button to call the calc event to set char1 equal to the modbus word assuming it will truncate the upper byte and leave the lower byte in char1. For the upper byte I just divided the modbus word by 256 and equated that to char2. Seems like a brut force method but I don't see how to manipulate bytes in the PV 2.2. If this is a reasonable approach I will pursue it further. Are char1 and char2 in the database 16bit int or shorts (byte)?
snussbaum
Attachments
ASCII_A.zip
(1.96 MiB) Downloaded 11 times
ksaenz
Enovation Controls Development
Enovation Controls Development
Posts: 263
Joined: Thu Aug 19, 2010 7:53 am

Re: Display ASCII

Post by ksaenz » Thu Aug 04, 2011 7:57 am

snussbaum,

Database variables are doubles and your modbus word is also a database variable so you don't need to copy it to char1 and char2, you can read it directly and separate the bits like this:

Code: Select all

void $EventName ()
{
	//integer variables to hold the numberic values
	uint readASCII;
		
	//string variable to hod the ASCII characters
	string myString = "--";
	
	//read values from database variables
	smRead( smGetHandle("Modbus.MPI-8/16.40149.read ascii"), readASCII );
	
	//put the values in the string
	myString[0] = 0xFF & readASCII;
	myString[1] = 0xFF & ( readASCII >> 8 );
	
	//put text into the text widget
	setTextWidgetText(ScreenObjectID("modbus Text Widget"), myString);
	processScreenApi(); //force the screen to redraw
	
}
If you do this remember to set the "fire on change" in the modbus variable to run the script.

You can also look at mbowdich's example for ideas.

Regards,

ksaenz
snussbaum
Posts: 28
Joined: Thu Jul 07, 2011 12:17 pm

Re: Display ASCII

Post by snussbaum » Thu Aug 04, 2011 5:18 pm

ksaenz,
Thanks for the help, I see what you did and it makes sense to me.
Steve
snussbaum
Posts: 28
Joined: Thu Jul 07, 2011 12:17 pm

Re: Display ASCII

Post by snussbaum » Sat Aug 20, 2011 11:04 am

Kasaenz,
I was able to use elements of your code and can read/edit/write 16 ascii params. Thanks for the support. Now that I have these 16 text widgets displaying ascii chars I want to use them on several pages(views). As a test, I copied and pasted one of the widgets to the same page and I only see that the ascii char shows on the original widget, not on the second added one. The second widget shows the default text I put in the text box so I could better spot the widget on the page. How can I display a text widget in multiple locations? Thanks in advance for your help.
snussbaum
ksaenz
Enovation Controls Development
Enovation Controls Development
Posts: 263
Joined: Thu Aug 19, 2010 7:53 am

Re: Display ASCII

Post by ksaenz » Mon Aug 22, 2011 7:48 am

Snussbaum,

The bad news is that setTextWidgetText() sets the text of a specific text widget, so if you want the same text in different widgets you need multiple calls of setTextWidgetText().

The good news is that version 2.3 of PowerVision Studio introduces string variables, so you'll simply need to change the value in the variable and all the widgets reading that variable will change their text.

Regards,

ksaenz
snussbaum
Posts: 28
Joined: Thu Jul 07, 2011 12:17 pm

Re: Display ASCII

Post by snussbaum » Mon Aug 22, 2011 7:06 pm

Ksaenz,
Thanks for your response. At least I can do in 2.2 so that's good. I haven't migrated over to 2.3. yet. I'm not sure when I will, I would like to get to point in the task where I am a little more confident and competent on 2.2.
snussbaum
snussbaum
Posts: 28
Joined: Thu Jul 07, 2011 12:17 pm

Re: Display ASCII

Post by snussbaum » Tue Aug 23, 2011 1:28 pm

Ksaenz,
The ascii scripting is working fine but I need to refine it a bit. The characters required are limited to 0-9,space,L,R. These are used for depicting an engine's firing order. Can you provide some script code for accompishing this? Thanks again for your help.
snussbaum
ksaenz
Enovation Controls Development
Enovation Controls Development
Posts: 263
Joined: Thu Aug 19, 2010 7:53 am

Re: Display ASCII

Post by ksaenz » Wed Aug 24, 2011 7:35 am

Snussbaum,

I can help but I don't understand well which changes need to be made.
Can you decribe it a little more?

Thank you,

ksaenz
snussbaum
Posts: 28
Joined: Thu Jul 07, 2011 12:17 pm

Re: Display ASCII

Post by snussbaum » Wed Aug 24, 2011 4:15 pm

ksaenz, thanks for the response. I can explain further. As the user edits the characters he will want to select or enter a single char from the following small set of chars, namelly the numerals 0-9, the space char and two chars "L" and "R". For example, he may want to load a modbus register with the char pair "1L". He uses a pair of keys to scroll through the registers shown on the screen until he highlight box covers the char to edit. Then he uses a different pair of keys to scroll up or down through the ascii field. If the char highlighted is a "9" for example, he has to scroll through many chars to get to the letter "L". So to speed this up I want to got directly from the "9" to the "L" and next the letter "R". Just to save the time and aggivation of scrolling through chars he'll never need.
So the full range of the scrolling sequence would be: " ","1","2"..."9","L","R"," ","1".....

I hope this helps.
snussbaum
ksaenz
Enovation Controls Development
Enovation Controls Development
Posts: 263
Joined: Thu Aug 19, 2010 7:53 am

Re: Display ASCII

Post by ksaenz » Fri Aug 26, 2011 8:09 am

I understand now, you want to limit the characters the user can use.

My suggestion is to make an array of the allowed ASCII values and cycle through that sub-set of values.

Array

Code: Select all

uint[] myASCII = {32,48,49,50,51,52,53,54,55,56,57,76,82};
Calculation events

Code: Select all

mod("char1"+1,13)
mod("char1"-1,13)
Assignment

Code: Select all

myString[x] = myASCII[char1];
Regards,

ksaenz