Having trouble with USB_VCP

Your code is different, timeout=5 I think timeout is in milliseconds. I tested the following example on Linux and it’s working, can you try it ?

This is saved as main.py:

import ustruct
from pyb import USB_VCP

usb = USB_VCP()

while(True):
    try:
        cmd = usb.recv(4, timeout=5000)
        if (cmd == b'snap'):
            usb.send(ustruct.pack("<L", 1234))
    except:
        pass

And this is run from blender:

import sys, serial, struct
port = '/dev/ttyACM0'
sp = serial.Serial(port, baudrate=115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, xonxoff=False, rtscts=False, stopbits=serial.STOPBITS_ONE, timeout=None, dsrdtr=True)
sp.write(b"snap")
size = struct.unpack('<L', sp.read(4))[0]
sp.close()
print(size)

It prints (1234):

blender --background --python test.py 
1234
Blender quit

Note for isconnected to return True DTR must be set high. I see you’re testing on Windows maybe this is the issue. Anyway, let’s first try this simple example.