5. Using the Memory Address Map
ADI16-4(FIT)GY
57
WORD wStatus;
BYTE byCategory;
BYTE byRange;
BYTE byModuleStart;
BYTE byData[0x80];
BYTE byChCount;
BYTE byErrorStatus;
/* Open */
dwIpAddress = FIT_IpChenge((BYTE *)FIT_SAMPLE_IP_ADDRESS);
hHandle = FIT_Open((BYTE *)&dwIpAddress, FIT_SAMPLE_PORT, NULL);
if (hHandle == 0) {
printf("Error! FIT_Open = %04X(H)\n", hHandle);
return 1;
}
/* Offset Address */
dwVaOffset = FIT_IO_DEVICE_SIZE * FIT_SAMPLE_DEVICE_ID;
/* Read 'Category' */
dwVaBase = FIT_IO_DEVICE_CONFIG;
wStatus = FIT_Read(hHandle, dw dwVa FIT_PRODUCT_CATEGORY,
1, &byCategory);
if (wStatus != 0) {
printf("Error! FIT_Read = %04X(H)\n", wStatus);
FIT_Close(hHandle);
return 1;
}
if (byCategory != FIT_PRODUCT_ANALOG) {
printf("Error! Category = %02X(H)\n", byCategory);
FIT_Close(hHandle);
return 1;
}
/* Write 'A/D Range' */
byRange = FIT_AIO_RANGE_PM10;
/* Range:-10 to 10V
*/
wStatus = FIT_Write(hHandle, dw dwVa FIT_AIO_AI_RANGE, 1,
&byRange);
if (wStatus != 0) {
printf("Error! FIT_Write = %04X(H)\n", wStatus);
}
/* Write 'Module Start'
*/
byModuleStart = FIT_MODULE_START_ON;
wStatus = FIT_Write(hHandle, dw dwVa FIT_MODULE_START, 1,
&byModuleStart);
if (wStatus != 0) {
printf("Error! FIT_Write = %04X(H)\n", wStatus);
}
/* Read 'A/D Data' */
dwVaBase = FIT_IO_INPUT;
wStatus = FIT_Read(hHandle, dw dwVaOffset, 2 * 4, (BYTE
*)&byData[0]);
if (wStatus != 0) {
printf("Error! FIT_Read = %04X(H)\n", wStatus);
}
for (byChCount = 0; byChCount < 4; by+) {
printf("A/D CH%d Data:%02X%02X\n", byChCount, byData[byChCount * 2 +
1], byData[byChCount * 2]);
}