//----------------------------------------------------------------------------- // Load the I/O list from a file. Since we are just loading pin assignments, // put it into IoSeenPreviously so that it will get used on the next // extraction. //----------------------------------------------------------------------------- BOOL LoadIoListFromFile(FILE *f) { char line[80]; char name[MAX_NAME_LEN]; int pin; while(fgetsNoCR(line, sizeof(line), f)) { if(strcmp(line, "END\n")==0) { return TRUE; } // Don't internationalize this! It's the file format, not UI. if(sscanf(line, " %s at %d", name, &pin)==2) { int type; switch(name[0]) { case 'X': type = IO_TYPE_DIG_INPUT; break; case 'Y': type = IO_TYPE_DIG_OUTPUT; break; case 'A': type = IO_TYPE_READ_ADC; break; default: oops(); } AppendIoSeenPreviously(name, type, pin); } } return FALSE; }
//----------------------------------------------------------------------------- // Wipe the I/O list and then re-extract it from the PLC program, taking // care not to forget the pin assignments. Gets passed the selected item // as an index into the list; modifies the list, so returns the new selected // item as an index into the new list. //----------------------------------------------------------------------------- int GenerateIoList(int prevSel) { int i, j; char selName[MAX_NAME_LEN]; if(prevSel >= 0) { strcpy(selName, Prog.io.assignment[prevSel].name); } if(IoSeenPreviouslyCount > MAX_IO_SEEN_PREVIOUSLY/2) { // flush it so there's lots of room, and we don't run out and // forget important things IoSeenPreviouslyCount = 0; } // remember the pin assignments for(i = 0; i < Prog.io.count; i++) { AppendIoSeenPreviously(Prog.io.assignment[i].name, Prog.io.assignment[i].type, Prog.io.assignment[i].pin); } // wipe the list Prog.io.count = 0; // extract the new list so that it must be up to date for(i = 0; i < Prog.numRungs; i++) { ExtractNamesFromCircuit(ELEM_SERIES_SUBCKT, Prog.rungs[i]); } for(i = 0; i < Prog.io.count; i++) { if(Prog.io.assignment[i].type == IO_TYPE_DIG_INPUT || Prog.io.assignment[i].type == IO_TYPE_DIG_OUTPUT || Prog.io.assignment[i].type == IO_TYPE_READ_ADC) { for(j = 0; j < IoSeenPreviouslyCount; j++) { if(strcmp(Prog.io.assignment[i].name, IoSeenPreviously[j].name)==0) { Prog.io.assignment[i].pin = IoSeenPreviously[j].pin; break; } } } } qsort(Prog.io.assignment, Prog.io.count, sizeof(PlcProgramSingleIo), CompareIo); if(prevSel >= 0) { for(i = 0; i < Prog.io.count; i++) { if(strcmp(Prog.io.assignment[i].name, selName)==0) break; } if(i < Prog.io.count) return i; } // no previous, or selected was deleted return -1; }