ceshi_test.go 732 B

1234567891011121314151617181920212223242526272829303132333435
  1. package test1
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. "server/initialize"
  7. "testing"
  8. )
  9. type Ceshi1 struct{}
  10. const dataFilePath = "../static/devicePath.json"
  11. func TestCeshi(t *testing.T) {
  12. for _, connection := range initialize.ConnectionPool {
  13. fmt.Println("111")
  14. fmt.Println(connection)
  15. results, err := connection.Tcp.ReadInputRegisters(0x03EE, 0x0008)
  16. if err != nil {
  17. fmt.Printf("Failed to write to Modbus device: %v\n", err)
  18. return
  19. }
  20. fmt.Printf("Write Multiple Registers: %v\n", string(results))
  21. }
  22. }
  23. // 保存数据到文件
  24. func saveData(parameter interface{}) error {
  25. data, err := json.MarshalIndent(parameter, "", " ")
  26. if err != nil {
  27. return err
  28. }
  29. return os.WriteFile(dataFilePath, data, 0644)
  30. }