Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92979211
YFilesExample.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 25, 07:56
Size
1 KB
Mime Type
text/x-python
Expires
Wed, Nov 27, 07:56 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
22549369
Attached To
rSERVICENOWCHATALERT servicenow-chat-alert
YFilesExample.py
View Options
#!/usr/bin/python
# -*- coding: utf-8 -*-
import
os
,
sys
import
math
# add ../../Sources to the PYTHONPATH
sys
.
path
.
append
(
os
.
path
.
join
(
".."
,
".."
,
"Sources"
))
from
array
import
*
from
yocto_api
import
*
from
yocto_files
import
*
def
usage
():
scriptname
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
print
(
"Usage:"
)
print
(
scriptname
+
' <serial_number>'
)
print
(
scriptname
+
' <logical_name>'
)
print
(
scriptname
+
' any '
)
sys
.
exit
()
def
die
(
msg
):
sys
.
exit
(
msg
+
' (check USB cable)'
)
errmsg
=
YRefParam
()
if
len
(
sys
.
argv
)
<
2
:
usage
()
target
=
sys
.
argv
[
1
]
# Setup the API to use local USB devices
if
YAPI
.
RegisterHub
(
"usb"
,
errmsg
)
!=
YAPI
.
SUCCESS
:
sys
.
exit
(
"init error"
+
errmsg
.
value
)
if
target
==
'any'
:
# retrieve any filesystem
files
=
YFiles
.
FirstFiles
()
if
files
is
None
:
die
(
'No module connected'
)
else
:
files
=
YFiles
.
FindFiles
(
target
+
".files"
)
if
not
files
.
isOnline
():
die
(
"Module not connected "
)
# create text files and upload them to the device
for
i
in
range
(
1
,
5
):
contents
=
"This is file "
+
str
(
i
)
# convert the string to binary data
binaryData
=
contents
.
encode
(
"latin-1"
)
# upload the file to the device
files
.
upload
(
"file"
+
str
(
i
)
+
".txt"
,
binaryData
)
# list files found on the device
print
(
"Files on device:"
)
filelist
=
files
.
get_list
(
"*"
)
for
i
in
range
(
len
(
filelist
)):
file
=
filelist
[
i
]
print
(
'
%-40s%08x
%d
bytes'
%
(
file
.
get_name
(),
file
.
get_crc
()
%
0xffffffff
,
file
.
get_size
()))
# download a file
binaryData
=
files
.
download
(
"file1.txt"
)
# and display
print
(
""
)
print
(
"contents of file1.txt:"
)
print
(
binaryData
.
decode
(
"latin-1"
))
YAPI
.
FreeAPI
()
Event Timeline
Log In to Comment