天天看点

玩转USB虚拟串口

1 Linux serial

1.1 Linux控制串口的各种属性

busybox stty -F /dev/ttyS0 -a

busybox setserial -a /dev/ttyS0

busybox

https://busybox.net/downloads/binaries/1.28.1-defconfig-multiarch/

1.2 Linux slcand

slcan:the serial line CAN(using tty line discipline,N_SLCAN),用于CAN dongle,将Linux上的CAN转串口(ttyUSB0或者ttyACM0)桥接到socketCAN

2 Windows VCP

2.1 禁止USB转串口序列号检查

Write a reg file(Disable_Ser_SN_CHK.reg), then add the following comment.

Windows Registry Editor Version5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\usbflags]

"GlobalDisableSerNumGen"=hex:01

2.2 USB Protocol Analyzer Beagle

1)修改时间戳到Wall时间

Time-Item Right Click>>Timestamp Reference>>Wall Time View

2)Guide

Beagle使用前,USB Host的VBUS必须连接,否则会探测不到硬件,并且显示“host disconnect”

3 Windows pyserial

3.1 install

https://pypi.python.org/pypi/pyserial

pip install pyserial

3.2 showcase

import io

import os

import re

import shutil

import sys

import serial

from serial.tools import list_ports

arg0_proc_name = ''

def print_usage():

    print('\nUsage: python ' + arg0_proc_name + ' <COM_PORT>\n')

def my_print(string):

    for char in string:

        print(char, end='')

def list_serial_ports():

    print('Available serial ports:\n')

    for dev in list_ports.grep('COM', include_links=True):

        print(dev)

def serial_reader(port):

    try:

        while True:

            # port.write(('\x1c' + '\n').encode())

            count = port.inWaiting()

            if count > 0:

                raw = port.read(count)

                my_print(raw.decode())

    except KeyboardInterrupt:

            print('Got ^C signal, will close '  + port.name)

def main():

    global arg0_proc_name

    arg0_proc_name = sys.argv[0]

    if sys.argv[0].rfind(os.path.sep) > 0:

        index = sys.argv[0].rfind(os.path.sep)

        arg0_proc_name = sys.argv[0][index+1:]

    if len(sys.argv) < 2:

        print_usage()

        list_serial_ports()

        exit(0)

    print('Enter Ctrl + C to exit')

    try:

        port = serial.Serial(sys.argv[1],

            baudrate=115200,

            bytesize=serial.EIGHTBITS,

            stopbits=serial.STOPBITS_ONE,

            parity=serial.PARITY_NONE,

            xonxoff=0,

            rtscts=0,

            timeout=None)

    except IOError:

        print('Please ensure close all applications that opened ' + sys.argv[1])

        exit(0)

    # script_dir = os.path.split(os.path.realpath(sys.argv[0]))[0]

    serial_reader(port)

    if port != None:

        port.close()

if __name__ == '__main__':

    main()

4 Abbreviations

ARC:Argonant RISC Core

AT91SAM9260:SAM means Smart ARM-based Microcontroller

ATMEL SAMBA:ATMEL Smart ARM-based Microcontroller Boot Assistant

CC2530:TI ChipCon2530

DWC2:Design Ware Controller 2,Apple的嵌入式设备,包括iPad和iPhone都是使用的DWC2

FTDI_SIO:FTDI Serial Input/Output

ISP1161:Philips' Integrated host Solution Pairs 1161,“Firms introduce USB host controllers”,https://www.eetimes.com/document.asp?doc_id=1290054

SL811HS:Cypress/ScanLogic 811 Host/Slave,性能上与ISP1161(Integrated host Solution Pairs 1161)相当

TDI:TransDimension Inc.,该公司首先发明了将TT集成到EHCI RootHub中的方法,这样对于嵌入式系统来说,就省去了OHCI/UHCI的硬件,同时降低了成本,作为对该公司的纪念,Linux内核定义了宏ehci_is_TDI(ehci);产品UHC124表示USB Host Controller;收购了ARC USB技术;现已被chipidea收购,chipidea又被mips收购

TLV:TI Low Value,高性价比

TPS:TI Performance Solution

TT:Transaction Translator(事务转换器,将USB2.0的包转换成USB1.1的包)

USB BH reset:Bigger Hammer or Brad Hosler,表示warm reset;you may be confused why the USB 3.0 spec calls the same type of reset "warm reset" in some places and "BH reset" in other places. "BH" reset is supposed to stand for "Big Hammer" reset, but it also stands for "Brad Hosler". Brad died shortly after the USB 3.0 bus specification was started, and they decided to name the reset after him. The suggestion was made shortly before the spec was finalized, so the wording is a bit inconsistent

WHL:Python Wheel Package

Zadig:an Automated Driver Installer GUI application for WinUSB, libusb-win32 and libusbK