12-11-2009 07:30 AM
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);
12-11-2009 07:33 AM
12-11-2009 07:42 AM
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);
12-11-2009 09:32 AM
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?
12-11-2009 09:44 AM