re-init record when 2 is written to .PROC

This commit is contained in:
2018-07-30 15:37:37 +02:00
parent 9e6f2d593d
commit fb58a80b0c
3 changed files with 16 additions and 16 deletions

View File

@ -556,14 +556,17 @@ There is a fixed set of exception handler names starting with
<dt><code>@init</code></dt> <dt><code>@init</code></dt>
<dd> <dd>
Not really an exception but formally specified in the same syntax. Not really an exception but formally specified in the same syntax.
This handler is called from <code>iocInit</code> during record This handler can be used to initialize an output record with a value read from
initialization <span class="new">and again whenever <em>StreamDevice</em>
detects that the device has reconnected after a disconnect or when the
ioc is resumed with <code>iocRun</code> after beeing paused or
when the protocol has been <a href="setup.html#reload">reloaded</a></span>.
It can be used to initialize an output record with a value read from
the device. the device.
Also see chapter <a href="processing.html#init">Record Processing</a>. Also see chapter <a href="processing.html#init">Record Processing</a>.
It is called at startup by <code>iocInit</code> during record
initialization <span class="new">and again whenever <em>StreamDevice</em>
detects that the device has reconnected after a disconnect or when the
IOC is resumed with <code>iocRun</code> after beeing paused or
when the protocol has been <a href="setup.html#reload">reloaded</a></span>
or when the "magic value" <code>2</code> is written to the <code>.PROC</code>
field.
</dd> </dd>
</dl> </dl>
<h3>Example:</h3> <h3>Example:</h3>

View File

@ -421,6 +421,7 @@ startProtocol(StartMode startMode)
switch (startMode) switch (startMode)
{ {
case StartInit: case StartInit:
if (!onInit) return false;
flags |= InitRun; flags |= InitRun;
commandIndex = onInit(); commandIndex = onInit();
break; break;
@ -432,13 +433,10 @@ startProtocol(StartMode startMode)
} }
flags |= AsyncMode; flags |= AsyncMode;
case StartNormal: case StartNormal:
if (!commands) return false;
commandIndex = commands(); commandIndex = commands();
break; break;
} }
if (!commandIndex)
{
return false;
}
StreamBuffer buffer; StreamBuffer buffer;
runningHandler = Success; runningHandler = Success;
protocolStartHook(); protocolStartHook();

View File

@ -869,11 +869,11 @@ process()
debug("Stream::process(%s) start\n", name()); debug("Stream::process(%s) start\n", name());
status = NO_ALARM; status = NO_ALARM;
convert = OK; convert = OK;
if (!startProtocol(StreamCore::StartNormal)) if (!startProtocol(record->proc==2 ? StreamCore::StartInit : StreamCore::StartNormal))
{ {
debug("Stream::process(%s): could not start, status=%d\n", debug("Stream::process(%s): could not start %sprotocol, status=%d\n",
name(), status); name(), record->proc==2 ? "@init " : "", status);
(void) recGblSetSevr(record, status, INVALID_ALARM); (void) recGblSetSevr(record, status ? status : UDF_ALARM, INVALID_ALARM);
return false; return false;
} }
debug("Stream::process(%s): protocol started\n", name()); debug("Stream::process(%s): protocol started\n", name());
@ -1010,7 +1010,7 @@ protocolFinishHook(ProtocolResult result)
break; break;
} }
if ((flags & (InitRun|Aborted)) == InitRun) if ((flags & (InitRun|Aborted)) == InitRun && record->proc != 2)
{ {
debug("Stream::protocolFinishHook %s: signalling init done\n", name()); debug("Stream::protocolFinishHook %s: signalling init done\n", name());
#ifdef EPICS_3_13 #ifdef EPICS_3_13
@ -1033,7 +1033,6 @@ protocolFinishHook(ProtocolResult result)
callbackSetPriority(priority(), &processCallback); callbackSetPriority(priority(), &processCallback);
callbackRequest(&processCallback); callbackRequest(&processCallback);
} }
} }
void Stream:: void Stream::