UM-0085-B09
DT80 Range User Manual
Page 354
RG
•
Conversions which may be terminated by whitespace(P433) (
%f
,
%d
,
%x
,
%o
,
%i
and
%S
) will skip over any
leading whitespace, e.g. %d will match input strings of
"123"
,
" 123"
and
"
\013\013\010 123"
.
•
The
%i
conversion assumes that the value is hexadecimal if it starts with
0x
or
0X
, octal if it starts with
0
(zero),
otherwise decimal.
•
The
%f
conversion will accept numbers in standard (e.g.
–12.39904
) or exponential (e.g.
-1.239904e01
)
format.
•
The
%c
and
%b
conversions treat the characters as 8-bit binary values. So the character "1" (ASCII 49) will
result in the value 49 being stored in the CV.
Return Value
The
return value
of a
SERIAL
channel may be either a status code or a data value:
•
If all numeric input conversions in the control string include a
[
n
CV]
specification then the
SERIAL
channel
will return the status code –
0
(success),
20
(receive timeout),
21
(transmit timeout),
5
(CTS timeout) or
29
Serial Data Transmission and Reception (P350)
.
•
If one or more numeric input conversions in the control string do not include a
[
n
CV]
specification then the
SERIAL
channel will return the result of the rightmost conversion. If any part of the channel's evaluation fail
(i.e. the channel's status code is non zero) then the returned value will be the special "
NotYetSet
" error value.
The following example will attempt to read a floating point value from the serial sensor and return the value read
RA2+E 1SERIAL("%f")
1SERIAL 27.9
1SERIAL 31.2
dataTaker 80 E89 – Serial sensor receive time out
1SERIAL NotYetSet
Compare this with the following example, which instead assigns the value to a CV:
RA2+E 1SERIAL("%f[1CV]") 1CV
1SERIAL 0 State
1CV 27.9
1SERIAL 0 State
1CV 31.2
dataTaker 80 E89 – Serial sensor receive time out
1SERIAL 20 State
1CV 31.2
For many applications the form where the
SERIAL
channel returns the actual value scanned provides a simpler
solution.
Width
The optional
width
value specifies the maximum number of characters to read for conversion. For example, with the
above example's input data:
1SERIAL("%2d[1CV]")
will result in 1CV = 12 (
3.456
left in receive buffer). The
default for most of the conversions (except
%c
and
%b
) is to keep reading characters until an invalid character is read.
(That's why the integer conversions in the above example stop when the "." character is seen.)
The default
width
value for
%c
and
%b
is 1; with this setting the two conversions behave identically. However, if
width
is
specified then:
•
for
%c
, only the last character is read; preceding characters are skipped
•
for
%b
, the specified number of characters are treated as a multi-byte binary word, in "big-endian" (most
significant byte first) format. Note that due to the limited precision of CVs, the maximum practical
width
value is
3 (24 bits).
For example:
Example assumes input data is
123.456
1SERIAL("%1c[1CV]")
→
1CV = 49 (
23.456
left in receive buffer)
1SERIAL("%2c[1CV]")
→
1CV = 50 (
3.456
left in receive buffer)
1SERIAL("%3c[1CV]")
→
1CV = 51 (
.456
left in receive buffer)
1SERIAL("%1b[1CV]")
→
1CV = 49 (
23.456
left in receive buffer)
1SERIAL("%2b[1CV]")
→
1CV = 12594 (49*256 + 50) (
3.456
left in receive buffer)
1SERIAL("%3b[1CV]")
→
1CV = 3223859 (49*65536 + 50*256 + 51) (
.456
left in receive buffer)
Important:
If
width
is not specified then the incoming data must be terminated by a non-matching character, otherwise the serial
channel will continue to wait for more characters to be read, eventually returning a timeout.
Содержание DT80
Страница 29: ...UM 0085 B09 DT80 Range User Manual Page 29 RG The DT80 File System P114 ...
Страница 184: ...UM 0085 B09 DT80 Range User Manual Page 184 RG Figure 71 DT80 communications options ...
Страница 185: ...UM 0085 B09 DT80 Range User Manual Page 185 RG Figure 72 DT80 communications options integrated modem models ...