So I've got this form that a user puts in a numeric value into a text box. This value then has to be placed into a byte string of data so that it can be transmitted over as a packet. Bellow is what I have so far:
I've put in red the area where I'm having issues. I've tried different methods and have not been able to get this working yet. It only works if I speciffy the value manually as with OUTBuffer[1] = 0x85;, but I want byte 2 of OUTBuffer[] to be set with what I put in the text box. Hope this is understandable, any help will be appreciated.Code:Byte[] OUTBuffer = new byte[65]; //Allocate output memory buffer Byte[] INBuffer = new byte[65]; //Allocate input memory buffer if (setmSpeed == true) { OUTBuffer[0] = 0; //Not used, must be set to 0 OUTBuffer[1] = 0x85; //Command mode int decValue = Convert.ToInt32(textBox4.Text); //Get textbox contents and vconvert it to an integer byte[] intBytes = BitConverter.GetBytes(decValue); OUTBuffer[2] = decValue; //Data to be sent for (uint i = 3; i < 65; i++) //Set rest of data bytes to 1. OUTBuffer[i] = 0xFF; WriteFile(WriteHandleToUSBDevice, OUTBuffer, 65, ref BytesWritten, IntPtr.Zero); //Blocking function, unless an "overlapped" structure is used ToggleLEDsPending = false; }



LinkBack URL
About LinkBacks




thanks for your help, this will help a lot in the long run.