raven daniel

raven daniel

  • NA
  • 61
  • 29.5k

Inserting more than 255 users to last byte array occurrence

May 4 2016 12:22 PM
Hi Guys<br />Apologies for the funny title but im seriously stuck trying to figure out how to tackle this.<br /><br />I have a list of users with some details that i send to a device. When sending a small list of users then everything is fine, it fails however when i send +200, and i know the reason.<br /><br />In project i was given, the user ID is converted to <strong>CardID</strong> so that many things can work, that im clueless about. the card ID is a 32 byte array.<br /><br />I have here a struct which shows in highlight it has to be a byte.<br /><br /> <p style="text-autospace:none"><span style="font-size:9.5pt; font-family:Consolas;color:blue;background:white;white">public</span> <span style="font-size:9.5pt;font-family:Consolas; color:blue;background:white;white">struct</span> <span style="font-size:9.5pt;font-family:Consolas; color:#2B91AF;background:white;white">BS2Card</span></p> <p style="text-autospace:none"><span style="font-size:9.5pt; font-family:Consolas;color:black;background:white;white"> {</span></p> <p style="text-autospace:none"><span style="font-size:9.5pt; font-family:Consolas;color:black;background:white;white"> </span><span style="font-size:9.5pt;font-family:Consolas;color:blue;background: white;white">public</span> <span style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;white">byte</span><span style="font-size:9.5pt;font-family:Consolas; color:black;background:white;white"> type;</span></p><span style="font-size:9.5pt; font-family:Consolas;color:black;background:white;white"></span><span style="font-size:9.5pt;font-family:Consolas;color:blue;background: yellow;yellow">public</span> <span style="font-size:9.5pt;font-family:Consolas;color:blue;background:yellow;yellow">byte</span><span style="font-size:9.5pt;font-family:Consolas; color:black;background:yellow;yellow"> size;</span> <p style="text-autospace:none"><span style="font-size:9.5pt; font-family:Consolas;color:black;background:white;white"> [</span><span style="font-size:9.5pt;font-family:Consolas;color:#2B91AF; background:white;white">MarshalAs</span><span style="font-size: 9.5pt;font-family:Consolas;color:black;background:white;white">(</span><span style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;white">UnmanagedType</span><span style="font-size:9.5pt; font-family:Consolas;color:black;background:white;white">.ByValArray, SizeConst = </span><span style="font-size:9.5pt;font-family:Consolas; color:#2B91AF;background:white;white">BS2Envirionment</span><span style="font-size:9.5pt;font-family:Consolas;color:black;background:white;white">.BS2_CARD_DATA_SIZE)]</span></p> <p style="text-autospace:none"><span style="font-size:9.5pt; font-family:Consolas;color:black;background:white;white"> </span><span style="font-size:9.5pt;font-family:Consolas;color:blue;background: white;white">public</span> <span style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;white">byte</span><span style="font-size:9.5pt;font-family:Consolas; color:black;background:white;white">[] data;</span></p> <p><span style="font-size:9.5pt;font-family:Consolas; color:black;background:white;white"> }</span></p> So ill be sending the device everything including This 32 padded byte array<br /> <p style="text-autospace:none"><span style="font-size:9.5pt; font-family:Consolas;color:blue;background:yellow;yellow">byte</span><span style="font-size:9.5pt;font-family:Consolas;color:black;background:yellow;yellow">[] cardByte = </span><span style="font-size:9.5pt; font-family:Consolas;color:blue;background:yellow;yellow">new</span> <span style="font-size:9.5pt;font-family:Consolas; color:blue;background:yellow;yellow">byte</span><span style="font-size:9.5pt;font-family:Consolas;color:black;background:yellow;yellow">[32];</span></p> Finally the userID has to be converted to bit and inserted to the last occurrence of the byte array, meaning userID 11 has to be inserted into 0000000000000000000000000000000(11)<br /><br />problem is<strong> </strong>byte ranges from 0 - 255 so when you send lots of users then they start ending up with the same card ID's which brings back errors.<br /><br />Why am i stuck cause im abit junior and im told to fix this, and my mind set is stuck on the fact that this has to be 0000000000000000000000000000000(11) like this and i kinda lack the experience of senior to see around this.<br /><br />Can anyone point me in some direction/give criticism/ or tell me there is no hope i should rather talk to people who made the device. anything will help thank you in advance guys.

Answers (1)