Posted to tcl by grummund at Thu Jun 01 19:32:23 GMT 2017view raw

  1. #!/usr/bin/expect -f
  2.  
  3. log_file -noappend modbustest.log
  4.  
  5. set device /dev/ttyUSB0
  6. spawn -open [open $device r+]
  7. stty 9600 cs8 parenb -cstopb raw < $device
  8. fconfigure $spawn_id -encoding binary -translation binary
  9.  
  10. # fconfigure stdin -encoding binary -translation binary
  11. # fconfigure stdout -encoding binary -translation binary
  12.  
  13. send "\xE0\x10\x4E\x74\x00\x02\x04\x42\x78\x00\x00\x4F\x85"
  14. expect "\xE0\x10\x4E\x74\x00\x02\x01\x4B"
  15.  
  16. after 1000
  17.  
  18. send "\xE0\x10\x4E\x72\x00\x02\x04\x44\x7A\x00\x00\x6E\xE7"
  19. expect "\xE0\x10\x4E\x72\x00\x02\xE1\x4A"
  20.  
  21. after 1000
  22.  
  23. send "\xE0\x06\x00\x64\x00\x00\xDF\xA4"
  24. expect "\xE0\x06\x00\x64\x00\x00\xDF\xA4"
  25.  
  26. after 1000
  27.  
  28. send "\xE0\x06\x00\x65\x00\x00\x8E\x64"
  29. expect "\xE0\x06\x00\x65\x00\x00\x8E\x64"
  30.  
  31. after 1000
  32.  
  33. send "\xE0\x06\x00\x66\x00\x00\x7E\x64"
  34. expect "\xE0\x06\x00\x66\x00\x00\x7E\x64"
  35.  
  36. after 1000
  37.  
  38. send "\xE0\x06\x00\xC8\x00\x05\xDF\x86"
  39. expect "\xE0\x06\x00\xC8\x00\x05\xDF\x86"
  40.  
  41. exit
  42.