Chanaka
Posts: 1
Joined: Thu Nov 03, 2016 1:58 pm

How Configure HL-340 USB-Serial adapter

Thu Nov 03, 2016 2:35 pm

I'm new to raspberry pi. I tried to connect PLC with raspberry pi using 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter. but it is not working. what i did is.
1 download zip file of above adapter driver for Linux
2 extract it
3 run make command
4 connect USB serial adapter to raspberry pi ( I connected pin 2 and pin 3 of serial port together)
5 run putty on raspberry and select serial and type port as ttyUSB0 and clicked open
6 then new windows was popup and when i type on keyboard there is no any letters appear. cursor position changed for some keys
is it converter problem ? or is there any method to connect PLC with raspberry pi via modbus protocol?

andytran
Posts: 1
Joined: Fri Dec 02, 2016 5:37 am

Re: How Configure HL-340 USB-Serial adapter

Fri Dec 02, 2016 5:48 am

The same for me
[email protected]:~ $ lsusb
Bus 001 Device 006: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
Bus 001 Device 005: ID 046d:c077 Logitech, Inc.
Bus 001 Device 004: ID 413c:2107 Dell Computer Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
[email protected]:~ $ ls -l /dev/ttyUSB*
crwxrwxrwx 1 root dialout 188, 0 Dec 2 05:32 /dev/ttyUSB0
Bus 001 Device 006: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
Couldn't open device, some information will be missing
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.54
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 96mA
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
[email protected]:~ $ python -m serial.tools.list_ports
/dev/ttyS0
/dev/ttyUSB0
2 ports found
>>> ser.open()
>>> ser
Serial<id=0x76a21c50, open=True>(port='/dev/ttyUSB0', baudrate=19200, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)
>>> ser.readall()
''
>>> ser.write("sw i01\r\n")
8
>>> ser.readall()

robertfsix
Posts: 1
Joined: Sun Oct 07, 2018 6:07 am

Re: How Configure HL-340 USB-Serial adapter

Sun Oct 07, 2018 6:21 am

This is a very late posting and perhaps this is not any issue anymore. However for anyone that cares.....

The HL-340 USB-to-RS232 adaptors I have seen (& purchased on eBay) seem to be all *defective*.

More specifically, they do not generate the correct voltage swings on the RS232 TxD pin. I know this because I bought some and could not get them to work. I plugged in an alternative adaptor (using the PL2303 chip) and there was no problem. I then checked the RS232 data pins on an oscilloscope.

The HL-340 voltages on TxD were no good. RS232 requires a -5 to +5 volt swing. The HL-340s gave about 0 to +3v.

But voltages are good from the PL2303 adaptors I have used. I have had no problem with the PL2303 USB to Rs232 adaptors.

It is possible I just had a bad batch. The RS232 voltages are generated by a transceiver chip after the HL-340. So I am not saying every HL-340 based adaptor eve3ry produced will fail. Just the ones I have seen to date.

Also - FYI - I have had no issue with the MCS7840 adaptors (USB to 4-port RS232). They are commonly available on eBay for about US$20-$30. They work straight off on current Raspbian "stretch". I presume the 2-port variant MCS7820 would also work seamlessly.

The MCS7840 is an easy and cheap way to add 4,8,12,.... ports to a Pi.

Cheers,

Bob.

delta_vee
Posts: 1
Joined: Sun Jun 09, 2019 12:00 am

Re: How Configure HL-340 USB-Serial adapter

Sun Jun 09, 2019 12:11 am

"The RS232 voltages are generated by a transceiver chip after the HL-340." Bob, are you mixing up CH340 and HL-340? HL-340 is a model of USB to serial cable that uses a CH340 chip (datasheet: https://cdn.sparkfun.com/datasheets/Dev ... 340DS1.PDF)

Return to “Beginners”