www.vxitech.com
APPENDIX A
APPENDIX A
DATA SWAPPING EXAMPLE
An example is provided below detailing how data might be swapped in to get a REAL number when the data is read “swapped”. In order to make the code easier to understand, only the portion that shuffles the data is presented here. The VME functions that actually perform the reading of the data are the responsibility of the user.
byte tempData[16]; int regRdata[16]; doublerealData;
union
{char data[8];
doublevalue;
}dblData;
// read results
data = VmeRead16(channel, VmeAddress+0x28, &Api_Result); printf("MSB1: %02x\n", data);
regRdata[0] = data;
data = VmeRead16(channel, VmeAddress+0x2a, &Api_Result); printf("MSB0: %02x\n", data);
regRdata[1] = data;
data = VmeRead16(channel, VmeAddress+0x2c, &Api_Result); printf("LSB1: %02x\n", data);
regRdata[2] = data;
data = VmeRead16(channel, VmeAddress+0x2e, &Api_Result); printf("LSB0: %02x\n", data);
regRdata[3] = data;
//now shuffle the bytes
dblData.data[0] = (byte)((regRdata[3] & 0xff00) >> 8); dblData.data[1] = (byte)((regRdata[3] & 0x00ff) >> 0); dblData.data[2] = (byte)((regRdata[2] & 0xff00) >> 8); dblData.data[3] = (byte)((regRdata[2] & 0x00ff) >> 0); dblData.data[4] = (byte)((regRdata[1] & 0xff00) >> 8); dblData.data[5] = (byte)((regRdata[1] & 0x00ff) >> 0); dblData.data[6] = (byte)((regRdata[0] & 0xff00) >> 8); dblData.data[7] = (byte)((regRdata[0] & 0x00ff) >> 0); realData = dblData.value;
SVM2608 Appendix A | 55 |