I think I got it now.
I found that there was "a gap" in the value table for code128 compared to the ascii-table.
The code below is used in a function node and as input in msg.payload it takes a string.
Output msg.payload is a string that when displayed with font code128.ttf displays a code 128 barcode of type B.
kod = msg.payload.toString();
checksum = 104;
for (t=0; t<kod.length; t++)
{
value = kod.charCodeAt(t) -32;
checksum = checksum + (value * (t+1));
}
checksum = checksum % 103;
checksumChar = checksum + 32;
if (checksumChar > 126)
{
checksumChar = checksumChar + 68;
}
result = String.fromCharCode(204);
result = result + kod + String.fromCharCode(checksumChar) + String.fromCharCode(206);
msg.payload = result;
return msg;
Sample Flow:
(You need code128.ttf font installed on the machine viewing the dashboard).
[{"id":"95c4ed88.b5109","type":"function","z":"e11eeb25.55a068","name":"To Code 128","func":"kod = msg.payload.toString();\nchecksum = 104;\nfor (t=0; t<kod.length; t++)\n{\n value = kod.charCodeAt(t) -32;\n checksum = checksum + (value * (t+1));\n}\nchecksum = checksum % 103;\nchecksumChar = checksum + 32;\nif (checksumChar > 126)\n {\n checksumChar = checksumChar + 68;\n }\nresult = String.fromCharCode(204);\nresult = result + kod + String.fromCharCode(checksumChar) + String.fromCharCode(206);\nmsg.payload = result;\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":960,"wires":[["335868bd.1408c8"]]},{"id":"335868bd.1408c8","type":"ui_template","z":"e11eeb25.55a068","group":"534a47c2.a947d8","name":"","order":0,"width":"6","height":"6","format":"<style>\n .bar\n {\n font-family: 'code 128';\n font-size: 60px;\n }\n</style>\n<div class = 'bar' ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":420,"y":960,"wires":[[]]},{"id":"9ec1e58e.a48c18","type":"ui_text_input","z":"e11eeb25.55a068","name":"","label":"","tooltip":"","group":"efe50b8a.7ad188","order":0,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":100,"y":960,"wires":[["95c4ed88.b5109"]]},{"id":"534a47c2.a947d8","type":"ui_group","z":"","name":"Barcode","tab":"fd476524.098798","disp":true,"width":"6","collapse":false},{"id":"efe50b8a.7ad188","type":"ui_group","z":"","name":"Testar","tab":"fd476524.098798","disp":true,"width":"6","collapse":false},{"id":"fd476524.098798","type":"ui_tab","z":"","name":"Testar","icon":"dashboard","disabled":false,"hidden":false}]