protected override Scenario.ScenarioResult internalRun(CancellationToken ct) { ScenarioResult.RunResult sResult = ScenarioResult.RunResult.Fail; float current = 0; try { device.connect(); if (!device.isAlive()) { log.Info("aaa"); throw new ScenarioException("zUP device is not alive!"); } device.sendMsg(new zUPSetAddressMessage()); /* read current consuption voltage */ device.sendMsg(new zUPGetCurrentMessage()); string readCurrent = ((zUpGetCurrentResponse)device.receiveAnswer()).current; log.Info("Read current of: " + readCurrent); current = 0; if (!float.TryParse(readCurrent, out current)) { throw new ScenarioException("Error reading voltage from zUp"); } sResult = ScenarioResult.RunResult.Pass; } catch (Exception ex) { log.Error("Error in scenario", ex); } finally { device.disconnect(); } return(new ScenarioResult(sResult, current)); }
protected override Scenario.ScenarioResult internalRun(CancellationToken ct) { ScenarioResult.RunResult sResult = ScenarioResult.RunResult.Fail; float voltage = 0; try { device.connect(); if (!device.isConnected()) { throw new ScenarioException("could not connect to zUP device!"); } device.sendMsg(new zUPSetAddressMessage()); /* read current output voltage */ device.sendMsg(new zUpGetVoltageMessage()); string readVoltage = ((zUpGetVoltageResponse)device.receiveAnswer()).voltage; log.Info("Read voltage of: " + readVoltage); voltage = 0; if (!float.TryParse(readVoltage, out voltage)) { throw new ScenarioException("Error reading voltage from zUp!"); } sResult = ScenarioResult.RunResult.Pass; } catch (Exception ex) { log.Error("Error in scenario", ex); } finally { device.disconnect(); } return(new ScenarioResult(sResult, voltage)); }
protected override Scenario.ScenarioResult internalRun(CancellationToken ct) { log.Info("sending a message of type: " + message.GetType().Name); IResponse resp = null; AsyncMessageToken token = null; if (device == null) { throw new DeviceNotInitException("The device object was not initilized correctly!"); } try { if (temporaryConnection) { device.connect(); } if (device.SupportsAsyncOperations) { token = device.sendAsyncMsg(message); } else { device.sendMsg(message); } if (receiveAnswer) { if (device.SupportsAsyncOperations) { resp = device.receiveAsyncAnswer(token); } else { resp = device.receiveAnswer(ct); } if (resp == null) { throw new UnknownOPException("response arrived as NULL"); } } } catch (Exception ex) { log.Error(ex.Message); throw ex; } finally { if (temporaryConnection) { device.disconnect(); } } ScenarioResult.RunResult runResult = ScenarioResult.RunResult.Pass; return(new ScenarioResult(runResult, resp)); }
protected override Scenario.ScenarioResult internalRun(CancellationToken ct) { ScenarioResult.RunResult sResult = ScenarioResult.RunResult.Pass; try { device.connect(); if (!device.isAlive()) { throw new ScenarioException("zUP device is not alive!"); } //device.sendMsg(new zUPSetAddressMessage()); /* disable output */ device.sendMsg(new zUPOutputMessage(true)); /* set voltage */ device.sendMsg(new zUPSetVoltagetMessage(voltage)); /* read back assigned voltage */ device.sendMsg(new zUpGetVoltageMessage()); string readVoltage = ((zUpGetVoltageResponse)device.receiveAnswer()).voltage; log.Info("Read voltage of: " + readVoltage); float actualVoltage = 0; if (!float.TryParse(readVoltage, out actualVoltage)) { log.Error("Error reading voltage from zUp"); sResult = ScenarioResult.RunResult.Fail; } else { if (voltage * 1.05 < actualVoltage || voltage * 0.95 > actualVoltage) { log.Error("Voltage reading is not in range (+- 5%), Stopping output!"); device.sendMsg(new zUPOutputMessage(false)); sResult = ScenarioResult.RunResult.Fail; } } // if (false) // { // /* disable output */ // device.sendMsg(new zUPOutputMessage(false)); // } } catch (Exception ex) { log.Error("Error in scenario", ex); } finally { device.disconnect(); } return(new ScenarioResult(sResult, null)); }
protected override Scenario.ScenarioResult internalRun(CancellationToken ct) { log.Info("sending a message of type: " + message.GetType().Name); Dictionary <Device, IResponse> resp = null; try { if (temporaryConnection) { devices.ConnectAll(); } devices.SendMsgToAll(message); if (receiveAnswer) { resp = devices.ReceiveAnswerFromAll(); } } catch (Exception ex) { if (ex is NullDeviceException) { log.Error("null device in device list!", ex); } } finally { if (temporaryConnection) { devices.DisconnectAll(); } } ScenarioResult.RunResult runResult = ScenarioResult.RunResult.Pass; if (resp == null || resp.ContainsValue(null)) { runResult = ScenarioResult.RunResult.Fail; } return(new ScenarioResult(runResult, resp)); }