{"action":"created","issue":{"url":"https://api.github.com/repos/openhab/openhab/issues/2382","labels_url":"https://api.github.com/repos/openhab/openhab/issues/2382/labels{/name}","comments_url":"https://api.github.com/repos/openhab/openhab/issues/2382/comments","events_url":"https://api.github.com/repos/openhab/openhab/issues/2382/events","html_url":"https://github.com/openhab/openhab/issues/2382","id":65083249,"number":2382,"title":"Working with raw byte data from binding","user":{"login":"tertuis","id":11636364,"avatar_url":"https://avatars.githubusercontent.com/u/11636364?v=3","gravatar_id":"","url":"https://api.github.com/users/tertuis","html_url":"https://github.com/tertuis","followers_url":"https://api.github.com/users/tertuis/followers","following_url":"https://api.github.com/users/tertuis/following{/other_user}","gists_url":"https://api.github.com/users/tertuis/gists{/gist_id}","starred_url":"https://api.github.com/users/tertuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tertuis/subscriptions","organizations_url":"https://api.github.com/users/tertuis/orgs","repos_url":"https://api.github.com/users/tertuis/repos","events_url":"https://api.github.com/users/tertuis/events{/privacy}","received_events_url":"https://api.github.com/users/tertuis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-29T18:22:33Z","updated_at":"2015-04-03T22:39:17Z","closed_at":null,"body":"Hi All\r\n\r\nI'm trying to work directly with the bytes received from a serial link. I got to the point of representing the received messages as bytes, i.e. item.state.toString.getBytes() will look like [-17, -65, -67, 20, 15, 3, 27]. My instance just has about 100 entries at a time.\r\n\r\nThe problem is now working with this byte array. I need to find the location of certain sequences inside, then extract the bytes that are in-between these sequences (start-stop headings for my data). There's no methods available to do this, as all of them are only available at the string level. Unfortunately the byte data falls well outside the normal UTF-8 encoding, so I cannot simply use something like string.substringAfterLast(\"X\".getBytes()) to compare with, as X in this case is not defined in UTF-8.\r\n\r\nIn essence I'd like to know if there are some tool-set available from within the Eclipse IDE to assist iwth working with bytes. I've googled a lot and till date cannot event create a byte variable in Eclipse which will have the corresponding .getBytes() value of -17. Any help is very much appreciated!"},"comment":{"url":"https://api.github.com/repos/openhab/openhab/issues/comments/89439465","html_url":"https://github.com/openhab/openhab/issues/2382#issuecomment-89439465","issue_url":"https://api.github.com/repos/openhab/openhab/issues/2382","id":89439465,"user":{"login":"tertuis","id":11636364,"avatar_url":"https://avatars.githubusercontent.com/u/11636364?v=3","gravatar_id":"","url":"https://api.github.com/users/tertuis","html_url":"https://github.com/tertuis","followers_url":"https://api.github.com/users/tertuis/followers","following_url":"https://api.github.com/users/tertuis/following{/other_user}","gists_url":"https://api.github.com/users/tertuis/gists{/gist_id}","starred_url":"https://api.github.com/users/tertuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tertuis/subscriptions","organizations_url":"https://api.github.com/users/tertuis/orgs","repos_url":"https://api.github.com/users/tertuis/repos","events_url":"https://api.github.com/users/tertuis/events{/privacy}","received_events_url":"https://api.github.com/users/tertuis/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T22:39:17Z","updated_at":"2015-04-03T22:39:17Z","body":"So I eventually got it to work, somewhat, at least getting the bytes to display correctly. The key it seems is that you can specify the encoding to use, e.g. \r\n\r\n```\r\nAlarmSerialInput.state.toString.getBytes(\"ASCII\").get(counter)\r\n```\r\n\r\nAdding in the \"ASCII\" resulted in my string characters being translated to old-fashioned bytes, as per the ASCII mapping. I however have a new issue now.\r\n\r\nThe code below receives an input from the serial binding (AlarmSerialInput), which can be over 200 bytes long. This needs to be broken into smaller chucks based on a defined deliminator, which will always be the first byte received in the message. These chucks are then sent for further processing to perform actions on other items.\r\n\r\nThe problem is that I cannot construct a new byte array (which will be one smaller message) with this code as the .add method is giving an error. This is in the last code-block below. Messages will typically be between 10 and 37 bytes when deconstructed from the main input stream.\r\n\r\nI tried using integers, rather than bytes for all varioables and arrays but run into other issues then. I suspect I'm declaring the byte variables incorrectly, but have tried everything I could find on google.\r\n\r\n**Variables:**\r\n```\r\nvar byte x\r\nvar byte[] newInput\r\n```\r\n\r\n**Rule (when received update...):**\r\n```\r\nx = AlarmSerialInput.state.toString.getBytes(\"ASCII\").get(0)\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\tnewInput.add(x)\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\tcounter = 1\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\twhile (!(counter == (ParadoxEventSize-1))) {\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\twhile (AlarmSerialInput.state.toString.getBytes(\"ASCII\").get(counter) == x) {\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\tcounter = counter+1\r\n\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\tnewInput.add(AlarmSerialInput.state.toString.getBytes(\"ASCII\").get(counter))\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\tcounter = counter+1\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\tif (AlarmSerialInput.state.toString.getBytes(\"ASCII\").get(counter) == x) {\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\tprintln(\"Got a start and end, sending now:\")\r\n\t\t\t\t\t\t\t\t\tprintln(newInput)\r\n\t\t\t\t\t\t\t\t\t//Send newInput HERE!!!!!!!!!!!!!!!!!!!\r\n\t\t\t\t\t\t\t\t\tnewInput.clear()\r\n\t\t\t\t\t\t\t\t\tnewInput.add(x)\r\n\t\t\t\t\t\t\t\t\tcounter = counter+1\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t}\r\n```\r\n\r\n**Output from console:**\r\n```\r\nSize of event received: 234\r\nEntire String not 37 bytes or Chatter: [63, 20, 15, 4, 4, 0, 2, 2, 12, 0, 0, 0, 0, 0, 2, 77, 97, 105, 110, 32, 65, 108, 97, 114, 109, 32, 32, 32, 32, 32, 32, 12, 0, 0, 0, 0, 123, 63, 20, 15, 4, 4, 0, 2, 29, 6, 0, 0, 0, 0, 0, 1, 85, 115, 101, 114, 32, 48, 54, 32, 32, 32, 32, 32, 32, 32, 32, 32, 12, 0, 0, 0, 0, 63, 63, 20, 15, 4, 4, 0, 2, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 63, 20, 15, 4, 4, 0, 2, 30, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 58, 63, 20, 15, 4, 4, 0, 2, 58, 6, 0, 0, 0, 0, 0, 0, 83, 107, 117, 105, 102, 100, 101, 117, 114, 32, 83, 105, 116, 107, 109, 114, 0, 0, 0, 0, 0, 63, 63, 63, 12, 0, 92, 55, 116, 63, 65, 31, 63, 4, 63, 20, 15, 4, 4, 0, 2, 58, 13, 0, 0, 0, 79, 38, 0, 83, 107, 117, 105, 102, 100, 101, 117, 114, 32, 66, 114, 97, 97, 105, 107, 0, 0, 0, 0, 0, 63]\r\n2015-04-04 00:03:42.927 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Paradox Alarm Event - Raw Input': cannot invoke method public abstract boolean java.util.List.add(java.lang.Object) on null\r\n```"}}