xcom_parser.xcom 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. {
  2. P0046F56202C21000T : {
  3. name:雷优/单相电表/阀控,
  4. protocol:{
  5. ```xcom
  6. #型号 modbus(crc16)
  7. def crc_modbus: $crc16($1,0x8005,0xffff,0x0000,1,1)
  8. # 以上可以定义公共函数
  9. def modbus_read_req:[$num($addr) $fcode $itom(2,$reg) $itom(2,$reglen) $crc_modbus($group(0,$pos))]
  10. def modbus_read_resp:[$num($addr) $fcode $ditch(1,{dl=$int($0)}) $ditch($dl, {data=$0}) $ditch(2,{$chk($0,$crc_modbus($group(0,$pos)))})]
  11. def modbus_write_req:[$num($addr) $fcode $itom(2,$reg) $itom(2,$reglen) $len($1) $1 $crc_modbus($group(0,$pos))]
  12. def modbus_write_resp:[$num($addr) $fcode $ditch(1,{dl=$int($0)}) $ditch($dl,{data=$0}) $ditch(2,{$chk($0,$crc_modbus($group(0,$pos)))})]
  13. ```
  14. # read,write表示读写流程,名称可以自定义,但要与funcpoints的flow绑定名称一致
  15. read:{
  16. send:$modbus_read_req()
  17. recv:$modbus_read_resp()
  18. },
  19. write:{
  20. send:$modbus_write_req($if($1==0, [22H 22H], [11H 11H]))
  21. recv:$modbus_write_resp()
  22. }
  23. },
  24. funcpoints:{
  25. 11X:{flow:read, fcode:03H, reg: 0000H, reglen:2, result:$float($data)},
  26. 12K:{flow:write, fcode:10H, reg: 0db8H, reglen:1, result:$int($data)}
  27. }
  28. },
  29. P056934A925C21000T : {
  30. name:雷优/485/多回路水表V2,
  31. protocol:{
  32. ```xcom
  33. def chksum: $itom(1,$sum($1)%256)
  34. # $addr $len 都是输入的参数
  35. def cj188_read_req: [68H $fcode $sbcd($addr) 01H 3 $itom(3,$seq) $chksum($group(0,$pos)) 16H]
  36. def cj188_read_resp: [68H $fcode $sbcd($addr) 81H $ditch(1,{dl=$int($0)-3}) $itom(3,$seq) $ditch($dl,{data=$0}) $ditch(1) 16H]
  37. ```
  38. # read,write表示读写流程,名称可以自定义,但要与funcpoints的flow绑定名称一致
  39. read:{
  40. send:$cj188_read_req()
  41. recv:$cj188_read_resp()
  42. },
  43. write:{
  44. send:$cj188_write_req()
  45. recv:$cj188_write_resp()
  46. }
  47. },
  48. funcpoints:{
  49. 12L:{flow:read, fcode:10H, seq: 0x1f9001, result:$bcd($data,0,4)*0.001},
  50. 12P:{flow:12L, fcode:10H, seq: 0x1f9001, result:$bcd($data,4,4)*0.0001},
  51. 14Z:{flow:12L, fcode:10H, seq: 0x1f9001, result:$bcd($data,11,2)*0.1},
  52. 13B:{flow:12L, fcode:10H, seq: 0x1f9001, result:$int8($data,13,1)},
  53. 401:{flow:12L, fcode:10H, seq: 0x1f9001, result:$bcd($data,4,4)},
  54. 402:{flow:12L, fcode:10H, seq: 0x1f9001, result:$bcd($data,4,4)},
  55. 403:{flow:12L, fcode:10H, seq: 0x1f9001, result:$bcd($data,4,4)},
  56. 404:{flow:12L, fcode:10H, seq: 0x1f9001, result:$bcd($data,4,4)},
  57. 405:{flow:12L, fcode:10H, seq: 0x1f9001, result:$bcd($data,4,4)},
  58. }
  59. }
  60. }