(defun C:RockeyFun()

;Command
(SETQ RY_FIND 1)
(SETQ RY_FIND_NEXT 2)
(SETQ RY_OPEN 3)
(SETQ RY_CLOSE 4)
(SETQ RY_READ 5)
(SETQ RY_WRITE 6)
(SETQ RY_RANDOM 7)
(SETQ RY_SEED 8)
(SETQ RY_WRITE_USERID 9)
(SETQ RY_READ_USERID 10)
(SETQ RY_SET_MOUDLE 11)
(SETQ RY_CHECK_MOUDLE 12)
(SETQ RY_WRITE_ARITHMETIC 13)
(SETQ RY_CALCULATE1 14)
(SETQ RY_CALCULATE2 15)
(SETQ RY_CALCULATE3 16)
(SETQ RY_DECREASE 17)
(SETQ ERR_SUCCESS 0)
(SETQ Handle 0)
(SETQ p1 50252)
(SETQ p2 51448)
(SETQ p3 1945)
(SETQ p4 50235)
(SETQ lp1 0)
(SETQ lp2 0)
(SETQ Buffer 0)
	       
(princ
    "\nThis is a simple program for the FeiTian Rockey4 Dongle\n"
)

(princ "Copyright (c) FeiTian Technology Ltd.\n\n")

 ; load ActiveX support
(vl-load-com)

;Load ActiveX
(vlax-import-type-library
    :tlb-filename "C:/Ry4Com.dll"
    :methods-prefix "Rockeym-"
    :properties-prefix "Rockeyp-"
    :constants-prefix "Rockeyc-"
) 

  ;Create object
(setq app (vlax-get-or-create-object "Ry4Com.Rockey4.1"))
(if (equal nil app)
(princ "\ncannot access Rockey4 COM module\n")
)
  
(princ "\naccess Rockey4 COM module Success\n")

 ;Find Rockey
(vlax-put-property app "p1" p1)
(vlax-put-property app "p2" p2)
(vlax-put-property app "p3" p3)
(vlax-put-property app "p4" p4)
(vlax-put-property app "lp1" lp1)
(vlax-put-property app "lp2" lp2)
(vlax-put-property app "handle" Handle)

 
(setq retcode(vlax-invoke-method app "DoCmd" RY_FIND))

(if (equal retcode ERR_SUCCESS)
(princ "\nFind Rockey Success:\n")
)

 ;Open Rockey
(setq retcode(vlax-invoke-method app "DoCmd" RY_OPEN))

(if (equal retcode ERR_SUCCESS)
(princ "\nOpen Rockey Success:\n")
)

;Write
(vlax-put-property app "p1" 3)
(vlax-put-property app "p2" 5)
(vlax-put-property app "buffer" "Hello")
(setq retcode(vlax-invoke-method app "DoCmd" RY_WRITE))
(if (equal retcode ERR_SUCCESS)
(princ "\nWrite Hello to Rockey Success:\n")
)

;Read
(vlax-put-property app "p1" 3)
(vlax-put-property app "p2" 5)
(setq retcode(vlax-invoke-method app "DoCmd" RY_READ))
(setq Buffer(vlax-get-property app "buffer"))
(princ "\nRead from rockey\n")
(if (equal retcode ERR_SUCCESS)
(prin1 Buffer)
)

;Random
(setq retcode (vlax-invoke-method app "DoCmd" RY_RANDOM))
(princ "\nRandom:")
(setq p1(vlax-get-property app "p1"))
(if (equal retcode ERR_SUCCESS)
(princ p1)
)

;Seed
(vlax-put-property app "lp2" 12345678) 
(setq retcode (vlax-invoke-method app "DoCmd" RY_SEED))
(princ "\nSeed:")
(setq p1(vlax-get-property app "p1"))
(if (equal retcode ERR_SUCCESS)
(princ p1)
)
(princ "\n")
(setq p2(vlax-get-property app "p2"))
(if (equal retcode ERR_SUCCESS)
(princ p2)
)
(princ "\n")
(setq p3(vlax-get-property app "p3"))
(if (equal retcode ERR_SUCCESS)
(princ p3)
)
(princ "\n")
(setq p4(vlax-get-property app "p4"))
(if (equal retcode ERR_SUCCESS)
(prin1 p4)
)
(princ "\n")



;Write USER ID
(vlax-put-property app "lp1" 88888888) 
(setq retcode (vlax-invoke-method app "DoCmd" RY_WRITE_USERID))
(if (equal retcode ERR_SUCCESS)
(princ "\nWrite User ID 88888888:")
)

;Read USER ID
(vlax-put-property app "lp1" 0) 
(setq retcode (vlax-invoke-method app "DoCmd" RY_READ_USERID))
(princ "\nRead User ID:")
(setq lp1 (vlax-get-property app "lp1"))  
(if (equal retcode ERR_SUCCESS)
(princ lp1)
)
(princ "\n")


 ;SET MODULE
(vlax-put-property app "p1" 7)
(vlax-put-property app "p2" 8481)
(vlax-put-property app "p3" 0)
(setq retcode (vlax-invoke-method app "DoCmd" RY_SET_MODULE))
(if (equal retcode ERR_SUCCESS) 
(princ "\nSET MODULE 7 0x2121:")
  )
(princ "\n")


;CHECK MODULE
(vlax-put-property app "p1" 7)
(setq retcode (vlax-invoke-method app "DoCmd" RY_CHECK_MODULE))
(princ "\nCHECK MODULE:")
(setq p2 (vlax-get-property app "p2"))  
(if (> p2 0) 
(princ "p2 is Allow")
)
(princ "\n") 



 
)

				