@@ -232,7 +232,7 @@ class MicroPythonBoard {
232
232
if ( filePath ) {
233
233
await this . enter_raw_repl ( )
234
234
const output = await this . exec_raw ( {
235
- command : `with open('${ filePath } ') as f:\n while 1:\n b=f.read(256)\n if not b:break\n print(b,end='')`
235
+ command : `with open('${ filePath } ', 'r' ) as f:\n while 1:\n b=f.read(256)\n if not b:break\n print(b,end='')`
236
236
} )
237
237
await this . exit_raw_repl ( )
238
238
return Promise . resolve ( output )
@@ -242,18 +242,22 @@ class MicroPythonBoard {
242
242
243
243
async fs_put ( src , dest ) {
244
244
if ( src && dest ) {
245
- const content = fs . readFileSync ( path . resolve ( src ) )
245
+ const contentBuffer = fs . readFileSync ( path . resolve ( src ) )
246
246
await this . enter_raw_repl ( )
247
247
let output = await this . exec_raw ( {
248
248
command : `f=open('${ dest } ','w')\nw=f.write`
249
249
} )
250
250
await sleep ( 100 )
251
- for ( let i = 0 ; i < content . length ; i += 128 ) {
252
- let slice = content . subarray ( i , i + 128 )
253
- slice = slice . toString ( )
254
- slice = escape_string ( slice )
255
- await this . serial . write ( `w("""${ slice } """)` )
256
- await this . serial . write ( `\x04` )
251
+ const contentString = contentBuffer . toString ( )
252
+ const hexArray = contentString . split ( '' ) . map (
253
+ c => c . charCodeAt ( 0 ) . toString ( 16 ) . padStart ( 2 , '0' )
254
+ )
255
+ const chunkSize = 256
256
+ for ( let i = 0 ; i < hexArray . length ; i += chunkSize ) {
257
+ let slice = hexArray . slice ( i , i + chunkSize )
258
+ let bytes = slice . map ( h => `0x${ h } ` )
259
+ let line = `w(bytes([${ bytes . join ( ',' ) } ]))\x04`
260
+ await this . serial . write ( line )
257
261
await sleep ( 100 )
258
262
}
259
263
return this . exit_raw_repl ( )
0 commit comments