/* ICPDAS(R) Modbus Shared Memory Header */ #include #include #include #include #include #include #include #include #include #include #include #define MBS_DI "mbs_di" #define MBS_DO "mbs_do" #define MBS_AI "mbs_ai" #define MBS_AO "mbs_ao" typedef enum {DO,DI,AI,AO} IO_TYPE; int shm_id[4]; int *iMemory_DO; int *iMemory_AO; int *iMemory_AI; int *iMemory_DI; #define SHM_INIT(IO,SIZE) \ do{ \ if ((shm_id[IO]= shm_open(MBS_##IO, (O_CREAT | O_EXCL | O_RDWR),S_IRWXU )) > 0 ) { \ ftruncate(shm_id[IO], SIZE*sizeof(int)); \ }else if ((shm_id[IO]= shm_open(MBS_##IO, (O_CREAT | O_RDWR),S_IRWXU)) < 0){ \ perror("shm_open"); \ } \ iMemory_##IO=mmap(NULL,SIZE*sizeof(int),PROT_READ|PROT_WRITE,MAP_SHARED,shm_id[IO],0L); \ if (iMemory_##IO == MAP_FAILED) { \ perror("mmap"); \ exit(0); \ } \ if(close(shm_id[IO])<0){ \ perror("shm_id close failed\n"); \ } \ }while(0) \