Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display ASCII characters on dashboard
#1
I use IoT version to read information from an industrial HMI using Modbus. I have a name of current recipe that I need to display on the dashboard. I can read the 20 input registers and see the ACSII numbers in the variables of my Modbus connection but for the life of me I cannot figure a way to display the text on the dashboard. Was thinking of using the recipe index numbers and maintain the name lists in both the HMI and again in the IoT dashboard and use visibility on text/label widget but updates would be problematic to keep these lists synced and displaying correctly. I will also have the same issue with operator name when I get to that point. Any suggestions?
Reply
#2
Hi,
you have to add a java script code.
1. Read all the variables from the script. 
2. Convert the alues to characters
3. Create a text from the charactes.
4. Write the text to a new Variable

Please check the attached image. I have created an example.
In this example the variables V1-V5 contains the numbers 65,66,67,68,69
The result to V10 is the text: ABCDE

Code:
//--- Copy values from Virtuino Variables to JavaScript variables
var inputValue1 =+Virtuino.readValue("inputTag1");   //Read inputTag1 value as number from V1.       
var inputValue2 =+Virtuino.readValue("inputTag2");   //Read inputTag2 value as number from V2     
var inputValue3 =+Virtuino.readValue("inputTag3");   //Read inputTag3 value as number from V3     
var inputValue4 =+Virtuino.readValue("inputTag4");   //Read inputTag4 value as number from V4     
var inputValue5 =+Virtuino.readValue("inputTag5");   //Read inputTag5 value as number from V5     

//---  enter the JavaScript code like the example below

  var char1 = String.fromCharCode(inputValue1);                     
  var char2 = String.fromCharCode(inputValue2);                     
  var char3 = String.fromCharCode(inputValue3);                     
  var char4 = String.fromCharCode(inputValue4);                     
  var char5 = String.fromCharCode(inputValue5);         
  var text = char1+char2+char3+char4+char5;             
  result = '{"tag":"outputTag", "value":"'+ text+ '"}'; //  return a json message   


Attached Files Thumbnail(s)
       
Reply
#3
(12-03-2023, 08:58 PM)iliaslamprou Wrote: Hi,
you have to add a java script code.
1. Read all the variables from the script. 
2. Convert the values to characters
3. Create a text from the characters.
4. Write the text to a new Variable


Your example worked great with the input from my Modbus connection after adding another character for the word "Manual"!! This gets me started, have to learn some Javascript to find the null character "0" in the string so that the Json output will always be valid for various string lengths. I haven't coded by line since the 80s so will have to hit the books to learn. 

Thanks again!
   
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)