// Dll functions import
function
yapiInitAPI
(
mode:
integer
;
errmsg :
pansichar
)
:
integer
;
cdecl
;
external
'yapi.dll'
name
'yapiInitAPI'
;
function
yapiUpdateDeviceList
(
force:
integer
;errmsg :
pansichar
)
:
integer
;
cdecl
;
external
'yapi.dll'
name
'yapiUpdateDeviceList'
;
function
yapiHTTPRequest
(
device:
pansichar
;url:
pansichar
; buffer:
pansichar
;
buffsize:
integer
;
var
fullsize:
integer
;
errmsg :
pansichar
)
:
integer
;
cdecl
;
external
'yapi.dll'
name
'yapiHTTPRequest'
;
var
errmsgBuffer :
array
[
0
..
256
]
of
ansichar
;
dataBuffer :
array
[
0
..
1024
]
of
ansichar
;
errmsg,data :
pansichar
;
fullsize,p :
integer
;
const
serial =
'YD128X32-12345'
;
getValue =
'GET /api/module/luminosity HTTP/1.1'#13#10#13#10
;
setValue =
'GET /api/module?luminosity=100 HTTP/1.1'#13#10#13#10
;
begin
errmsg := @errmsgBuffer;
data := @dataBuffer;
// API initialization
if(
yapiInitAPI
(
1
,errmsg
)
<
0
)
then
begin
writeln
(
errmsg
)
;
halt
;
end
;
// forces a device inventory
if(
yapiUpdateDeviceList
(
1
,errmsg
)
<
0
)
then
begin
writeln
(
errmsg
)
;
halt
;
end
;
// requests the module luminosity
if
(
yapiHTTPRequest
(
serial,getValue,data,
sizeof
(
dataBuffer
)
,fullsize,errmsg
)
<
0
)
then
begin
writeln
(
errmsg
)
;
halt
;
end
;
// searches for the HTTP header end
p :=
pos
(
#13#10#13#10
,data
)
;
// displays the response minus the HTTP header
writeln
(
copy
(
data,p+
4
,
length
(
data
)
-p-
3
))
;
// changes the luminosity
if
(
yapiHTTPRequest
(
serial,setValue,data,
sizeof
(
dataBuffer
)
,fullsize,errmsg
)
<
0
)
then
begin
writeln
(
errmsg
)
;
halt
;
end
;
end
.
Module inventory
To perform an inventory of Yoctopuce modules, you need two functions from the dynamic library:
int
yapiGetAllDevices
(
int
*
buffer,
int
maxsize,
int
*
neededsize,
char
*
errmsg
);
int
yapiGetDeviceInfo
(
int
devdesc,yDeviceSt
*
infos,
char
*
errmsg
);
The
yapiGetAllDevices
function retrieves the list of all connected modules as a list of handles.
buffer
points to a 32-bit integer array which contains the returned handles.
maxsize
is the size in bytes of
the buffer. To
neededsize
is assigned the necessary size to store all the handles. From this, you can
deduce either the number of connected modules or that the input buffer is too small. The
errmsg
21. Using with unsupported languages
130
www.yoctopuce.com
Содержание Yocto-Display
Страница 1: ...Yocto Display User Manual...
Страница 2: ......
Страница 40: ...34 www yoctopuce com...
Страница 52: ...46 www yoctopuce com...
Страница 84: ...78 www yoctopuce com...
Страница 92: ...86 www yoctopuce com...
Страница 130: ...124 www yoctopuce com...
Страница 158: ...22 High level API Reference 152 www yoctopuce com On failure throws an exception or returns a negative error code...
Страница 422: ...416 www yoctopuce com...
Страница 424: ...24 Characteristics 418 www yoctopuce com...