Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hello, I am pretty new to Kepware and was hoping for some guidance. Using advanced tags or Thingworx, is there a way to convert decimal data coming from a Siemens PLC to ASCII and feed it into Thingworx? The result I need to get should read like +99.9
I was able to find a chart that shows decimal to ASCII, but I am not sure how I can make that conversion using Kepware/Thingworx.
Using the chart I have, I can see that a byte sending a 43 from the PLC should be a '+' and a 26 should be a '.' I am just not sure how to get those numbers to translate to those characters for the Thing I have created in Composer. Nothing obvious is jumping out to me using advanced tags. But I am very new to this software, so maybe the solution is very obvious? Maybe I would have to create something in Thingworx using coding? I'm not sure if it's possible or what approach to use. Thank you for your patience with me!
Solved! Go to Solution.
Within the Kepware project, you can use an Advanced Tag > Derived Tag with an output data type as a STRING, and then in the expression reference the numerical source tag.
This MIGHT work for what you need, however it is not a direct byte for byte conversion to ASCII.
Andy Servetas
Principal Technical Support Engineer | Kepware Technologies
Within the Kepware project, you can use an Advanced Tag > Derived Tag with an output data type as a STRING, and then in the expression reference the numerical source tag.
This MIGHT work for what you need, however it is not a direct byte for byte conversion to ASCII.
Andy Servetas
Principal Technical Support Engineer | Kepware Technologies
Hello,
I was able to get this to work by creating a service on a Thing in Thingworx and then putting the following code. I have changed some of my tags and inputs slightly to make them more generic, but I hope it will still translate
var params = {
infoTableName: "asciiResults" /* STRING */
};
// result: INFOTABLE
var result = Resources["InfoTableFunctions"].CreateInfoTable(params);
//Add a new field to the InfoTable:
result.AddField({name: "ADDYOUROWN", baseType: "STRING"});
result.AddField({name: "ASCIICharacterTgmFromPLC_0000", baseType: "STRING"});
// Input decimal value from PLC
var TgmFromPLC_0000FromPLC = me.TgmFromPLC_0000; // Replace this with your actual decimal value
// Convert decimal to ASCII character
var TgmFromPLC_0000asciiCharacter = String.fromCharCode(TgmFromPLC_0000FromPLC);
// Print or use the ASCII character as needed
logger.info("ASCIICharacterTgmFromPLC_0000: " + TgmFromPLC_0000asciiCharacter);
// Now 'asciiCharacter' contains the ASCII character corresponding to the decimal value from the PLC
// add data row
result.AddRow({ADDYOUROWN : me.ADDYOUROWN,
ASCIICharacterTgmFromPLC_0000 : TgmFromPLC_0000asciiCharacter,
});