PDA

View Full Version : [ubuntu] 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter does not work with Ubuntu



yunzhi-wu
September 8th, 2023, 10:12 PM
Hi! I have got a "1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter".
I am trying to use it on my Nano TX2 platform where Ubuntu 18.04 LTS is running.

I use python3 script with pyserial lib, it does not work. The same script and lib works fine on windows, i.e., bytes can be sent and received via port COM3.

It is ttyUSB0 in my Ubuntu. I can see it is detected. It seems that it can send, but it can not response.

I tried two methods. None of them fixed.

Method 1 is to check the rate. It is correct.
sudo stty -F /dev/ttyUSB0 -a

speed 19200 baud; rows 0; columns 0; line = 0;

intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;

eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;

werase = ^W; lnext = ^V; discard = ^O; min = 0; time = 0;

parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts

-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff

-iuclc -ixany -imaxbel -iutf8

-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0

-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt

-echoctl -echoke -flusho -extproc


Method 2:
sudo modprobe ch341


My python3 script is like:



import serial




def read_serial_port_info(serial_port):

packet = bytearray() # 02 03 00 01 00 04 15 fa

packet.append(0x02)

packet.append(0x03)

packet.append(0x00)

packet.append(0x01)

packet.append(0x00)

packet.append(0x04)

packet.append(0x15)

packet.append(0xfa)




serial_port.write(packet)




print('ttyUSB0 write done')




while 1:

# Wait until there is data waiting in the serial buffer

if serial_port.in_waiting > 0:

# Read data out of the buffer until a carraige return / new line is found

serial_bytes_read = serial_port.read(serial_port.in_waiting)

serial_bytes_list_hex = [hex(x).split('x')[-1] for x in serial_bytes_read]

print(serial_bytes_list_hex)

return serial_bytes_list_hex

break




def main():

serial_port = serial.Serial(

port="/dev/ttyUSB0", baudrate=19200, bytesize=8, timeout=20, stopbits=serial.STOPBITS_ONE, parity=serial.PARITY_EVEN

)

read_serial_port_info(serial_port)




if __name__ == "__main__":

main()

One LED blinks when to write to the converter (same as with windows), but no data come back. (In windows, it always sends data back correctly.)

On this page https://linux-hardware.org/?id=usb:1a86-7523&page=1, the device has been detected on Ubuntu. Only four rows "works", does it mean no one has verified it on Ubuntu?

Any idea what should I try?

Some info about my ttyUSB0:
Bus 001 Device 008: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

Device Descriptor:

bLength 18

bDescriptorType 1

bcdUSB 1.10

bDeviceClass 255 Vendor Specific Class

bDeviceSubClass 0

bDeviceProtocol 0

bMaxPacketSize0 8

idVendor 0x1a86 QinHeng Electronics

idProduct 0x7523 HL-340 USB-Serial adapter

bcdDevice 2.64

iManufacturer 0

iProduct 2

iSerial 0

bNumConfigurations 1

Configuration Descriptor:

bLength 9

bDescriptorType 2

wTotalLength 39

bNumInterfaces 1

bConfigurationValue 1

iConfiguration 0

bmAttributes 0x80

(Bus Powered)

MaxPower 98mA

Interface Descriptor:

bLength 9

bDescriptorType 4

bInterfaceNumber 0

bAlternateSetting 0

bNumEndpoints 3

bInterfaceClass 255 Vendor Specific Class

bInterfaceSubClass 1

bInterfaceProtocol 2

iInterface 0

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0x82 EP 2 IN

bmAttributes 2

Transfer Type Bulk

Synch Type None

Usage Type Data

wMaxPacketSize 0x0020 1x 32 bytes

bInterval 0

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0x02 EP 2 OUT

bmAttributes 2

Transfer Type Bulk

Synch Type None

Usage Type Data

wMaxPacketSize 0x0020 1x 32 bytes

bInterval 0

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0x81 EP 1 IN

bmAttributes 3

Transfer Type Interrupt

Synch Type None

Usage Type Data

wMaxPacketSize 0x0008 1x 8 bytes

bInterval 1

jeremy31
September 8th, 2023, 10:19 PM
Have you added your user to the dialout group

yunzhi-wu
September 8th, 2023, 10:30 PM
I have just added myself into that group, now I am in that group after I log out and log in:
groups
yunzhi adm dialout
Still issue remains.