/* Get Analog input for i8k modules and put its value to share memory . Author: Jerry Chiu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* File level history (record changes for this file here.). 2010.11.09 JerryChiu - Get Analog Input from i-8017HW and put its value to shared memory */ #include #include "icpdas_mbs.h" #include "msw.h" // int main(int argc, char **argv) { int RetValue,slot,channel,gain,mode; float f ; unsigned long l; slot=3; channel=0; gain=0; mode=0; /* OPEN Share Memory */ SHM_INIT(AI,2000); /* open device file */ RetValue = Open_Slot(slot); if (RetValue >0) { printf("open Slot %d failed!\n",slot); return FAILURE; } RetValue=I8017_Init(slot); I8017_SetChannelGainMode(slot,channel,gain,mode); while (1) { /* Get AI Value */ f=I8017_GetCurAdChannel_Float_Cal(slot); l = *((unsigned long *)&f); /* Float inverse (Big-Endian) , depends on your SCADA */ /* iMemory_AI[0]=*((short *)&l+1); iMemory_AI[1]=*((short *)&l); */ /* Float (Little-Endian) */ iMemory_AI[0]=*((short *)&l); iMemory_AI[1]=*((short *)&l+1); printf("%f\n",f); // printf("" usleep(100); } Close_Slot(slot); return 0; }