Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
I need to get a 2D matrix barcode data from a PLC and split them into date, time, part number, cavity number, etc. and then save them into the database. Is it possible to do so?
Solved! Go to Solution.
Hi @dawnman
Please use the below code to split values from a string
var sampleString = 'EBABC23192124466BB68 10C700 AC';
var firstValue = sampleString.substring(0,5);
var secondValue = parseInt(sampleString.substring(5,10));
var thirdValue = parseInt(sampleString.substring(10,11));
var fourthValue = parseInt(sampleString.substring(11,12));
var fifthValue = parseInt(sampleString.substring(12,16));
var sixthValue= sampleString.substring(16);
I would recommend changing the PLC output. While constructing a string use delimiter/separator to separate each data.
For example: In Sample Value - 'EBABC-23192-1-2-4466-BB68 10C700 AC' each value is separated by the symbol '-'. It will avoid parsing/splitting errors when each value length grows in the future and it is simpler to split values in code
Something like this :
var sampleString = 'EBABC-23192-1-2-4466-BB68 10C700 AC';
var valueArray = sampleString.split("-");
var result = valueArray;
/VR
Hi @dawnman
Yes, you can split the string and write back to DB.
Could you please post a sample format
/VR
Hi @dawnman
Please use the below code to split values from a string
var sampleString = 'EBABC23192124466BB68 10C700 AC';
var firstValue = sampleString.substring(0,5);
var secondValue = parseInt(sampleString.substring(5,10));
var thirdValue = parseInt(sampleString.substring(10,11));
var fourthValue = parseInt(sampleString.substring(11,12));
var fifthValue = parseInt(sampleString.substring(12,16));
var sixthValue= sampleString.substring(16);
I would recommend changing the PLC output. While constructing a string use delimiter/separator to separate each data.
For example: In Sample Value - 'EBABC-23192-1-2-4466-BB68 10C700 AC' each value is separated by the symbol '-'. It will avoid parsing/splitting errors when each value length grows in the future and it is simpler to split values in code
Something like this :
var sampleString = 'EBABC-23192-1-2-4466-BB68 10C700 AC';
var valueArray = sampleString.split("-");
var result = valueArray;
/VR