{"action":"created","issue":{"url":"https://api.github.com/repos/digitalpetri/modbus/issues/1","labels_url":"https://api.github.com/repos/digitalpetri/modbus/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/digitalpetri/modbus/issues/1/comments","events_url":"https://api.github.com/repos/digitalpetri/modbus/issues/1/events","html_url":"https://github.com/digitalpetri/modbus/issues/1","id":74377287,"number":1,"title":"WriteMultipleCoilsRequest failure","user":{"login":"brianruss","id":10008824,"avatar_url":"https://avatars.githubusercontent.com/u/10008824?v=3","gravatar_id":"","url":"https://api.github.com/users/brianruss","html_url":"https://github.com/brianruss","followers_url":"https://api.github.com/users/brianruss/followers","following_url":"https://api.github.com/users/brianruss/following{/other_user}","gists_url":"https://api.github.com/users/brianruss/gists{/gist_id}","starred_url":"https://api.github.com/users/brianruss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianruss/subscriptions","organizations_url":"https://api.github.com/users/brianruss/orgs","repos_url":"https://api.github.com/users/brianruss/repos","events_url":"https://api.github.com/users/brianruss/events{/privacy}","received_events_url":"https://api.github.com/users/brianruss/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/digitalpetri/modbus/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":{"login":"kevinherron","id":340273,"avatar_url":"https://avatars.githubusercontent.com/u/340273?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinherron","html_url":"https://github.com/kevinherron","followers_url":"https://api.github.com/users/kevinherron/followers","following_url":"https://api.github.com/users/kevinherron/following{/other_user}","gists_url":"https://api.github.com/users/kevinherron/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinherron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinherron/subscriptions","organizations_url":"https://api.github.com/users/kevinherron/orgs","repos_url":"https://api.github.com/users/kevinherron/repos","events_url":"https://api.github.com/users/kevinherron/events{/privacy}","received_events_url":"https://api.github.com/users/kevinherron/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/digitalpetri/modbus/milestones/1","html_url":"https://github.com/digitalpetri/modbus/milestones/1.0.2","labels_url":"https://api.github.com/repos/digitalpetri/modbus/milestones/1/labels","id":1101945,"number":1,"title":"1.0.2","description":null,"creator":{"login":"kevinherron","id":340273,"avatar_url":"https://avatars.githubusercontent.com/u/340273?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinherron","html_url":"https://github.com/kevinherron","followers_url":"https://api.github.com/users/kevinherron/followers","following_url":"https://api.github.com/users/kevinherron/following{/other_user}","gists_url":"https://api.github.com/users/kevinherron/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinherron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinherron/subscriptions","organizations_url":"https://api.github.com/users/kevinherron/orgs","repos_url":"https://api.github.com/users/kevinherron/repos","events_url":"https://api.github.com/users/kevinherron/events{/privacy}","received_events_url":"https://api.github.com/users/kevinherron/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":1,"state":"open","created_at":"2015-05-08T14:30:31Z","updated_at":"2015-05-08T14:42:02Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2015-05-08T14:16:06Z","updated_at":"2015-05-08T14:44:19Z","closed_at":"2015-05-08T14:42:02Z","body":"When using a WriteMultipleCoilsRequest, if the quantity parameter is not a multiple of 8, the request fails to send, and a response timeout ensues.\r\nThe issue appears to be with the formula used to calculate the number of bytes that are needed to hold the quantity of bits to be written. Currently the formula (in ModbusRequestEncoder.encodeWriteMultipleCoils() ) is:\r\n```Java\r\n        int byteCount = (request.getQuantity() / 8) + (request.getQuantity() % 8);\r\n```\r\nThis should be:\r\n```\r\n        int byteCount = 1 + (request.getQuantity() -1) / 8;\r\n```\r\nThe ModbusRequestSerializationTest could be enhanced to check for these as below:\r\n```Java\r\n    @DataProvider\r\n    private Object[][] getAddressAndNumCoilsAndCoilValues() {\r\n        return new Object[][]{\r\n                {0, 1, new byte[]{0x01}},\r\n                {0, 2, new byte[]{0x02}},\r\n                {0, 3, new byte[]{0x04}},\r\n                {0, 4, new byte[]{0x08}},\r\n                {0, 5, new byte[]{0x10}},\r\n                {0, 6, new byte[]{0x20}},\r\n                {0, 7, new byte[]{0x40}},\r\n                {0, 8, new byte[]{(byte)0x80}},\r\n                {0, 9, new byte[]{0x01, 0x01}},\r\n                {0, 10, new byte[]{0x01, 0x02}},\r\n                {0, 11, new byte[]{0x01, 0x04}},\r\n                {0, 12, new byte[]{0x01, 0x08}},\r\n                {0, 13, new byte[]{0x01, 0x10}},\r\n                {0, 14, new byte[]{0x01, 0x20}},\r\n                {0, 15, new byte[]{0x01, 0x40}},\r\n                {0, 16, new byte[]{0x01, (byte)0x80}},\r\n                {0, 17, new byte[]{0x02, 0x01, 0x01}}\r\n        };\r\n    }\r\n.\r\n.\r\n.\r\n    @Test(dataProvider = \"getAddressAndNumCoilsAndCoilValues\")\r\n    public void testWriteMultipleCoilsRequest(int address, int numCoils, byte[] values) {\r\n        WriteMultipleCoilsRequest request = new WriteMultipleCoilsRequest(address, numCoils, values);\r\n        request.retain().content().markReaderIndex();\r\n\r\n        ByteBuf encoded = encoder.encode(request, Unpooled.buffer());\r\n        WriteMultipleCoilsRequest decoded = (WriteMultipleCoilsRequest) decoder.decode(encoded);\r\n\r\n        request.content().resetReaderIndex();\r\n\r\n        assertEquals(request.getAddress(), decoded.getAddress());\r\n        assertEquals(request.getQuantity(), decoded.getQuantity());\r\n        assertEquals(request.getValues(), decoded.getValues());\r\n    }\r\n\r\n```\r\n\r\nThe problem is detected as a IndexOutOfBoundsException, which does not get reported to the Modbus sendRequest() future."},"comment":{"url":"https://api.github.com/repos/digitalpetri/modbus/issues/comments/100255886","html_url":"https://github.com/digitalpetri/modbus/issues/1#issuecomment-100255886","issue_url":"https://api.github.com/repos/digitalpetri/modbus/issues/1","id":100255886,"user":{"login":"brianruss","id":10008824,"avatar_url":"https://avatars.githubusercontent.com/u/10008824?v=3","gravatar_id":"","url":"https://api.github.com/users/brianruss","html_url":"https://github.com/brianruss","followers_url":"https://api.github.com/users/brianruss/followers","following_url":"https://api.github.com/users/brianruss/following{/other_user}","gists_url":"https://api.github.com/users/brianruss/gists{/gist_id}","starred_url":"https://api.github.com/users/brianruss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianruss/subscriptions","organizations_url":"https://api.github.com/users/brianruss/orgs","repos_url":"https://api.github.com/users/brianruss/repos","events_url":"https://api.github.com/users/brianruss/events{/privacy}","received_events_url":"https://api.github.com/users/brianruss/received_events","type":"User","site_admin":false},"created_at":"2015-05-08T14:44:19Z","updated_at":"2015-05-08T14:44:19Z","body":"The alternative formula is good."}}