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

📄 files.c

📁 电路仿真程序 Classic Ladder is coded 100% in C.It can be used for educational purposes or anything you wan
💻 C
📖 第 1 页 / 共 2 页
字号:
    for(NumRung=0;NumRung<NBR_RUNGS;NumRung++)    {        sprintf(RungFile,"%s%d.csv",BaseName,NumRung);        unlink(RungFile);    }    /* save rungs (only defined ones are saved) */    /* at the next load, the number of the rungs */    /* will be different */    Done = FALSE;    NumSavedRung = 0;    NumRung = InfosGene->FirstRung;    do    {        sprintf(RungFile,"%s%d.csv",BaseName,NumSavedRung++);        dbg_printf("Saving file : %s",RungFile);        if (SaveRung(RungFile,&RungArray[NumRung],&NewNumRungForJumps[0]))            dbg_printf(" - ok.\n");        else            dbg_printf(" - failed.\n");        if (NumRung == InfosGene->LastRung)            Done = TRUE;        else            NumRung = RungArray[NumRung].NextRung;    }    while(!Done);}void DumpRung(StrRung * TheRung){    int x,y;    printf("Used=%d\n",TheRung->Used);    for (y=0;y<RUNG_HEIGHT;y++)    {        for(x=0;x<RUNG_WIDTH;x++)        {            printf("%d:%d:%d=%d , ",TheRung->Element[x][y].Type,TheRung->Element[x][y].ConnectedWithTop,TheRung->Element[x][y].VarNum,TheRung->Element[x][y].DynamicOutput);        }        printf("\n");    }}void ConvRawLineOfNumbers(char * RawLine,char NbrParams,int * ValuesFnd){    char * StartOfValue;    char * EndOfValue;    char Num = 0;    char EndOfLine;    StartOfValue = RawLine;    EndOfValue = RawLine;    EndOfLine = FALSE;    do    {        /* Extract Value */        StartOfValue = EndOfValue;        do        {            EndOfValue++;        }        while( (*EndOfValue!=',') && (*EndOfValue!=10) );        if (*EndOfValue==10)            EndOfLine = TRUE;            *EndOfValue++ = '\0';            *ValuesFnd++ = atoi(StartOfValue);            Num++;            StartOfValue = EndOfValue;    }    while( (!EndOfLine) && (Num<NbrParams) );}char LoadTimersParams(char * FileName,StrTimer * BufTimers){    FILE * File;    char Okay = FALSE;    char Line[300];    char * LineOk;    int Params[3];    File = fopen(FileName,"rt");    if (File)    {        do        {            LineOk = fgets(Line,300,File);            if (LineOk)            {                if (Line[0]!=';')                {                    ConvRawLineOfNumbers(Line,2,Params);                    switch(Params[0])                    {                        case BASE_MINS:                        case BASE_SECS:                        case BASE_100MS:                            BufTimers->Base = CorresDatasForBase[Params[0]].ValueInMS;                            BufTimers->Preset = Params[1] * BufTimers->Base;                            strcpy(BufTimers->DisplayFormat,CorresDatasForBase[Params[0]].DisplayFormat);                            break;                        default:                            BufTimers->Base = 1;                            BufTimers->Preset = 10;                            strcpy(BufTimers->DisplayFormat,"%f?");                            printf("!!! Error loading parameter base in %s\n",FileName);                            break;                    }dbg_printf("Timer => Base = %d , Preset = %d\n",BufTimers->Base,BufTimers->Preset);                    BufTimers++;                }            }        }        while(LineOk);        fclose(File);        Okay = TRUE;    }    return (Okay);}char SaveTimersParams(char * FileName,StrTimer * BufTimers){    FILE * File;    char Okay = FALSE;    int NumTimer = 0;    File = fopen(FileName,"wt");    if (File)    {        fprintf(File,"; Timers :\n");        fprintf(File,"; Base(see classicladder.h),Preset\n");        do        {            fprintf(File,"%d,%d\n",ConvBaseInMilliSecsToId(BufTimers->Base),BufTimers->Preset/BufTimers->Base);            BufTimers++;            NumTimer++;        }        while(NumTimer<NBR_TIMERS);        fclose(File);        Okay = TRUE;    }    return (Okay);}char LoadMonostablesParams(char * FileName,StrMonostable * BufMonostables){    FILE * File;    char Okay = FALSE;    char Line[300];    char * LineOk;    int Params[3];    File = fopen(FileName,"rt");    if (File)    {        do        {            LineOk = fgets(Line,300,File);            if (LineOk)            {                if (Line[0]!=';')                {                    ConvRawLineOfNumbers(Line,2,Params);                    switch(Params[0])                    {                        case BASE_MINS:                        case BASE_SECS:                        case BASE_100MS:                            BufMonostables->Base = CorresDatasForBase[Params[0]].ValueInMS;                            BufMonostables->Preset = Params[1] * BufMonostables->Base;                            strcpy(BufMonostables->DisplayFormat,CorresDatasForBase[Params[0]].DisplayFormat);                            break;                        default:                            BufMonostables->Base = 1;                            BufMonostables->Preset = 10;                            strcpy(BufMonostables->DisplayFormat,"%f?");                            printf("!!! Error loading parameter base in %s\n",FileName);                            break;                    }dbg_printf("Monostable => Base = %d , Preset = %d\n",BufMonostables->Base,BufMonostables->Preset);                    BufMonostables++;                }            }        }        while(LineOk);        fclose(File);        Okay = TRUE;    }    return (Okay);}char SaveMonostablesParams(char * FileName,StrMonostable * BufMonostables){    FILE * File;    char Okay = FALSE;    int NumMonostable = 0;    File = fopen(FileName,"wt");    if (File)    {        fprintf(File,"; Monostables :\n");        fprintf(File,"; Base(see classicladder.h),Preset\n");        do        {            fprintf(File,"%d,%d\n",ConvBaseInMilliSecsToId(BufMonostables->Base),BufMonostables->Preset/BufMonostables->Base);            BufMonostables++;            NumMonostable++;        }        while(NumMonostable<NBR_MONOSTABLES);        fclose(File);        Okay = TRUE;    }    return (Okay);}char LoadArithmeticExpr(char * FileName){    FILE * File;    char Okay = FALSE;    char Line[300];    char * LineOk;    int NumExpr = 0;    File = fopen(FileName,"rt");    if (File)    {        do        {            LineOk = fgets(Line,300,File);            if (LineOk)            {                if (Line[0]!=';')                {                    if (Line[strlen(Line)-1]=='\n')                        Line[strlen(Line)-1]='\0';                    strcpy(ArithmExpr[NumExpr].Expr,Line);                    NumExpr++;                }            }        }        while(LineOk);        fclose(File);        Okay = TRUE;    }    return (Okay);}char SaveArithmeticExpr(char * FileName){    FILE * File;    char Okay = FALSE;    int NumExpr;    File = fopen(FileName,"wt");    if (File)    {        fprintf(File,"; Arithmetic expressions :\n");        fprintf(File,"; Compare or Operate ones\n");        for(NumExpr=0; NumExpr<NBR_ARITHM_EXPR; NumExpr++)        {            fprintf(File,"%s\n",ArithmExpr[NumExpr].Expr);        }        fclose(File);        Okay = TRUE;    }    return (Okay);}

⌨️ 快捷键说明

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