0

To send an api frame, I use the following code:

byte[] bytesToSend5 = new byte[] { 0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x40, 0xA6, 0x5E, 0x23, 0xFF, 0xFE, 0x02, 0x44, 0x34, 0x05, 0x4F };
serialPort1.Write(bytesToSend5, 0, bytesToSend5.Length);

The items from 5 to 12 represent a macaddress that the user will change from time to time. To make this easy, I want the user to input the new macaddress in a windows form application like this "123456789012" (this input window is called "prop1_serienr"). I then want to save this to a string, which I have done using this code:

string xbee_serienr;
xbee_serienr = prop1_serienr.Text;

I want to get this string into the array, changing the items on place 5-12 in the array, on the form 0x12, 0x,34, 0x56 and so on.

In theory, it would look something like this:

byte[] bytesToSend5 = new byte[] { 0x7E, 0x00, 0x10, 0x17, 0x01, xbee_serienr, 0xFF, 0xFE, 0x02, 0x44, 0x34, 0x04, 0x50 };
serialPort1.Write(bytesToSend5, 0, bytesToSend5.Length);

Anyone know if this is possible, if I should take another approach or otherwise have any suggestions/advice?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • What is your question? The separate steps you're looking for have all been answered before (string to byte array, combine multiple byte arrays into one), so try searching. See for example [Converting string to byte array in C#](http://stackoverflow.com/questions/16072709/converting-string-to-byte-array-in-c-sharp), [Merging two arrays in .NET](http://stackoverflow.com/questions/59217/merging-two-arrays-in-net). – CodeCaster Feb 10 '16 at 11:43
  • To be able to manipulate the frame as I want, I need to split the byte array. I want to keep the first 5 items, edit the following 8 items, then keep the last 7 - including changing the 7th as it's a checksum based on the other items. The searches I've done and the links you've sent me doesn't help me with this as far as I understand. Any input on this would be appreciated. – KermitLover Feb 10 '16 at 12:00
  • You don't need to split anything, you can just use `Array.Copy()` to overwrite a part of an array as explained in the [second link](http://stackoverflow.com/questions/59217/merging-two-arrays-in-net). – CodeCaster Feb 10 '16 at 12:22
  • Ok, thanks, I will see how I can make this work. WIll it be possible to "centralise" this part so I can use the user input in one method then use that variable in the bit arrays used in several different methods? – KermitLover Feb 10 '16 at 12:26

0 Answers0