c# - Reading a range of output from USB device with LibUSB -


i working on program communicates device connected through usb. when program reads in data sent device (button presses, example), sent byte array. have key value pairs stored dictionary button press byte array , string name of button, display whenever pressed. device has sliders sends byte arrays, has full range, each slider different digit in array

{ 3, 0, 0, 0, ff, 0, 0, 0 } 

the range goes 00 ff in hex convert decimal.

byte[] slider1rangelower = { 3, 0, 0, 0, 00, 0, 0, 0 } byte[] slider1rangeupper = { 3, 0, 0, 0, 255, 0, 0, 0 } byte[] slider2rangelower = { 3, 0, 0, 00, 0, 0, 0, 0 } byte[] slider2rangeupper = { 3, 0, 0, 255, 0, 0, 0, 0 } 

i need know slider being used, every value between 0-255 comes through "slider1" or whatever name might be. there way store whole range of values 1 object, opposed making 256 entries per slider?

c# object oriented language, , create object device of properties. since don't know device, had guess lot, here came , should extensible need use for.

public class mydevice {     private const int payloadidbyte = 0;     private const int payloadsliderid = 3;     private const int payloadbuttonid = 4;     private const int button1byte = 1;     private const int button2byte = 2;     private const int button3byte = 3;     private const int slider1byte = 4;     private const int slider2byte = 3;     private const int payloadsize = 8;      public bool button1 { get; set; }     public bool button2 { get; set; }     public bool button3 { get; set; }     public byte slider1 { get; set; }     public byte slider2 { get; set; }      public mydevice()     {      }      public void update(byte[] payload)     {         if (payload.length != payloadsize)             throw new argumentexception("payload");          if (payload[payloadidbyte] == payloadsliderid)         {             slider1 = payload[slider1byte];             slider2 = payload[slider2byte];         }          if (payload[payloadidbyte] == payloadbuttonid)         {             button1 = payload[button1byte] > 0;             button2 = payload[button2byte] > 0;             button3 = payload[button3byte] > 0;         }     } } 

you can add events when object updated, additional features, etc. when read new payload usb, pass update function , let function parse payload object.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -