Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid serial port error trying to open CH343G based serial port #158

Open
nnnpa31 opened this issue Mar 1, 2023 · 10 comments
Open

Invalid serial port error trying to open CH343G based serial port #158

nnnpa31 opened this issue Mar 1, 2023 · 10 comments
Assignees
Labels

Comments

@nnnpa31
Copy link

nnnpa31 commented Mar 1, 2023

When does it happen
This error is reported when I open /dev/ttyCH343USB0.

What module
The device model is CH343G.

System and version information
Ubuntu 22.04, Go 1.20

Code

package main
...
func main() {
    mode := &serial.Mode{
	BaudRate: 921600,
	DataBits: 8,
	StopBits: 1,
	Parity:   serial.NoParity,
    }
    port, err := serial.Open("/dev/ttyCH343USB0", mode)
    if err != nil {
        panic(err) // The error happen here.
    }
    defer port.Close()
}

What's return

panic: Invalid serial port

More infomation
The same code and device can run on Windows, just replace /dev/ttyCH343USB0 with COM7.

I don't know what other information I need to provide about this. If you need it, please let me know and I will provide it as soon as possible.

Update: I can use the same settings to open it in the serial module of other languages.

@cyberxnomad
Copy link

Check this to see if it helps:
https://github.com/bugst/go-serial/blob/master/serial_linux.go#L12

@mateo08c
Copy link

mateo08c commented May 6, 2023

On Windows 11 (10.0.22621 Build 22621) i have the same error, but it works on ARM64 (Raspberry Pi 3B). I have a CH341 USB adapter.

@Heckelbert
Copy link

I have the same issue after updating to Windows 11.
The same code did run on Windows 10 just fine.

@mateo08c
Copy link

Up!

@cmaglie
Copy link
Member

cmaglie commented Feb 16, 2024

Did it work normally with other terminal emulators? like putty?
Is there an easy/cheap way to get one of those CH343G boards to try?

@mateo08c
Copy link

Did it work normally with other terminal emulators? like putty?
Is there an easy/cheap way to get one of those CH343G boards to try?

Yes it works perfectly with putty.

@cmaglie
Copy link
Member

cmaglie commented Feb 16, 2024

@mateo08c @nnnpa31 @xray-bit @Heckelbert
I've updated the library with better error reporting, could you retry with the latest v1.6.2 and paste the error here?
At least we could understand where the InvalidSerialPort error is raised...

@cmaglie cmaglie self-assigned this Feb 16, 2024
@cmaglie cmaglie added the bug label Feb 16, 2024
@mateo08c
Copy link

@mateo08c @nnnpa31 @xray-bit @Heckelbert I've updated the library with better error reporting, could you retry with the latest v1.6.2 and paste the error here? At least we could understand where the InvalidSerialPort error is raised...

It works! However, even with a defer and a call close function it still won't reopen for me afterward.

package main

import (
	"fmt"
	"go.bug.st/serial"
	"go.bug.st/serial/enumerator"
	"log"
)

func main() {
	ports, err := enumerator.GetDetailedPortsList()
	if err != nil {
		log.Fatal(err)
	}
	if len(ports) == 0 {
		fmt.Println("No serial ports found!")
		return
	}
	for _, port := range ports {
		fmt.Printf("Found port: %s\n", port.Name)
		if port.IsUSB {
			fmt.Printf("   USB ID     %s:%s\n", port.VID, port.PID)
			fmt.Printf("   USB serial %s\n", port.SerialNumber)
		}
	}

	open, err := serial.Open("COM11", &serial.Mode{
		BaudRate: 9600,
		DataBits: 8,
		Parity:   serial.NoParity,
		StopBits: serial.OneStopBit,
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	defer open.Close()

	buf := make([]byte, 1024)
	for {
		n, err := open.Read(buf)
		if err != nil {
			fmt.Println(err)
			return
		}

		fmt.Printf("Read %d bytes: %s\n", n, string(buf[:n]))
	}
}

First run:

Read 1 bytes:
Read 1 bytes:
Read 1 bytes:
Read 31 bytes: test, 32768k bytes found.
INFO
Read 1 bytes: :
Read 31 bytes:  Self tests complete.
INFO: Do
Read 1 bytes: w
Read 27 bytes: nloading switch software.
Read 1 bytes: E
Read 20 bytes: PROM download (Y) ?
Read 1 bytes: �
Read 31 bytes: ���♠Initial download successful
Read 1 bytes: .
Read 2 bytes: 
Read 1 bytes: F
Read 31 bytes: O: Initialising Flash File Syst
Read 1 bytes: e
Read 3 bytes: m. 
Read 1 bytes:  
Read 2 bytes: 
...etc

Second run:

Found port: COM5
Found port: COM3
Found port: COM4
Found port: COM8
Found port: COM10
Found port: COM6
Found port: COM11
   USB ID     1A86:7523
   USB serial
Invalid serial port

@cmaglie cmaglie changed the title Invalid serial port Invalid serial port error trying to open CH343G based serial port Feb 29, 2024
@577fkj
Copy link

577fkj commented Oct 8, 2024

I have also encountered the same problem, is there a solution.

@577fkj
Copy link

577fkj commented Oct 8, 2024

I have also encountered the same problem, is there a solution.

image
Using 3.3.2011.11 has restored normal operation, but why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants