NSString
*
serial_or_name
=
[
NSString
stringWithUTF8String
:
argv
[
1
]]
;
// use serial or logical name
YModule
*
module
=
[
YModule
FindModule
:
serial_or_name
]
;
if
(
module.isOnline
)
{
if
(
argc >
=
3
)
{
NSString
*
newname
=
[
NSString
stringWithUTF8String
:
argv
[
2
]]
;
if
(![
YAPI
CheckLogicalName
:
newname
])
{
NSLog
(
@"Invalid name (%@)
\n
"
, newname
)
;
usage
(
argv
[
0
])
;
}
module.logicalName
=
newname;
[
module saveToFlash
]
;
}
NSLog
(
@"Current name: %@
\n
"
, module.logicalName
)
;
}
else
{
NSLog
(
@"%@ not connected (check identification and USB cable)
\n
"
,
serial_or_name
)
;
}
[
YAPI
FreeAPI
]
;
}
return
0
;
}
Warning: the number of write cycles of the nonvolatile memory of the module is limited. When this
limit is reached, nothing guaranties that the saving process is performed correctly. This limit, linked to
the technology employed by the module micro-processor, is located at about 100000 cycles. In short,
you can use the
saveToFlash
function only 100000 times in the life of the module. Make sure you
do not call this function within a loop.
Listing the modules
Obtaining the list of the connected modules is performed with the
yFirstModule()
function which
returns the first module found. Then, you only need to call the
nextModule()
function of this
object to find the following modules, and this as long as the returned value is not
NULL
. Below a
short example listing the connected modules.
#import <Foundation/Foundation.h>
#import "yocto_api.h"
int
main
(
int
argc,
const
char
*
argv
[])
{
NSError
*
error;
@autoreleasepool
{
// Setup the API to use local USB devices
if([
YAPI
RegisterHub
:
@"usb"
:&
error
]
!=
YAPI_SUCCESS
)
{
NSLog
(
@"RegisterHub error: %@
\n
"
,
[
error localizedDescription
])
;
return
1
;
}
NSLog
(
@"Device list:
\n
"
)
;
YModule
*
module
=
[
YModule
FirstModule
]
;
while
(
module
!=
nil
)
{
NSLog
(
@"%@ %@"
, module.serialNumber, module.productName
)
;
module
=
[
module nextModule
]
;
}
[
YAPI
FreeAPI
]
;
}
return
0
;
}
12.3. Error handling
When you implement a program which must interact with USB modules, you cannot disregard error
handling. Inevitably, there will be a time when a user will have unplugged the device, either before
running the software, or even while the software is running. The Yoctopuce library is designed to help
12. Using Yocto-Display with Objective-C
www.yoctopuce.com
69
Summary of Contents for Yocto-Display
Page 1: ...Yocto Display User Manual...
Page 2: ......
Page 40: ...34 www yoctopuce com...
Page 52: ...46 www yoctopuce com...
Page 84: ...78 www yoctopuce com...
Page 92: ...86 www yoctopuce com...
Page 130: ...124 www yoctopuce com...
Page 422: ...416 www yoctopuce com...