package test1 import ( "encoding/json" "fmt" "os" "server/initialize" "testing" ) type Ceshi1 struct{} const dataFilePath = "../static/devicePath.json" func TestCeshi(t *testing.T) { for _, connection := range initialize.ConnectionPool { fmt.Println("111") fmt.Println(connection) results, err := connection.Tcp.ReadInputRegisters(0x03EE, 0x0008) if err != nil { fmt.Printf("Failed to write to Modbus device: %v\n", err) return } fmt.Printf("Write Multiple Registers: %v\n", string(results)) } } // 保存数据到文件 func saveData(parameter interface{}) error { data, err := json.MarshalIndent(parameter, "", " ") if err != nil { return err } return os.WriteFile(dataFilePath, data, 0644) }