USB_VCP Vs pyboard.py?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

USB_VCP Vs pyboard.py?

Post by starter111 » Mon May 08, 2017 6:27 am

I have been using pyboard.py run my script on pyboard. It save me a lot of time....
Right now major part of pyboard side is done, I like send data back to pc. Should I use pyboard.py or USB_VCP?

let say I have myfuntion will return 10k of data on pyboard, how can I save return data to PC as a variable instead of printing it out??
I try var=pyb.exec('myfuntion()') it only returns b''.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: USB_VCP Vs pyboard.py?

Post by pythoncoder » Mon May 08, 2017 6:44 am

You can capture results from pyboard.py. Given rats.py containing

Code: Select all

print('rats\n')
and you issue

Code: Select all

pyboard.py --device /dev/pyboard rats14.py > result.txt
then you should find the output text in result.txt

Code: Select all

[adminpete@axolotl]: ~
$ cat result.txt
rats

Peter Hinch
Index to my micropython libraries.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: USB_VCP Vs pyboard.py?

Post by dhylands » Mon May 08, 2017 6:52 am

I wrote some JSON IPC code that you can send data back and forth:
https://github.com/dhylands/json-ipc

pyboard.py allows you to take a piece of code from the PC and execute it on the pyboard. Over the USB link you should be able to return 10k of data. rshell uses pyboard.py to copy files back and forth by executing snippets of python. For the simpler cases the snppet of python code running on the pyboard prints a python statement, and the PC side evals it to get the results.

starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

Re: USB_VCP Vs pyboard.py?

Post by starter111 » Mon May 08, 2017 7:09 am

Thanks for both, will look into VCP module..
just try to understand little bit pyboard.py ..looks like data got save to PC after aded "print" but it add bytearray and one more '\' to data...if pyboard.py can print it out must be someway save as variable??

import pyboard
pyb = pyboard.Pyboard('COM16')
pyb.enter_raw_repl()
data=pyb.exec('print(myfuntion())')
pyb.exec('pyb.LED(2).toggle()')
pyb.exit_raw_repl()
print('hi')
print(data)

output:
hi
b'bytearray(b\'\\x00\\x00\\x01\\

starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

Re: USB_VCP Vs pyboard.py?

Post by starter111 » Mon May 08, 2017 8:54 am

I think my question is not clear...
I have been using pyboard.py with notepad++ in windows with below nppexec script. It prints every thing expected.
bytearray(b'\x00\x00\x01.....more....)

I can save data as file to /flash or /sd. works ok. but now I want send data as variable to pc directly, because my application going to be sending a lot larger data back and forth, doesn't make sense save to file. I understand usb_vcp module can do that, but if pyboard.py can print out data already, is it much easier? So I don't have to modify or add anything in pyboard side?

NPP_SAVE
cd $(CURRENT_DIRECTORY)
python pyboard.py --device COM16 $(FULL_CURRENT_PATH)

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: USB_VCP Vs pyboard.py?

Post by dhylands » Mon May 08, 2017 4:34 pm

I think it depends on what you want to do. Try and it and see which way works best for you. As far as I can tell, either way can work fine.

starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

Re: USB_VCP Vs pyboard.py?

Post by starter111 » Sun May 21, 2017 8:39 pm

raw_repl is cool feature.. with pyboard.py right now I don't have any code in pyboard, everything runs in PC and works find..

I have a python question instead of upython...Let me know if this forum only allow upython questions, I can delete my post.

Here's my question..
How can I write a decorator for pyb.exec so I don't have to type pyb.exec every time..I know I can have my code in a file and run .execfile. but will be nice to have decorator for .exec too.

I want to have some thing like this..this's my self learning project, I don't have a schedule just find something to learn..any hit or example are welcome. I'm trying to find @micropython.asm_thumb source code as example, but don't know where is it.. I guess it does link your code to assembler?? which similar to what I trying to do?

@pyb.exec
def runpyboard():
pyb.LED(2).toggle()
run more pyb syntax

Post Reply