# ILD file to Json

**URL:** <https://discourse.nodered.org/t/ild-file-to-json/38272>\
**Category:** General\
**Created:** [30 December 2020 10:42 UTC](https://discourse.nodered.org/t/ild-file-to-json/38272 "2020-12-30T10:42:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schotte2360](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@Schotte2360](https://discourse.nodered.org/u/Schotte2360)\
**Post date:** [30 December 2020 10:42 UTC](https://discourse.nodered.org/t/ild-file-to-json/38272/1 "2020-12-30T10:42:52Z")

</div>

I am designing an RGB LASER system controlled with an RPI 3B + and Node-Red.  
On the internet I found '[https://github.com/possan/ilda.js/tree/master](https://github.com/possan/ilda.js/tree/master)'

Can someone help me further?

 ![2020-12-30_113239](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/37ff9856163d71df197e75baf98a524455142dca.jpeg)

This is in the function node:

```auto
var file = msg.payload;
var back = {};
var ArrayReader = function(bytes) {
	this.bytes = bytes || [];
	this.position = 0;
	this.length = this.bytes.length;
}

ArrayReader.prototype.seek = function(p) {
	this.position = p;
}

ArrayReader.prototype.eof = function() {
	return this.position >= this.length;
}

ArrayReader.prototype.readString = function(length) {
	var s = '';
	for(var i=0; i<length; i++) {	
		var b0 = this.readByte();
		if (b0 > 0 && b0 < 0x7F)
			s += String.fromCharCode(b0);
	}
	return s.trim();
}

ArrayReader.prototype.readByte = function() {
	var b = this.bytes[this.position];
	this.position ++;
	return b;
}

ArrayReader.prototype.readShort = function() {
	var b0 = this.readByte();
	var b1 = this.readByte();
	return (b0 << 8) + b1;
}

ArrayReader.prototype.readSignedShort = function() {
	var b0 = this.readByte();
	var b1 = this.readByte();
	var s = (b0 << 8) + b1;
	if (s > 32768)
		s = -(65535-s);
	return s;
}

ArrayReader.prototype.readLong = function() {
	var b0 = this.readByte();
	var b1 = this.readByte();
	var b2 = this.readByte();
	var b3 = this.readByte();
	return b3 + (b2<<8) + (b1<<16) + (b0<<24);
}

var Reader = {};

Reader.fromByteArray = function(arr, callback) {
	var i;
	var f = msg.payload;//new File();
	var p = new ArrayReader(arr);
	while (!p.eof()) {
		// read frame.
		var head = p.readString(4);
		if (head != 'ILDA')
		 	break;
		var section = new Section();
		section.type = p.readLong();
		switch(section.type) {
			case SectionTypes.THREE_DIMENSIONAL:
				// 3D frame
				section.name = p.readString(8);
				section.company = p.readString(8);
				var np = p.readShort();
				section.index = p.readShort();
				section.total = p.readShort();
				section.head = p.readByte();
				p.readByte();
				for (var i=0; i<np; i++) {
					var point = new Point();
					point.x = p.readSignedShort();
					point.y = p.readSignedShort();
					point.z = p.readSignedShort();
					var st = p.readShort();
					point.color = (st >> 0) & 0x7F; 
					point.blanking = (st & BlankingBit) == BlankingBit;
					point.last = (st & LastBit) == LastBit;
					section.points.push(point);
				}
				break;
			case SectionTypes.TWO_DIMENSIONAL:
				// 2D frame
				section.name = p.readString(8);
				section.company = p.readString(8);
				var np = p.readShort();
				section.index = p.readShort();
				section.total = p.readShort();
				section.head = p.readByte();
				p.readByte();
				for (var i=0; i<np; i++) {
					var point = new Point();
					point.x = p.readSignedShort();
					point.y = p.readSignedShort();
					var st = p.readShort();
					point.color = (st >> 0) & 0x7F; 
					point.blanking = (st & BlankingBit) == BlankingBit;
					point.last = (st & LastBit) == LastBit;
					section.points.push(point);
				}
				break;
			case SectionTypes.COLOR_TABLE:
				// color table
				section.name = p.readString(8);
				section.company = p.readString(8);
				var np = p.readShort();
				section.index = p.readShort();
				p.readByte();
				p.readByte();
				section.head = p.readByte();
				p.readByte();
				for (var i=0; i<np; i++) {
					var color = new Color();
					color.r = p.readByte();
					color.g = p.readByte();
					color.b = p.readByte();
					section.colors.push(color);
				}
				break;
			case SectionTypes.TRUECOLOR_TABLE:
				// truecolor points
				var _len = p.readLong();
				var np = p.readLong();
				for(var i=0; i<np; i++) {
					var color = new Color();
					color.r = p.readByte();
					color.g = p.readByte();
					color.b = p.readByte();
					section.colors.push(color);
				}
					break;
		}
		f.sections.push(section);
	}
	callback(f);
};

msg.payload = reader(file);
return msg;

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [30 December 2020 11:20 UTC](https://discourse.nodered.org/t/ild-file-to-json/38272/2 "2020-12-30T11:20:44Z")

</div>

> [@Schotte2360](#):
>
> `msg.payload = reader(file);`

Hint: Case will always get you -now go look at the error message and your code

---

<div class="post-metadata">

**Author:** ![Schotte2360](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@Schotte2360](https://discourse.nodered.org/u/Schotte2360)\
**Post date:** [30 December 2020 11:26 UTC](https://discourse.nodered.org/t/ild-file-to-json/38272/3 "2020-12-30T11:26:39Z")

</div>

Stupid of me.  
I modified that line, but now I get the following error: 'TypeError: Reader is not a function'

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [30 December 2020 11:29 UTC](https://discourse.nodered.org/t/ild-file-to-json/38272/4 "2020-12-30T11:29:17Z")

</div>

what are you trying to return? using  
`msg.payload = Reader(file);`  
is saying 'set msg.payload to the value returned by the function `Reader` that is being sent what is in the variable `file`

---

<div class="post-metadata">

**Author:** ![Schotte2360](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@Schotte2360](https://discourse.nodered.org/u/Schotte2360)\
**Post date:** [30 December 2020 12:06 UTC](https://discourse.nodered.org/t/ild-file-to-json/38272/5 "2020-12-30T12:06:54Z")

</div>

The intention is to convert from the ILD file to JSON file, classified point by point with data x, y, r, g, b

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 February 2021 12:06 UTC](https://discourse.nodered.org/t/ild-file-to-json/38272/6 "2021-02-28T12:06:58Z")

</div>

Closed on 28 February 2021 12:06 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
