📄 vars_access.c
字号:
/* Classic Ladder Project *//* Copyright (C) 2001 Marc Le Douarain *//* mavati@club-internet.fr *//* http://www.multimania.com/mavati/classicladder *//* February 2001 *//* Last update : 19 January 2002 *//* --------------------------------------- *//* Access a variable for reading / writing *//* --------------------------------------- *//* This library is free software; you can redistribute it and/or *//* modify it under the terms of the GNU Lesser General Public *//* License as published by the Free Software Foundation; either *//* version 2.1 of the License, or (at your option) any later version. *//* This library 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 *//* Lesser General Public License for more details. *//* You should have received a copy of the GNU Lesser General Public *//* License along with this library; if not, write to the Free Software *//* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef __RTL__#include <gtk/gtk.h>#else#include <rtl_printf.h>#endif#include <stdio.h>#include <stdlib.h>#include "classicladder.h"#include "global.h"static char * VarArray;int AllocVars(void) { VarArray =#ifdef __RTL__ (char *) mbuff_alloc("Classicladder_VarsBits", (NBR_BITS + NBR_PHYS_INPUTS + NBR_PHYS_OUTPUTS) * sizeof(char));#else (char *) malloc((NBR_BITS + NBR_PHYS_INPUTS + NBR_PHYS_OUTPUTS) * sizeof(char));#endif if (!VarArray) {#ifdef __RTL__ debug_printf("Failed to alloc VarArray with mbuff !\n");#else printf("Failed to alloc VarArray !\n");#endif return FALSE; } else return TRUE;}void FreeVars(void) { if (VarArray) {#ifdef __RTL__ mbuff_free("Classicladder_VarsBits",VarArray);#else free(VarArray);#endif }}void InitVars(int argc, char** argv) //parameters not used in this variant, but see the MAT variant{ int NumVar; for (NumVar=0; NumVar<(NBR_BITS+NBR_PHYS_INPUTS+NBR_PHYS_OUTPUTS); NumVar++) VarArray[NumVar] = FALSE; for (NumVar=0; NumVar<NBR_WORDS; NumVar++) VarWordArray[NumVar] = 0; /* to tell the GTK application to refresh the bits */ InfosGene->CmdRefreshVarsBits = TRUE;}int ReadVar(int TypeVar,int Offset){ switch(TypeVar) { case VAR_MEM_BIT: return VarArray[Offset]; case VAR_TIMER_DONE: return TimerArray[Offset].OutputDone; case VAR_TIMER_RUNNING: return TimerArray[Offset].OutputRunning; case VAR_MONOSTABLE_RUNNING: return MonostableArray[Offset].OutputRunning; case VAR_PHYS_INPUT: return VarArray[NBR_BITS+Offset]; case VAR_PHYS_OUTPUT: return VarArray[NBR_BITS+NBR_PHYS_INPUTS+Offset]; case VAR_MEM_WORD: return VarWordArray[Offset]; default: debug_printf("!!! Error : Type not found in ReadVar()\n"); } return 0;}void WriteVar(int TypeVar,int NumVar,int Value){ switch(TypeVar) { case VAR_MEM_BIT: VarArray[NumVar] = Value;#ifndef __RTL__ if (Value) gtk_toggle_button_set_active((GtkToggleButton *)chkvar[NumVar],TRUE); else gtk_toggle_button_set_active((GtkToggleButton *)chkvar[NumVar],FALSE);#else /* to tell the GTK application to refresh the bits */ InfosGene->CmdRefreshVarsBits = TRUE;#endif break; case VAR_PHYS_INPUT: VarArray[NBR_BITS+NumVar] = Value; break; case VAR_PHYS_OUTPUT: VarArray[NBR_BITS+NBR_PHYS_INPUTS+NumVar] = Value; break; case VAR_MEM_WORD: VarWordArray[NumVar] = Value; break; default: debug_printf("!!! Error : Type not found in WriteVar()\n"); break; }}void DumpVars(void){ int NumVar; for (NumVar=0; NumVar<20; NumVar++) debug_printf("Var %d=%d\n",NumVar,ReadVar(VAR_MEM_BIT,NumVar));}/* these are only useful for the MAT-connected version */void DoneVars(void) {}void CycleStart(void) {}void CycleEnd(void) {}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -