Ry4 Interface for C#
1.
Manual install Ry4Com.dll -- regsvr32 Ry4Com.dll
Manual uninstall Ry4Com.dll -- regsvr32 /u Ry4Com.dll

(RockeyControlVal.ocx is in the "\\Api32\COM\\" directory)
or call routines in Ry4Com.dll.


2.Create a c# project by VS.Net, Select Reference in Solution,then click Com, select "Rockey4 Classlibrary for .Net",Add the reference of Ry4Com.dll to project.
3.Add below codes to your program:

using System.Runtime.InteropServices;
using ROCKEY4;;

4.Add below enums to your program. (Caution: The return code of Ry4COM is NOT same as Rockey4 API. The rule of new return code is : HIWORD is 0x8030,LOWORD is return code of Rockey4 API).

enum Ry4Cmd:ushort
{
		RY_FIND=1,			//Find Rockey4.
		RY_FIND_NEXT,			//Find next Rockey4.
		RY_OPEN,			//Open 
		RY_CLOSE,			//Close
		RY_READ,			//Read UDZ
		RY_WRITE,			//Write UDZ
		RY_RANDOM,			//Random
		RY_SEED,			//Seed code
		RY_WRITE_USERID,		//Write UID
		RY_READ_USERID,			//Read UID
		RY_SET_MODULE,			//Write module
		RY_CHECK_MODULE,		//Check module status
		RY_WRITE_ARITHMETIC,		//Write UAZ
		RY_CALCULATE1,			//Calculate 1
		RY_CALCULATE2,			//Calculate 2
		RY_CALCULATE3,			//Calculate 3
		RY_DECREASE			//Decrease
};


enum Ry4Type:uint
{
		// Rockey4 Type
		TYPE_ROCKEY4=1,			//Normal Ry4.
		TYPE_ROCKEY4Plus,		//Ry4Plus.
		TYPE_ROCKEYUSB,			//Ry4 USB.
		TYPE_ROCKEYUSBPlus,		//Ry4 USB Plus
		TYPE_ROCKEYNET,			//NetRy4
		TYPE_ROCKEYUSBNET		//NetRy4 USB.
};


	
enum Ry4ErrCode:uint
{
	ERR_SUCCESS=0,				//No error.
        ERR_NO_PARALLEL_PORT=0x80300001,	//(0x80300001)No parallel port on the computer 
        ERR_NO_DRIVER,				//(0x80300002)No driver installed 
        ERR_NO_ROCKEY,				//(0x80300003)No ROCKEY4 dongle 
        ERR_INVALID_PASSWORD,			//(0x80300004)ROCKEY4 dongle found, but base password is incorrect
        ERR_INVALID_PASSWORD_OR_ID,		//(0x80300005)Wrong password or ROCKEY4 HID
        ERR_SETID,				//(0x80300006)Set ROCKEY4 HID wrong
        ERR_INVALID_ADDR_OR_SIZE,		//(0x80300007)Read/Write address is wrong
        ERR_UNKNOWN_COMMAND,			//(0x80300008)No such command
        ERR_NOTBELEVEL3,			//(0x80300009)Inside error
        ERR_READ,				//(0x8030000A)Read error
        ERR_WRITE,				//(0x8030000B)Write error
        ERR_RANDOM,				//(0x8030000C)Random error
        ERR_SEED,				//(0x8030000D)Seed Code error
        ERR_CALCULATE,				//(0x8030000E)Calculate error
        ERR_NO_OPEN,				//(0x8030000F)Ry_Open must precede this operation
        ERR_OPEN_OVERFLOW,			//(0x80300010)Too many open dongles (>16)
        ERR_NOMORE,				//(0x80300011)No more dongle
        ERR_NEED_FIND,				//(0x80300012)No Find before FindNext
        ERR_DECREASE,				//(0x80300013)Decrease error
        ERR_AR_BADCOMMAND,			//(0x80300014)Arithmetic instruction error
        ERR_AR_UNKNOWN_OPCODE,			//(0x80300015)Arithmetic operator error
        ERR_AR_WRONGBEGIN,			//(0x80300016)A constant. cannot be in the first instruction
        ERR_AR_WRONG_END,			//(0x80300017)A constant. cannot be in the last instruction 
        ERR_AR_VALUEOVERFLOW,			//(0x80300018)Const number > 63

	ERR_UNKNOWN=0x8030ffff,			//(0x8030FFFF)Unknown error 

	ERR_RECEIVE_NULL=0x80300100,		//(0x80300100)Parallel port can not recieve data.
	ERR_PRNPORT_BUSY=0x80300101		//(0x80300101)Parallel port is busy.

	};

5.Create Rockey4 class by this line:

CRockey4Class ry4=new CRockey4Class();

Then you can call DoCmd routine of ry4.

6.DoCmd usage and parameters:

(1)Define variables you will use:

uint	lp1=0,lp2=0;				//long parameters, please see manual
ushort	p1=0,p2=0,p3=0,p4=0;			//short parameters,please see manual
ushort  handle=0				//Handle of opened device.
object	obBuffer=(int)0;			//object to store byte array or string. 

(2)obBuffer usage

obBuffer only used by below commands:

Command	   		obBuffer Direction	Data type

RY_READ	   		[out]			Return a Byte array,stored UDZ information.
RY_WRITE   		[in]                 	Set to a byte array, stored UDZ information.
RY_WRITE_ARITHMETIC	[in]			Set to a arithmetic string.

In other commands, you can set it to 0 by line "obBuffer=(int)0;" to improve efficiency.

