/// <summary> /// Locks the device for exclusive use, /// </summary> /// <param name="lockId">The lock id</param> /// <param name="PMSId">The PMS id</param> /// <param name="eventReceiverURI">The event receiver URI</param> /// <param name="lockTimeout">The lock timeout</param> /// <returns>SiLAReturnValue</returns> public virtual SiLAReturnValue Lock(string lockId, string PMSId, string eventReceiverURI, string lockTimeout) { SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, (noexec) => { if (noexec) { // calculates the estimated duration and returns AsynchronousCommandAccepted return(this.CreateReturnValue(ReturnCode.AsynchronousCommandAccepted, 0)); } this.LockDuration = TimeSpan.FromMilliseconds(0); this.LockID = lockId; this.PMSid = PMSid; this.EventReceiverURI = eventReceiverURI; this.LockDuration = Tools.ToTimeSpan(lockTimeout); // must unlock the device automatically // if lockTimeout parameter has value this.AutoUnlock(); return(this.CreateReturnValue()); }); return(returnValue); }
public SiLAReturnValue GetStatus(int requestId, out string deviceID, out Status state, out CommandDescription[] substates, out Boolean locked, out string PMSId, out DateTime currentTime) { SiLAReturnValue returnValue = new SiLAReturnValue( (int)ReturnCode.Success, this.Device.DeviceIdentification.DeviceName + "device status is Success", Tools.ZeroDuration, this.Device.DeviceIdentification.SiLADeviceClass); state = this.Device.State; deviceID = this.Device.ID; substates = null; locked = this.Device.IsLocked; PMSId = this.Device.PMSid; currentTime = DateTime.Now; // As value for the subStates null will be returned, // if the device is in the state startup, standby, or idle. if (this.Device.State == Status.startup || this.Device.State == Status.standby || this.Device.State == Status.idle) { substates = null; } else { substates = this.Device.SubStates.ToArray(); } return(returnValue); }
/// <summary> /// Processes the request /// </summary> /// <param name="requestId">The request id</param> /// <param name="lockId">The lock id</param> /// <param name="commandName">Name of the command.</param> /// <returns> /// SiLAReturnValue with ReturnCode.Success or ReturnCode.ErrorOnXXX code /// </returns> public SiLAReturnValue ProcessRequest(int requestId, string lockId, string commandName) { this.Requests.Add(new SiLARequest(requestId, lockId, commandName)); this.LastRequestTime = DateTime.Now; SiLAReturnValue returnValue = this.CreateReturnValue(); if (this.IsLocked && this.LockID != lockId) { returnValue.returnCode = (int)ReturnCode.ErrorOnLockId; } else { returnValue.returnCode = (int)ReturnCode.Success; } this.RequestId = requestId; Tools.WriteLogLine("Request for Device {0} [{6}]. RetVal: {7} ReqID:'{1}' Lock:'{2}' ID:'{3}' PMS:'{4}' EventURI:'{5}'", this.DeviceIdentification.DeviceName, requestId, lockId, this.ID, this.PMSid, this.EventReceiverURI, commandName, (ReturnCode)returnValue.returnCode); return(returnValue); }
public SiLAReturnValue LockDevice(int requestId, string lockId, string lockTimeout, string eventReceiverURI, string PMSId) { // If the Service Consumer wants to lock a device for exclusive use, // it shall invoke a LockDevice command with a generated String as value of the parameter “lockId”. // Subsequently the Service Provider shall only accept commands from a Service Consumer, // which uses the same lockId in the command calls. // The SiLA Service Consumer MUST ensure the uniqueness of the lockId to avoid conflicts with other SiLA Service Consumers. // The lockTimeout parameter is used to unlock the device automatically // after the indicated time period has passed, without receiving commands, // by executing a Reset and the UnlockDevice commands internally on the device. // The device will then be in the state Standby. // If the lockTimeout parameter is 0 or Null, then the locking is permanent until the next UnlockDevice or a power shutdown. SiLAReturnValue returnValue = this.Device.ProcessRequest(requestId, lockId, "LockDevice"); if (returnValue.ReturnCode != (int)ReturnCode.Success) { // lock error return(returnValue); } returnValue = this.Device.Lock(lockId, PMSId, eventReceiverURI, lockTimeout); return(returnValue); }
/// <summary> /// The SetParameters command is used to set device class and device specific parameters in the state idle so that the new values are used for the next command invocation. /// Only the parameters that need to be changed have to be transmitted to the device. /// </summary> /// <param name="paramsXML">ParameterSet XML</param> /// <returns>SiLAReturnValue</returns> public SiLAReturnValue SetParameters(string paramsXML) { // Example of a valid value for paramsXML: //<?xml version="1.0" encoding="utf-8"?> //<ParameterSet> // <Parameter name="Temperature"> // <Int32>33</Int32> // </Parameter> // <Parameter name="TimeInSeconds"> // <Int32>1500</Int32> // </Parameter> //</ParameterSet> SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, (noexec) => { if (noexec) { // calculates the estimated duration and returns AsynchronousCommandAccepted return(this.CreateReturnValue(ReturnCode.AsynchronousCommandAccepted, 100)); } // The paramsXML represents a ParameterSet ParameterSet data = Tools.FromXML <ParameterSet>(paramsXML); SiLAReturnValue retParam = this.CreateReturnValue(); // ResponseData contains a list of device parameters ResponseData responseData = this.GetIncubatorParameters(); retParam.SetResponseData(responseData); return(retParam); }); return(returnValue); }
/// <summary> /// Enables the continuation of the process (workflow) for a paused system /// </summary> /// <returns>SiLAReturnValue</returns> public SiLAReturnValue Continue() { // The DoContinue command shall enable the continuation of the process (workflow) for a paused system. // This means that paused asynchronous commands shall be continued and/or // that the system shall start working on the next (queued) command in the process (workflow). SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, this.ExecuteWork); return(returnValue); }
public SiLAReturnValue GetDeviceIdentification(int requestId, string lockId, out SiLA_DeviceIdentification deviceDescription) { SiLAReturnValue returnValue = new SiLAReturnValue( (int)ReturnCode.Success, this.Device.DeviceIdentification.DeviceName + " GetDeviceIdentification", "PT0.7S", this.Device.DeviceIdentification.SiLADeviceClass); deviceDescription = this.Device.DeviceIdentification; return(returnValue); }
public SiLAReturnValue GetDeviceIdentification(int requestId, string lockId, out SiLA_DeviceIdentification deviceDescription) { SiLAReturnValue returnValue = new SiLAReturnValue( (int)ReturnCode.Success, this.Device.DeviceIdentification.DeviceName + " GetDeviceIdentification", "PT0.7S", this.Device.DeviceIdentification.SiLADeviceClass); deviceDescription = this.Device.DeviceIdentification; return returnValue; }
public SiLAReturnValue StoreAtPosition(int requestId, string lockId, int position, string labwareType) { SiLAReturnValue returnValue = this.Device.ProcessRequest(requestId, lockId, "StoreAtPosition"); if (returnValue.ReturnCode != (int)ReturnCode.Success) { // invalid request or lock error return(returnValue); } returnValue = this.Device.StoreAtPosition(position, labwareType); return(returnValue); }
/// <summary> /// Resets the SiLA Service Provider and changes State to State.standby /// </summary> /// <returns>SiLAReturnValue</returns> public SiLAReturnValue Reset() { this.State = Status.resetting; // All queues shall be emptied without sending response events of already started or queued commands this.Requests.Clear(); this.Requests.Add(new SiLARequest(this.RequestId, this.LockID, "Reset")); // executes ResetDevice in a new thread SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, this.ResetDevice); return(returnValue); }
public SiLAReturnValue SetParameters(int requestId, string lockId, string paramsXML) { SiLAReturnValue returnValue = this.Device.ProcessRequest(requestId, lockId, "SetParameters"); if (returnValue.ReturnCode != (int)ReturnCode.Success) { // invalid request or lock error return(returnValue); } returnValue = this.Device.SetParameters(paramsXML); return(returnValue); }
public SiLAReturnValue DoContinue(int requestId, string lockId) { SiLAReturnValue returnValue = this.Device.ProcessRequest(requestId, lockId, "DoContinue"); if (returnValue.ReturnCode != (int)ReturnCode.Success) { // invalid request or lock error return(returnValue); } returnValue = this.Device.Continue(); return(returnValue); }
public SiLAReturnValue Delay(int requestId, string lockId, string time) { SiLAReturnValue returnValue = this.Device.ProcessRequest(requestId, lockId, "Delay"); if (returnValue.ReturnCode != (int)ReturnCode.Success) { // invalid request or lock error return(returnValue); } returnValue = this.Device.Delay(time); return(returnValue); }
public SiLAReturnValue UnlockDevice(int requestId, string lockId) { SiLAReturnValue returnValue = this.Device.ProcessRequest(requestId, lockId, "UnlockDevice"); if (returnValue.ReturnCode != (int)ReturnCode.Success) { // lock error return(returnValue); } returnValue = this.Device.Unlock(); return(returnValue); }
/// <summary> /// Creates the return value. /// </summary> /// <param name="retCode">The return code.</param> /// <param name="duration">The duration.</param> /// <returns></returns> protected SiLAReturnValue CreateReturnValue(ReturnCode retCode = ReturnCode.AsynchronousCommandAccepted, int duration = 0) { SiLAReturnValue retValue; retValue = new SiLAReturnValue() { returnCode = (int)retCode, duration = Tools.ToDuration(TimeSpan.FromMilliseconds(duration)), deviceClass = this.DeviceIdentification.SiLADeviceClass, }; return(retValue); }
/// <summary> /// Executes a method in a new thread /// </summary> /// <param name="requestId">The request id</param> /// <param name="action">Some action</param> /// <returns> /// SiLAReturnValue /// </returns> protected SiLAReturnValue ExecuteAsync(int requestId, SiLAAction action) { Tools.WriteLogLine("Executing {0} ", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); Thread thread = new Thread(() => { Tools.WriteLogLine("... {0} thread", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); SiLAReturnValue retValue = action(false); Tools.WriteLogLine("... {0} completed", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); try { SiLARequest request = this.Requests.FirstOrDefault(r => r.RequestId == requestId); if (request != null) { Tools.WriteLogLine("... {0} ResponseEvent", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); this.Requests.Remove(request); string responseDataString = Tools.CreateXML(retValue.GetResponseData()); EventReceiverClient eventClient = new EventReceiverClient("EventReceiver_EventReceiver"); eventClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(this.EventReceiverURI); eventClient.ResponseEvent(requestId, retValue, responseDataString); eventClient.Close(); } } catch (Exception ex) { retValue.returnCode = (int)ReturnCode.FinishedWithWarning; retValue.message = ex.Message; this.State = Status.errorHandling; Tools.WriteLogLine("ERROR: {0}", ex); if (ex.InnerException != null) { Tools.WriteLogLine(" INNER: {0}", ex.InnerException); } } }); // sets result and return value to AsynchronousCommandAccepted SiLAReturnValue returnValue = action(true); // starts the thread thread.Start(); return(returnValue); }
/// <summary> /// Stops running /// </summary> /// <returns>SiLAReturnValue</returns> public virtual SiLAReturnValue Abort() { SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, (noexec) => { if (noexec) { // calculates the estimated duration and returns AsynchronousCommandAccepted return(this.CreateReturnValue(ReturnCode.AsynchronousCommandAccepted, 0)); } this.AbortRequested = true; return(this.CreateReturnValue()); }); return(returnValue); }
/// <summary> /// Unlocks the device /// </summary> /// <returns></returns> public virtual SiLAReturnValue Unlock() { SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, (noexec) => { if (noexec) { // calculates the estimated duration and returns AsynchronousCommandAccepted return(this.CreateReturnValue(ReturnCode.AsynchronousCommandAccepted, 0)); } this.LockDuration = TimeSpan.FromMilliseconds(0); this.LockID = string.Empty; return(this.CreateReturnValue()); }); return(returnValue); }
/// <summary> /// Initializes the SiLA Service Provider and changes State from State.standby to State.idle /// </summary> /// <returns>SiLAReturnValue</returns> public SiLAReturnValue Initialize() { if (this.State != Status.standby) { // It shall only be possible to be invoked when the device is in the “standby” state. return(new SiLAReturnValue( (int)ReturnCode.CommandNotAllowedInThisState, "Initialize only be possible to be invoked when the device is in the standby state", Tools.ZeroDuration, this.DeviceIdentification.SiLADeviceClass)); } SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, this.InitializeDevice); this.State = Status.resetting; return(returnValue); }
public SiLAReturnValue Initialize(int requestId, string lockId) { // This command shall initialize the SiLA Service Provider. // It shall only be possible to be invoked when the device is in the “standby” state. SiLAReturnValue returnValue = this.Device.ProcessRequest(requestId, lockId, "Initialize"); if (returnValue.ReturnCode != (int)ReturnCode.Success) { // invalid request or lock error return(returnValue); } returnValue = this.Device.Initialize(); return(returnValue); }
/// <summary> /// The RetrieveByPositionId enables the retrieval of labware by means of the position identification. /// </summary> /// <param name="position">The position.</param> /// <param name="labwareType">Type of the labware.</param> /// <returns></returns> public SiLAReturnValue RetrieveByPositionId(int position, string labwareType) { SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, (noexec) => { int duration = 550; if (noexec) { return(this.CreateReturnValue(ReturnCode.AsynchronousCommandAccepted, duration)); } // performs a demo action Thread.Sleep(duration); return(this.CreateReturnValue(ReturnCode.AsynchronousCommandHasFinished, duration)); }); return(returnValue); }
public SiLAReturnValue Abort(int requestId, string lockId) { // The abort command shall stop all running and queued asynchronous commands (busy state). // If no error occurs, the device shall be in the idle state. // After completion of the abort command no response events // for the aborted asynchronous commands shall be fired any more. SiLAReturnValue returnValue = this.Device.ProcessRequest(requestId, lockId, "Abort"); if (returnValue.ReturnCode != (int)ReturnCode.Success) { // invalid request or lock error return(returnValue); } returnValue = this.Device.Abort(); return(returnValue); }
/// <summary> /// With this command the labware item is stored at the defined position in the device. /// </summary> /// <param name="position">The position.</param> /// <param name="labwareType">Type of the labware.</param> /// <returns></returns> public SiLAReturnValue StoreAtPosition(int position, string labwareType) { SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, (noexec) => { int duration = 1200; if (noexec) { // calculates the estimated duration and returns AsynchronousCommandAccepted return(this.CreateReturnValue(ReturnCode.AsynchronousCommandAccepted, duration)); } // performs a demo action Thread.Sleep(duration); // calculates the estimated duration and returns AsynchronousCommandAccepted return(this.CreateReturnValue(ReturnCode.AsynchronousCommandHasFinished, duration)); }); return(returnValue); }
/// <summary> /// With this command the device reports the available parameters that can be set during the idle state to the PMS. /// The content of the response data is ParameterSet that contains a list of device parameters. /// </summary> /// <returns>SiLAReturnValue</returns> public SiLAReturnValue GetParameters() { SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, (noexec) => { if (noexec) { // calculates the estimated duration and returns AsynchronousCommandAccepted return(this.CreateReturnValue(ReturnCode.AsynchronousCommandAccepted, 100)); } SiLAReturnValue retParam = this.CreateReturnValue(); // ResponseData contains a list of device parameters ResponseData responseData = this.GetIncubatorParameters(); retParam.SetResponseData(responseData); return(retParam); }); return(returnValue); }
/// <summary> /// Delay is used to suspend command execution /// </summary> /// <param name="duration">The duration</param> /// <returns>SiLAReturnValue</returns> public virtual SiLAReturnValue Delay(string duration = "") { TimeSpan interval = Tools.ToTimeSpan(duration); SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, (noexec) => { if (noexec) { this.State = Status.busy; // calculates the estimated duration and returns AsynchronousCommandAccepted return(this.CreateReturnValue(ReturnCode.AsynchronousCommandAccepted, "No Error", (int)interval.TotalMilliseconds)); } Thread.Sleep(interval); this.State = Status.idle; return(this.CreateReturnValue(ReturnCode.AsynchronousCommandHasFinished, "No Error", 0)); }); return(returnValue); }
/// <summary> /// Pauses /// </summary> /// <param name="duration">The duration</param> /// <returns>SiLAReturnValue</returns> public virtual SiLAReturnValue Pause(string duration = "") { this.WaitInterval = Tools.ToTimeSpan(duration); if (this.WaitInterval.Ticks == 0) { this.WaitInterval = TimeSpan.MaxValue; } SiLAReturnValue returnValue = this.ExecuteAsync(this.RequestId, (noexec) => { if (noexec) { // calculates the estimated duration and returns AsynchronousCommandAccepted return(this.CreateReturnValue(ReturnCode.AsynchronousCommandAccepted, 0)); } this.State = Status.paused; return(this.CreateReturnValue()); }); return(returnValue); }
public SiLAReturnValue Reset(int requestId, string lockId, string deviceId, string eventReceiverURI, string PMSId, string errorHandlingTimeout, Boolean simulationMode) { // This command shall reset the SiLA Service Provider. // All queues shall be emptied without sending response events of already started or queued commands. // It shall be callable at any time and from any state of the devices state machine. // It shall also be used to report the connection information of the service consumer’s event receiver available to the // SiLA Service Provider (or to overwrite it in subsequent calls). // Additionally sends the deviceId to the Service Provider so that the service // Provider can identify itself at the Service Consumer in case of a status event. this.Device.PrepareForReset(deviceId, PMSId, eventReceiverURI, errorHandlingTimeout, simulationMode); SiLAReturnValue returnValue = this.Device.ProcessRequest(requestId, lockId, "Reset"); if (returnValue.ReturnCode != (int)ReturnCode.Success) { // lock error return(returnValue); } returnValue = this.Device.Reset(); return(returnValue); }
public SiLAReturnValue GetStatus(int requestId, out string deviceID, out Status state, out CommandDescription[] substates, out Boolean locked, out string PMSId, out DateTime currentTime) { SiLAReturnValue returnValue = new SiLAReturnValue( (int)ReturnCode.Success, this.Device.DeviceIdentification.DeviceName + "device status is Success", Tools.ZeroDuration, this.Device.DeviceIdentification.SiLADeviceClass); state = this.Device.State; deviceID = this.Device.ID; substates = null; locked = this.Device.IsLocked; PMSId = this.Device.PMSid; currentTime = DateTime.Now; // As value for the subStates null will be returned, // if the device is in the state startup, standby, or idle. if (this.Device.State == Status.startup || this.Device.State == Status.standby || this.Device.State == Status.idle) { substates = null; } else { substates = this.Device.SubStates.ToArray(); } return returnValue; }
/// <summary> /// Creates the return value. /// </summary> /// <param name="retCode">The return code.</param> /// <param name="retText">The message.</param> /// <param name="duration">The duration.</param> /// <returns></returns> protected SiLAReturnValue CreateReturnValue(ReturnCode retCode = ReturnCode.AsynchronousCommandAccepted, string retText="No Error", int duration = 0) { SiLAReturnValue retValue; retValue = new SiLAReturnValue() { ReturnCode = (int)retCode, Message = retText, Duration = Tools.ToDuration(TimeSpan.FromMilliseconds(duration)), DeviceClass = this.DeviceIdentification.SiLADeviceClass, }; return retValue; }
/// <summary> /// Creates the return value. /// </summary> /// <param name="retCode">The return code.</param> /// <param name="duration">The duration.</param> /// <returns></returns> protected SiLAReturnValue CreateReturnValue(ReturnCode retCode = ReturnCode.AsynchronousCommandAccepted, int duration = 0) { SiLAReturnValue retValue; retValue = new SiLAReturnValue() { returnCode = (int)retCode, duration = Tools.ToDuration(TimeSpan.FromMilliseconds(duration)), deviceClass = this.DeviceIdentification.SiLADeviceClass, }; return retValue; }