{"id":18809325,"url":"https://github.com/xluohome/serial","last_synced_at":"2025-04-13T20:27:06.361Z","repository":{"id":49899651,"uuid":"239712230","full_name":"xluohome/serial","owner":"xluohome","description":"Go语言实现的uart串口发送和接收接口包，跨平台支持","archived":false,"fork":false,"pushed_at":"2020-02-14T05:29:43.000Z","size":54,"stargazers_count":33,"open_issues_count":1,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-19T01:58:08.943Z","etag":null,"topics":["mcu","mcuuart","serialport","txrx","uart"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xluohome.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-11T08:29:40.000Z","updated_at":"2024-05-11T06:31:56.000Z","dependencies_parsed_at":"2022-08-31T06:40:29.763Z","dependency_job_id":null,"html_url":"https://github.com/xluohome/serial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xluohome%2Fserial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xluohome%2Fserial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xluohome%2Fserial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xluohome%2Fserial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xluohome","download_url":"https://codeload.github.com/xluohome/serial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223602618,"owners_count":17171952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mcu","mcuuart","serialport","txrx","uart"],"created_at":"2024-11-07T23:15:59.468Z","updated_at":"2024-11-07T23:15:59.538Z","avatar_url":"https://github.com/xluohome.png","language":"Go","readme":"[![GoDoc](https://godoc.org/github.com/xluohome/serial?status.svg)](http://godoc.org/github.com/xluohome/serial)\n\n\n![](uart.jpg)\n\n# Serial\n\nSerial 是一个Go语言实现的串口(Uart)接口包,可使用操作系统标准的 read 和 write 文件接口\n实现串口字节流的接收和发送。\n\n\n## 默认配置\n \n\u003e 8 N 1 N （数据位: 8 奇偶校验: N 停止位: 1 数据流控: N）\n\n\n## 代码使用\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/xluohome/serial\"\n)\n\nfunc main() {\n\tc := \u0026serial.Config{Name: \"COM9\", Baud: 9600}\n\ts, err := serial.OpenPort(c)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\ttxbuf := []byte{0xAA, 0x01, 0x0f, 0x00, 0x00, 0xBA}\n\n\tn, err := s.Write(txbuf)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tbuf := make([]byte, 128)\n\tn, err = s.Read(buf)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tlog.Printf(\"%X\\n\", buf[:n])\n}\n\n```\n\n## 非阻塞模式\n\nBy default the returned Port reads in blocking mode. Which means\n`Read()` will block until at least one byte is returned. If that's not\nwhat you want, specify a positive ReadTimeout and the Read() will\ntimeout returning 0 bytes if no bytes are read.  Please note that this\nis the total timeout the read operation will wait and not the interval\ntimeout between two bytes.\n\n```go\n\tc := \u0026serial.Config{Name: \"COM45\", Baud: 115200, ReadTimeout: time.Second * 5}\n\t\n\t// In this mode, you will want to suppress error for read\n\t// as 0 bytes return EOF error on Linux / POSIX\n\tn, _ = s.Read(buf)\n```\n\n ","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxluohome%2Fserial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxluohome%2Fserial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxluohome%2Fserial/lists"}