C# readbyte function for LSB first 7 bit even 1 stop bit | CAS MWP 3000H rs232 interface

梦想的初衷 提交于 2020-07-02 03:13:34

问题


1. i have problem with CAS MWP 3000H , problem is serial protocol sends data 7 bit LSB fist data but C# i can read only readbyte not bit so problem is UEFI order is LSB First,, for examle MSB first data 4 = (binary 00000100) but if LSB first value this will be 00100000 and serial know 00100000(binary) = 10000(binary) so i take wrong data i need help for readbit first or library like this i need . or any one solve this problem with other solution or other languadge

2. i nearly solve this proble , i think if, LSB first and problem if readByte function works with bag .. i need ReadBit function , then i can convert msb first, then will be ok ..

3. if msb first 00000100 this is 4 (from 8 bit )correct but if lsb first 10000 not 0010000 for achieve 8 bit from UEfi order is first lsb then i take 10000 not 00000100 ,, then i try to get binary value then convert to binary than this value may be less than 7 bit if i read 7 bit but 00111100 (8bit) = 0111100(7bit MSB first ) but if LSB first then will be 0011110 = 11110 so i take 11110 , see ... and so , i try to make 8 bit MSB with next code sample , it works fine and correct . it tested .for this first of all must make 8 bit from any coming bit and.. i use reverse 4 problem is when i read with readbyte function i take
9A EF EF 40 20 0B EF EF EF 6F 18 (10011010 11101111 11101111 01000000 00100000 00001011 11101111 11101111 11101111 01101111 00011000) then change msb first to lsb 59 F7 F7 02 04 D0 F7 F7 F7 18 (01011001 11110111 11110111 00000010 00000100 11010000 11110111 11110111 11110111 00011000) but i cant tank normal value from ASCII , problem is i think readbyte reads when take 7 ,or 8 bit will and like i said (MSB first value is 0011110 will be 11110 from LSB so it need else 3 next bits then if i set 8 bit it reads this value .. like 11110 101001 but it thick 11110+101001 then take first 8 (11111010 and next byte stays 1010 ) wrong read .. soo i think readByte function wrong when LSB first.. we need readBit function if possible>

      String a = Convert.ToString(_serialPort.ReadByte(), 2);
      for(int i = 1; a.Length<7; i++){
            if (a.Length == i) {
                  String temppp = "0";
                  temppp += a;
                  a = temppp;
            }
       }  
       if (a.Length == 7){
            a += '0';
       }
       String temp = "";
       for(int i=0; i<a.Length;i++ ){
          char t = a[a.Length - i - 1];
          textBox1.Text += t;
          temp += t;
    }   
   </i>

来源:https://stackoverflow.com/questions/62289294/c-sharp-readbyte-function-for-lsb-first-7-bit-even-1-stop-bit-cas-mwp-3000h-rs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!