⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classicladder.c

📁 电路仿真程序 Classic Ladder is coded 100% in C.It can be used for educational purposes or anything you wan
💻 C
字号:
/* Classic Ladder Project *//* Copyright (C) 2001 Marc Le Douarain *//* mavati@club-internet.fr *//* http://www.multimania.com/mavati/classicladder *//* February 2001 *//* Last update : 22 January 2002 *//* --------------------------- *//* Alloc/free global variables *//* --------------------------- *//* 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 *//* FIXME: should be preferably done in Makefile_realtime instead of this... */#ifdef __RTL__#define RTLINUX_SUPPORT#include <rtl_printf.h>#endif#include <stdio.h>#include <string.h>#include <stdlib.h>#include "classicladder.h"#include "files.h"#include "calc.h"#include "vars_access.h"#ifdef RTLINUX_SUPPORT#include "/usr/rtlinux/include/mbuff.h"      //for RTLinux#endifStrRung * RungArray;int * VarWordArray;StrTimer * TimerArray;StrMonostable * MonostableArray;StrArithmExpr * ArithmExpr;StrInfosGene * InfosGene;/* used for the editor */StrEditRung EditDatas;char EditArithmExpr[NBR_ARITHM_EXPR][ARITHM_EXPR_SIZE];/* return TRUE if okay */int ClassicLadderAllocAll(){#ifndef RTLINUX_SUPPORT    RungArray = (StrRung *)malloc( NBR_RUNGS * sizeof(StrRung) );    if (!RungArray)    {        printf("Failed to alloc RungArray !\n");        return FALSE;    }    TimerArray = (StrTimer *)malloc( NBR_TIMERS * sizeof(StrTimer) );    if (!TimerArray)    {        printf("Failed to alloc TimerArray !\n");        return FALSE;    }    MonostableArray = (StrMonostable *)malloc( NBR_MONOSTABLES * sizeof(StrMonostable) );    if (!MonostableArray)    {        printf("Failed to alloc MonostableArray !\n");        return FALSE;    }    if (!AllocVars())        return FALSE;    VarWordArray = (int *)malloc( NBR_WORDS * sizeof(int) );    if (!VarWordArray)    {        printf("Failed to alloc VarWordArray !\n");        return FALSE;    }    ArithmExpr = (StrArithmExpr *)malloc( NBR_ARITHM_EXPR * sizeof(StrArithmExpr) );    if (!ArithmExpr)    {        printf("Failed to alloc ArithmExpr !\n");        return FALSE;    }    InfosGene = (StrInfosGene *)malloc( sizeof(StrInfosGene) );    if (!InfosGene)    {        printf("Failed to alloc InfosGene !\n");        return FALSE;    }#else    RungArray = (StrRung *)mbuff_alloc( "Classicladder_Rungs", NBR_RUNGS * sizeof(StrRung) );    if (!RungArray)    {        debug_printf("Failed to alloc RungArray with mbuff !\n");        debug_printf("The real-time module must be inserted before...\n");        return FALSE;    }    TimerArray = (StrTimer *)mbuff_alloc( "Classicladder_Timers", NBR_TIMERS * sizeof(StrTimer) );    if (!TimerArray)    {        debug_printf("Failed to alloc TimerArray with mbuff !\n");        return FALSE;    }    MonostableArray = (StrMonostable *)mbuff_alloc( "Classicladder_Monostables", NBR_MONOSTABLES * sizeof(StrMonostable) );    if (!MonostableArray)    {        debug_printf("Failed to alloc MonostableArray with mbuff !\n");        return FALSE;    }    if (!AllocVars())        return FALSE;    VarWordArray = (int *)mbuff_alloc( "Classicladder_VarWords", NBR_WORDS * sizeof(int) );    if (!VarWordArray)    {        debug_printf("Failed to alloc VarWordArray with mbuff !\n");        return FALSE;    }    ArithmExpr = (StrArithmExpr *)mbuff_alloc( "Classicladder_ArithmExpr", NBR_ARITHM_EXPR * sizeof(StrArithmExpr) );    if (!ArithmExpr)    {        debug_printf("Failed to alloc ArithmExpr with mbuff !\n");        return FALSE;    }    InfosGene = (StrInfosGene *)mbuff_alloc( "Classicladder_InfosGene", sizeof(StrInfosGene) );    if (!InfosGene)    {        debug_printf("Failed to alloc InfosGene with mbuff !\n");        return FALSE;    }#endif    InfosGene->LadderState = STATE_LOADING;    InfosGene->CmdRefreshVarsBits = FALSE;    return TRUE;}void ClassicLadderFreeAll(){#ifndef RTLINUX_SUPPORT    if (RungArray)        free(RungArray);    if (TimerArray)        free(TimerArray);    if (MonostableArray)        free(MonostableArray);    if (VarWordArray)        free(VarWordArray);    if (ArithmExpr)        free(ArithmExpr);    if (InfosGene)        free(InfosGene);#else    if (RungArray)        mbuff_free("Classicladder_Rungs",RungArray);    if (TimerArray)        mbuff_free("Classicladder_Timers",TimerArray);    if (MonostableArray)        mbuff_free("Classicladder_Monostables",MonostableArray);    if (VarWordArray)        mbuff_free("Classicladder_VarWords",VarWordArray);    if (ArithmExpr)        mbuff_free("Classicladder_ArithmExpr",ArithmExpr);    if (InfosGene)        mbuff_free("Classicladder_InfosGene",InfosGene);#endif    FreeVars();}void InitAllLadderDatas(){    InitVars(0,0);    InitArithmExpr();    InitRungs();}#ifndef __RTL__void LoadAllLadderDatas(char * DatasDirectory, int argc, char **argv){    char FileName[500];    InitVars(argc,argv);    sprintf(FileName,"%stimers.csv",DatasDirectory);    printf("Loading timers datas from %s\n",FileName);    LoadTimersParams(FileName,TimerArray);    sprintf(FileName,"%smonostables.csv",DatasDirectory);    printf("Loading monostables datas from %s\n",FileName);    LoadMonostablesParams(FileName,MonostableArray);    PrepareTimers();    PrepareMonostables();    InitArithmExpr();    sprintf(FileName,"%sarithmetic_expressions.csv",DatasDirectory);    printf("Loading arithmetic expressions from %s\n",FileName);    LoadArithmeticExpr(FileName);    InitRungs();    sprintf(FileName,"%srung_",DatasDirectory);    LoadAllRungs(FileName,RungArray,&InfosGene->FirstRung,&InfosGene->LastRung,&InfosGene->CurrentRung);    PrepareRungs();}void SaveAllLadderDatas(char * DatasDirectory){    char FileName[500];    sprintf(FileName,"%stimers.csv",DatasDirectory);    SaveTimersParams(FileName,TimerArray);    sprintf(FileName,"%smonostables.csv",DatasDirectory);    SaveMonostablesParams(FileName,MonostableArray);    sprintf(FileName,"%sarithmetic_expressions.csv",DatasDirectory);    SaveArithmeticExpr(FileName);    sprintf(FileName,"%srung_",DatasDirectory);    SaveAllRungs(FileName);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -