0

I am developing an application in which i need to pass a array of 12 element. i am sending this array as a request using socket. I have lots of button on which i am performing this action.

The whole array remains same to send different action except the element no 10 and 11 gets changed for different buttons.

for example i am sending this values for Button 1 to ON

byte[] data1 = new byte[1024], packet1 = 
{   
    (byte) 0x00,(byte) 0x00, (byte) 0x00, 
    (byte) 0x00,(byte) 0x00, (byte) 0x06, 
    (byte) 0x01,(byte) 0x05, (byte) 0x00, 
    (byte) 0x01,(byte) 0xff, (byte) 0x00 
};

Here only element no 10(0x01) will changed for Button 2 which will be (0x02) and i am changing element no 11 for ON|OFF.

So i want to create such a method in which i can pass this two elements only. if i pass (0x01,0xff) button 1 ON and (0x01,0x00) button 1 off.

If you have any idea give me some guidance and advice to achieve my goal. currently i am passing all those elements for all buttons. but i want to do this dynamically.

Edit Button 1 OFF

byte[] data1 = new byte[1024], packet1 = 
    {   
        (byte) 0x00,(byte) 0x00, (byte) 0x00, 
        (byte) 0x00,(byte) 0x00, (byte) 0x06, 
        (byte) 0x01,(byte) 0x05, (byte) 0x00, 
        (byte) 0x01,(byte) 0x00, (byte) 0x00 
    };

Button 2 on

byte[] data1 = new byte[1024], packet1 = 
    {   
        (byte) 0x00,(byte) 0x00, (byte) 0x00, 
        (byte) 0x00,(byte) 0x00, (byte) 0x06, 
        (byte) 0x01,(byte) 0x05, (byte) 0x00, 
        (byte) 0x02,(byte) 0xff, (byte) 0x00 
    };

Button 2 off

byte[] data1 = new byte[1024], packet1 = 
    {   
        (byte) 0x00,(byte) 0x00, (byte) 0x00, 
        (byte) 0x00,(byte) 0x00, (byte) 0x06, 
        (byte) 0x01,(byte) 0x05, (byte) 0x00, 
        (byte) 0x02,(byte) 0x00, (byte) 0x00 
    };

Button 3 ON

byte[] data1 = new byte[1024], packet1 = 
    {   
        (byte) 0x00,(byte) 0x00, (byte) 0x00, 
        (byte) 0x00,(byte) 0x00, (byte) 0x06, 
        (byte) 0x01,(byte) 0x05, (byte) 0x00, 
        (byte) 0x03,(byte) 0xff, (byte) 0x00 
    };

button 3 Off

byte[] data1 = new byte[1024], packet1 = 
    {   
        (byte) 0x00,(byte) 0x00, (byte) 0x00, 
        (byte) 0x00,(byte) 0x00, (byte) 0x06, 
        (byte) 0x01,(byte) 0x05, (byte) 0x00, 
        (byte) 0x03,(byte) 0x00, (byte) 0x00 
    };

Thanks & Regards

Juned
  • 6,290
  • 7
  • 45
  • 93
  • "Pass" how? I'm afraid the question is really quite unclear about what your ultimate goal is. – T.J. Crowder Dec 05 '12 at 10:58
  • Instead of passing 12 elements i just want to change those 2 elements for different operation. – Juned Dec 05 '12 at 11:00
  • You'll have to define a new service method that treats the input as *updates* to the existing data. – Andreas Dolk Dec 05 '12 at 11:02
  • @Andreas_D can't i create a method like `fooMethod(byte,byte) in which i can pass diffrent values ? – Juned Dec 05 '12 at 11:06
  • 1
    You said that `0x01` is for button 1 and `0x02` is for button 2. But again you are saying this: - `(0x00,0x00) button 1 off`. So why is it `0x00` for button 1 here? – Rohit Jain Dec 05 '12 at 11:15
  • sorry its my mistake, i corrected that @RohitJain – Juned Dec 05 '12 at 11:17
  • Ok now, if you are only concerned about that 2 values, then why are you creating an array at all? Can you post the scenario where you need to use it? – Rohit Jain Dec 05 '12 at 11:22
  • I am sending this request to hardware which accepts byte array of 12 element,and gives me response. – Juned Dec 05 '12 at 11:23
  • 1
    @juned what is wrong with `set(byte [] data, byte v1, byte v2) {data[BUTTON_INDEX] = v1; data[ON_OFF_INDEX] = v2); }` or `setButton(byte [] data, byte button) { data[BUTTON_INDEX] = button; }`. You can encapsulate all these functionality into some `Data` class which holds the data array itself and internal logic and exports `setButton(byte button); on(); off();` methods. – khachik Dec 05 '12 at 11:26
  • @juned.. So you are saying that, your this array is fixed. And you want some way to change those two elements only, by passing 2 extra parameters. So, you want to pass three parameters to your method? – Rohit Jain Dec 05 '12 at 11:29
  • @juned.. You can toggle the `ON/OFF` state by `XORing` with `0xff`. `0xff ^ 0xff = 0x00`, and `0x00 ^ 0xff = 0xff` – Rohit Jain Dec 05 '12 at 11:31
  • yeah my array is fixed to 12 element, i just want to change those two element only. its just two parameters @RohitJain – Juned Dec 05 '12 at 11:32
  • @juned. And for specifying a button say x, you can do - `0x01 * x`. e.g: - for x = 4, `0x01 * 4 = 0x04`. Now you need to make sure that your multiplication result is not out of range of `byte`. – Rohit Jain Dec 05 '12 at 11:33
  • @khachik yeah that way might work but i have problem in implement those values to index 10 and 11. – Juned Dec 05 '12 at 11:34
  • @juned. And are you actually having different arrays for each button? Because element 10 is specific for every button right? What problem are you having implementing it to index 10 and 11? – Rohit Jain Dec 05 '12 at 11:35
  • @RohitJain element 10 is specific for each elelment like 0x01 for button 1,0x02 for button 2 etc. – Juned Dec 05 '12 at 11:37
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20619/discussion-between-rohit-jain-and-juned) – Rohit Jain Dec 05 '12 at 11:38
  • @RohitJain, i need your small help – Juned Jan 22 '13 at 07:20
  • @RohitJain i have fixed byte array to read response of different button status and while reading and writing too frequently on socket, i am getting application not responding dialog. this happens when i am setting poll interval time too low i.e 100ms. thanks foe respond by the way :) – Juned Jan 22 '13 at 07:28
  • @RohitJain give me some rough idea,how do i fix this ? i have asked to many colleagues but no one able fix this problem – Juned Jan 22 '13 at 08:10
  • @juned. Please post a new question with details. It's hard to guess what went wrong by reading your comment. – Rohit Jain Jan 22 '13 at 08:13
  • @RohitJain http://stackoverflow.com/questions/14456552/applkcation-not-responding-while-performing-a-read-write-operation-on-socket-too – Juned Jan 22 '13 at 10:36
  • @RohitJain also please check is your idea is implemented correctly or not http://paste.ubuntu.com/1558355/ – Juned Jan 22 '13 at 10:55
  • @RohitJain please help me to implement your logic :) – Juned Jan 28 '13 at 06:40

0 Answers0