虚拟串口如何得到int型数据?
-
想通过虚拟串口接收int数据,但是以下代码却得不到想要的结果。本来应该是发送1,led灯会亮,但是实际上却不行
代码:import sensor, image, time, ustruct from pyb import USB_VCP,LED green_led = LED(2) red_led = LED(1) usb = USB_VCP() sensor.reset() # Reset and initialize the sensor. sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE) sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240) sensor.skip_frames(time = 2000) # Wait for settings take effect. while(True): if USB_VCP.any(): cmd = usb.readline().decode().strip() val = int(cmd) if (val == 1): green_led.on()
-
确保你在串口助手里,选择了ascii或者utf8发送了字符串1,而不是发送的数字1.