LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

manipulating bits

   im formatting a 7btye word.  which is 56 data bits, this is the method i took for my last card, I want to use the same method formatting the next card, all i have do a little shifting ,oring 

  read the next to messaages after this board and you will understand what im talking about.

 

 

    memset( controlMessage, 0, NUM_BYTE_IN_CMD);
    memset( inbuff,     0, NUM_BYTE_IN_RESP);
   
    //filling buffer with the seven byte command message
    //(array 0-6 )
    controlMessage[MSCARD_BYTE] = MSCardAddress; //master card address  0
   
    //'U':is use to physically
    // set/reset specific device card;
    controlMessage[1] = 'U'/*commandCode*/;
   
    // embed controller number and device address into output message
    data <<= NUM_ADDRESS_BITS; // left shift data bits
    msbLsb = data | deviceAddress;  // combine data and address bits
    controlMessage[2] = (msbLsb>>8) & 0xff;  // Set MSB
    controlMessage[3] =  msbLsb & 0xff;  // Set LSB
    controlMessage[4]=0;//documented in the manual that the element is unused
    controlMessage[5]=0;//documented in the manual that the element is unused
   
    // calc check sum
    controlMessage[6] =  controlMessage[0] + controlMessage[1] +
                                     controlMessage[2] + controlMessage[3] +
                                     controlMessage[4] + controlMessage[5];
    controlMessage[6] = controlMessage[6] & 0xFF;
    statusCheck=ComWrt(physicalPort,controlMessage,NUM_BYTE_IN_CMD);
 

0 Kudos
Message 1 of 5
(3,754 Views)
basically im formatting a 16 bit word  into  7byte word which is currently 56 databits,   read next board to have an ideal of the method i want to take with each device card.

there are 2 device cards . the 5 LSB are the address of the device card , and  the remaining are data bits.

keep main  bit 15, 14, are garbage.

 switch 1 and switch 2  are on device card 1

switch 3  , switch 4, and switch 5 are on device card 2

the antennuator is on device card 2.  which only get bits 5 - 12 which are binary numbers 1-64.

0-4     ==> Device card adrress  so if i enter a 1  im talking to Device card 1, if i enter a 2, device card 2, if i enter 3 im talking to device card 3 etc............ all the way up to five possibly in the future

                   but there are only 3 cards

device  card 1                             device card  2                               device  card  3

***********                            ***********                              ************

switch 1    5-8                             switch  3    5-8                               Master Card , I have this taken care also                

switch 2    9-11                           switch  4    9-10(0-0 off/1-1 on)

                                                   switch  5   11-12(0-0 off/1-1 on)
 

15    14     13      12      11      10         9          8         7         6          5          4        3       2        1      0

 

0 Kudos
Message 2 of 5
(3,751 Views)

i WANT TO USED THIS SAME APPROACH  BELOW WITH THE SWITCH STATEMENT, this is the logic behind the 7byte word im going to take ,I just really need a little help on how im going to shift

for each device card 1 and two mainly,

 

 

   switch (switchNumber)
   {
      case 0: /********Device Card 1 ---- Switch 1**********/
         commandAddr = atoi(g_sInstrData[DEVICE_ADDR1]);// range bits 5-8
                 break;
      case 1: /********Device Card 1 ---- Switch 2**********/
         commandAddr = atoi(g_sInstrData[DEVICE_ADDR1]);//range   bits 9-11

                 break;
      case 2: /********Device Card 2 ---- Switch 3**********/
         commandAddr =atoi(g_sInstrData[DEVICE_ADDR2]);//range    bits 9-10

            break;
      case 3: /********Device Card 2 ---- Switch 4**********/
         commandAddr = atoi(g_sInstrData[DEVICE_ADDR2]);//range   bits  11-12

             break;
      case 4: /********Device Card 3 ---- Switch 5**********/
         commandAddr = atoi(g_sInstrData[DEVICE_ADDR3]);//range    bits 5-8

            break;
       default:
         
         //being consistent with other cases setting the value to zero
         //don't really need to do this
         commandAddr = 0;
         upper = 0;
         lower = 0;
         break;
   }     
  
   //shift upper byte to the left five bits
   upper<<=NUM_DEVICE_ADDRESS_BITS; 
         
   //Or upper byte and left byte together
   mostSignByteLeastSignByte=upper|lower;
   statusError=Control_Bus_Message ( g_physicalPort,
                                      DEVICE_UPDATE,
                                      commandAddr,
                                      mostSignByteLeastSignByte);
 

0 Kudos
Message 3 of 5
(3,750 Views)

I haven't understood what you are asking us: bit shifting is normally performed in C (and CVI, of course!) using '<<' and '>>' operators, while we have already discussed bit maskingin some of your threads in the past so you should be able to complete this task. Unless there is something not clear in your description (like for example trying to map a 16 bit word into 5 bits adding some extra informations in between...).

 

Could you try to explain in a clearer way your needs?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 5
(3,741 Views)
nevermind you guys I had to write everything out on paper. for me to understand how to shift everything. but my code works. Im getting ready to tested my code against the card, and then im going to post my code, then tell me what you guys think?
0 Kudos
Message 5 of 5
(3,737 Views)