Closed cymplecy closed 5 years ago
Maybe get it to return a buffer of length 1 ?
@cymplecy
I have introduced the byte-block to have control over the values inside a buffer:
Indeed a buffer consists of a series of byte values. Each value of the buffer is between 0x00 and 0xFF (hex) OR 0 and 255 (decimal): see documentation. Therefore you can only enter number values between 0 and 255 in the byte-block...
An example flow:
[{"id":"da21f21b.aaf46","type":"function","z":"279b8956.27dfe6","name":"","func":"msg.payload = new Buffer([ 0, 6, 7, 5, 0, 255, 256, 257, 258]);\nreturn msg;","outputs":1,"noerr":0,"x":3720,"y":320,"wires":[["d5e89ebd.c0475"]]},{"id":"f4c54da1.da58d","type":"inject","z":"279b8956.27dfe6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3560,"y":320,"wires":[["da21f21b.aaf46"]]},{"id":"d5e89ebd.c0475","type":"debug","z":"279b8956.27dfe6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":3870,"y":320,"wires":[]}]
In this flow, a buffer is created from an array of byte values (i.e. numbers!!!):
msg.payload = new Buffer([ 0, 6, 7, 5, 0, 255, 256, 257, 258]);
return msg;
In the debug panel you will see that he starts counting again from 0 when you specify as value 256:
P.S. I had also planned to create a hex-block in the future:
Does this make sense to you ?? Otherwise it might be better to discuss this on the forum ...
Bart
My point is that it returns 13 when Blockly convert it to JS whereas I think it should convert it to a 1 byte buffer object
e.g
should return something like
cr = new buffer([13]);
not
cr= 13;
Well my point is that I have introduced the buffer block to have control about which values can be set in a buffer at index X. For example:
myBuffer[15] = 33;
This is very handy when you do e.g. image processing, like I use it heavily in my node-red-contrib-multipart-stream-decoder node ...
When we would do it your way it would become this:
myBuffer[15] = new Buffer([33]);
This would mean that each element in myBuffer would be another buffer containing only a single number. A byte is just a byte, nothing more nothing less. Correct me if I'm wrong !
Well my point is that I have introduced the (I think you meant to say byte not buffer here) buffer block to have control about which values can be set in a buffer at index X. For example:
myBuffer[15] = 33; Doesn't need a byte type to do that - you just take simple number block and convert to your JS
When we would do it your way it would become this:
myBuffer[15] = new Buffer([33]);
I'm not asking for this - I'm asking that if I set a variable to a byte with a value of 13 - that it sets the variable to a buffer, length 1, with a value of 13 in it.
At the moment, its ignoring my instructions that I'm using a byte and converts it (in error) to an integer with a value of 13
A byte is just a byte, nothing more nothing less. Correct me if I'm wrong !
No - your are right with that paragraph
IM(H)O
Get byte should return a buffer object length 1
Byte 13 should return buffer([13]) not 13
Maybe change get/set to
set value of index 1 of buffer empty buffer to 0
get value at index 1 of buffer empty buffer
Closing this issue and restarting the discussion from a different angle :)
returns
cr = 13;
but should be JS representation of a byte or a char (I don't understand how JS deals with bytes/chars