c# - Shifting Bits from a NamedPipeClientStream -


i trying write bit synchronous serial protocol reads data through namedpipeclientstream. data needs continuously monitored sync characters (hex 22) may or may not on byte boundaries , shift data accordingly ensure other data being received in frame.

i have prototyped several scenarios including bit array , using bitstream object designed person posted site of seem cumbersome , inefficient.

the data being sent continue come in after sync characters have been found must continue add incoming data end of bit stream shifted.

maybe this

using system; using system.collections.generic; using system.linq; using system.text; using system.io;  namespace consoleapplication1 {     class program     {         static void main(string[] args)         {             streamreader reader = new streamreader("filename");             uint16 chr = (uint16)reader.read();             uint16 word = 0;             int shift = -1;              while (shift == -1)             {                 word = (uint16)((uint16)(word << 8) | chr);                 shift = testsync(chr, word);             }             while ((chr = (uint16)reader.read()) >= 0)             {                 word = (uint16)((uint16)(word << 8) | chr);                 byte newchar = (byte)((word >> shift) & 0xff);              }           }         static int testsync(uint16 chr, uint16 word)         {             int results = -1;               if((uint16)(word & 0xff) == 0x11) return 0;             if((uint16)(word & 0xff) == 0x22) return 1;              if((uint16)(word & 0xff) == 0x44) return 2;             if((uint16)(word & 0xff) == 0x88) return 3;             if((uint16)(word & 0x1fe) == 0x110) return 4;             if((uint16)(word & 0x3fc) == 0x220) return 5;             if((uint16)(word & 0x7f8) == 0x440) return 6;             if ((uint16)(word & 0xff0) == 0x880) return 7;              return results;         }     } } ​ 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -