sniper_nuko

Extended script GP4301TW

May 10th, 2021
1,393
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Extended script GP4301TW
  2. // Master:RS232C -> Uart -> I2C
  3. // Slave:I2C -> Uart -> RS232C
  4.  
  5. // Clear Data buffer
  6. _strset(databuf0, "")
  7. _strset(databuf1, "")
  8. _strset(databuf2, "")
  9. _strset(databuf3, "")
  10.  
  11. // Clear internal device
  12. memset([w:[#INTERNAL]USR00010], 0, 10)
  13. memset([w:[#INTERNAL]USR00020], 0, 10)
  14.  
  15. // I2C write command string setting
  16. // I2C write command: "S" "addr" "bytes" "data1" "data2" "..." "P"
  17. [w:[#INTERNAL]USR00011]=0x0053  // "S"
  18. [w:[#INTERNAL]USR00012]=0x00BE  // "addr"
  19.  
  20. // Input value over 0x00FF
  21. if([w:[#INTERNAL]USR00000]>0x00FF)
  22. {
  23.     [w:[#INTERNAL]USR00010]=6
  24.     [w:[#INTERNAL]USR00013]=2   // "bytes"
  25.     [w:[#INTERNAL]USR00014]=[w:[#INTERNAL]USR00001] "data1"
  26.     [w:[#INTERNAL]USR00015]=[w:[#INTERNAL]USR00002] "data2"
  27.     [w:[#INTERNAL]USR00016]=0x0050  // "P"
  28. }
  29. else
  30. {
  31.     [w:[#INTERNAL]USR00010]=5
  32.     [w:[#INTERNAL]USR00013]=1   // "bytes"
  33.     [w:[#INTERNAL]USR00014]=[w:[#INTERNAL]USR00002] "data1"
  34.     [w:[#INTERNAL]USR00015]=0x0050  // "P"
  35.     [w:[#INTERNAL]USR00016]=0x0000
  36. }
  37. endif
  38.  
  39. // Store command string in data buffer
  40. _ldcopy(databuf0, [w:[#INTERNAL]USR00011], [w:[#INTERNAL]USR00010])
  41. _strlen([w:[#INTERNAL]USR00020], databuf0)
  42.  
  43. // Reset SIO port
  44. [c:EXT_SIO_CTRL00]=1
  45. [c:EXT_SIO_CTRL01]=1
  46. [c:EXT_SIO_CTRL02]=1
  47.  
  48. // Wait 200ms
  49. _wait(2)
  50.  
  51. // Send command
  52. IO_WRITE_EX([p:EXT_SIO], databuf0, [w:[#INTERNAL]USR00020])
RAW Paste Data