User`s guide

being over used, the port may not come available within the timeout specified in
the port. In this case, LockPort() returns 0 and we throw an error. We can’t do
anything else, otherwise we’d defeat the purpose of locking the port in the first
place.
In line 15 we purge the port. This clears out any extraneous data on the port and
is usually a good idea just to be sure nothing is left over from a previous request.
Once purged, we can write the string out in line 17. We can then immediately
read the data back in line 19. The readuntil() function reads from the port until
the given character is received or the timeout occurs. If the timeout does occur,
an error is thrown. Otherwise, the characters are returned and placed in the
variable. Once we have a response, we can unlock the port in line 21 and return
the string received in line 23.
If we don’t unlock the port after locking it, no other sequences or threads will be
able to communicate on the port. For this reason, immediately after locking the
port, we enclose all the code up to the UnlockPort() in a try/catch block (lines 9 to
24). If an error is thrown inside this block, DAQFactory will skip to line 26 where
it unlocks the port. We then rethrow the error in line 27 so the user knows
something happened. This format ensures that the port is properly unlocked.
As stated in the comments in the code, line 31 is not really necessary as it is
impossible to reach, but we placed it there anyway just in case the logic changed
in the rest of the script. This ensures that something is actually returned from the
function, even if its nothing.