00001 #include <stdio.h>
00002 #include "vapiLists.h"
00003 #include "vapiIOList.h"
00004 #include "vapiIOData.h"
00005 #include "vapiTypes.h"
00006
00007 vBoolean *FileAsDigitalInput (vOptions * Options, vpointer Data);
00008
00009 void
00010 vapiIORegisterSupportedHw ()
00011 {
00012 int position;
00013
00014 position =
00015 vapiIOListAddIO (GlobalIOList, "Ficheiro Como Input Digital",
00016 "Ficheiros",
00017 "Considerar um ficheiro como input digital",
00018 vInput, vNULL, vBool,
00019 (vIOFunction *) & FileAsDigitalInput);
00020
00021 vapiIOPropertySetChar (position, "Caminho Para o Ficheiro", " ");
00022
00023 position =
00024 vapiIOListAddIO (GlobalIOList, "1File as Digital Input",
00025 "group A",
00026 "Considerar um ficheiro como input digital",
00027 vInput, vStr, vStr,
00028 (vIOFunction *) & vapiDIFile);
00029
00030 vapiIOPropertySetChar (position, "Nome do Ficheiro", " ");
00031
00032 position =
00033 vapiIOListAddIO (GlobalIOList, "2File as Digital", "group A",
00034 "Considerar um ficheiro como input digital",
00035 vInputN, vStr, vStr,
00036 (vIOFunction *) & vapiDIFile);
00037
00038 vapiIOPropertySetChar (position, "Nome do Ficheiro1", " ");
00039 vapiIOPropertySetChar (position, "Nome do Ficheiro2", " ");
00040
00041
00042 position =
00043 vapiIOListAddIO (GlobalIOList, "3File as Digital", "group B",
00044 "Considerar um ficheiro como input digital",
00045 vOutput, vStr, vStr,
00046 (vIOFunction *) & vapiDIFile);
00047
00048 vapiIOPropertySetChar (position, "Nome do Ficheiro1", " ");
00049 vapiIOPropertySetChar (position, "Nome do Ficheiro2", " ");
00050
00051 position =
00052 vapiIOListAddIO (GlobalIOList, "4File as Digital", "group B",
00053 "Considerar um ficheiro como input digital",
00054 vOutputN, vStr, vStr,
00055 (vIOFunction *) & vapiDIFile);
00056
00057 vapiIOPropertySetChar (position, "Nome do Ficheiro1", " ");
00058 vapiIOPropertySetChar (position, "Nome do Ficheiro2", " ");
00059
00060 position =
00061 vapiIOListAddIO (GlobalIOList, "5File as Digital", "group B",
00062 "Considerar um ficheiro como input digital",
00063 vIOBoth, vStr, vStr,
00064 (vIOFunction *) & vapiDIFile);
00065
00066 vapiIOPropertySetChar (position, "Nome do Ficheiro1", " ");
00067 vapiIOPropertySetChar (position, "Nome do Ficheiro2", " ");
00068
00069 position =
00070 vapiIOListAddIO (GlobalIOList, "6File as Digital", "group B",
00071 "Considerar um ficheiro como input digital",
00072 vIOBothN, vStr, vStr,
00073 (vIOFunction *) & vapiDIFile);
00074
00075 vapiIOPropertySetChar (position, "Nome do Ficheiro1", " ");
00076 vapiIOPropertySetChar (position, "Nome do Ficheiro2", " ");
00077
00078 position = vapiIOListAddIO (GlobalIOList, "Siemens S7-300", "PLC",
00079 "Conectar via RS232 com o PLC S7-300",
00080 vIOBothN, vStr, vStr,
00081 (vIOFunction *) & vapiDIFile);
00082
00083 vapiIOPropertySetInt (position, "Número da Porta Com",
00084 "Qual a Porta Com a que o PLC está conectado",
00085 0, 10, 1, 1);
00086 }
00087
00088 int
00089 vapiDIFile (vOptions * Options, char *str)
00090 {
00091 v_debug ("DIFILE TRUE");
00092 return 1;
00093 }
00094
00095 vBoolean *
00096 FileAsDigitalInput (vOptions * Options, vpointer Data)
00097 {
00098 char *filename = vapiOptionsGetChars (Options, 0);
00099 int fileReturn;
00100 vBoolean *output;
00101 FILE *handler;
00102 if ((handler = fopen (filename, "r")) == NULL)
00103 {
00104 return NULL;
00105 }
00106 fileReturn = fgetc (handler);
00107 fclose (handler);
00108
00109 switch (fileReturn)
00110 {
00111 case EOF:
00112 {
00113 return NULL;
00114 break;
00115 }
00116 case (int) '1':
00117 {
00118 output = malloc (sizeof (vBoolean));
00119 output[0] = vTRUE;
00120 return output;
00121 break;
00122 }
00123 case (int) '0':
00124 {
00125 output = malloc (sizeof (vBoolean));
00126 output[0] = vFALSE;
00127 return output;
00128 break;
00129 }
00130 default:
00131 return NULL;
00132 }
00133 }