public bool Write(FSVariable variable) { bool forWriting = variable.ForWriting; variable.ForWriting = true; bool result = Process(variable); variable.ForWriting = forWriting; return(result); }
//private FSVariable[] _oneElementArray = new FSVariable[1]; public bool Read(FSVariable variable) { bool forWriting = variable.ForWriting; variable.ForWriting = false; bool result = Process(variable); variable.ForWriting = forWriting; return(result); }
public bool Process(FSVariable[] variables) { if (variables == null || variables.Length == 0) { return(true); } lock ("process") { if (!IsConnected || __errorsCounter > 10) { if ((DateTime.Now - _lastConnectingTryingTime) >= __intervalBetweenConnecting) { Connect(); __errorsCounter = 0; } } if (IsConnected) { int result = 0; bool needReading = false; for (int i = 0; i < variables.Length; i++) { FSVariable variable = variables[i]; if (variable.IsString) { } else { if (variable.IsArray) { } else { if (variable.ForWriting) { switch (variable.ValueSize) { case 1: if (!FSUIPC_Write(variable.Offset, variable.Value1, ref variable.Token, ref result)) { __errorsCounter++; return(false); } break; case 2: if (!FSUIPC_Write(variable.Offset, variable.Value2, ref variable.Token, ref result)) { __errorsCounter++; return(false); } break; case 4: if (!FSUIPC_Write(variable.Offset, variable.Value4, ref variable.Token, ref result)) { __errorsCounter++; return(false); } break; case 8: if (!FSUIPC_Write(variable.Offset, variable.Value8, ref variable.Token, ref result)) { __errorsCounter++; return(false); } break; default: throw new NotImplementedException(); } } else { needReading = true; if (!FSUIPC_Read(variable.Offset, variable.ValueSize, ref variable.Token, ref result)) { __errorsCounter++; return(false); } } } } variable.Processed(); } if (FSUIPC_Process(ref result)) { if (needReading) { for (int j = 0; j < variables.Length; j++) { FSVariable variable = variables[j]; if (variable.ForWriting) { continue; } if (variable.IsString) { } else { if (variable.IsArray) { } else { switch (variable.ValueSize) { case 1: if (!FSUIPC_Get(ref variable.Token, ref variable.Value1)) { __errorsCounter++; return(false); } break; case 2: if (!FSUIPC_Get(ref variable.Token, ref variable.Value2)) { __errorsCounter++; return(false); } break; case 4: if (!FSUIPC_Get(ref variable.Token, ref variable.Value4)) { __errorsCounter++; return(false); } break; case 8: if (!FSUIPC_Get(ref variable.Token, ref variable.Value8)) { __errorsCounter++; return(false); } break; } } } } } return(true); } else { __errorsCounter++; } } return(false); } }
public bool Process(FSVariable variable) { //_oneElementArray[0] = variable; return(Process(new FSVariable[] { variable })); }