// umem_test_view.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "gc_scpt_itf.h"
#include "conio.h"
#include "windows.h"

#pragma comment(lib,"gc_scpt_itf.lib")


// 用户变量交互测试例子
// 注意：gc_scpt_itf.dll运行时需要QT的支持，可以将‘光盘\ScriptDev\ScriptDownload’目录下的文件拷贝到exe所在目录
int _tmain(int argc, _TCHAR* argv[])
{
    // Scpt初始化
    int rtn = ScptItf_Init(0,0,0, 2000, 3);
    if(rtn != 0)
    {
        printf("Scpt初始化 错误 = %d",rtn); getch();return 1;
    }

	int wAddr = 5;
	int rAddr = 25;
	double varW = 0;
	double varR[4];
	while(1)
	{
		rtn = ScptItf_UserVarWrite(0,0,wAddr+0,varW);
		if(rtn != 0) { printf("写用户变量 错误 = %d",rtn); getch();return 1; }
		rtn = ScptItf_UserVarWrite(0,1,wAddr+1,varW + 1);
		if(rtn != 0) { printf("写用户变量 错误 = %d",rtn); getch();return 1; }
		rtn = ScptItf_UserVarWrite(0,2,wAddr+2,varW + 2);
		if(rtn != 0) { printf("写用户变量 错误 = %d",rtn); getch();return 1; }
		rtn = ScptItf_UserVarWrite(0,3,wAddr+3,varW + 3);
		if(rtn != 0) { printf("写用户变量 错误 = %d",rtn); getch();return 1; }
		varW = varW + 10;
		if (varW > 100)
		{
			varW = 0;
		}

		rtn = ScptItf_UserVarRead(0,0,rAddr+0,&varR[0]);
		if(rtn != 0) { printf("写用户变量 错误 = %d",rtn); getch();return 1; }
		rtn = ScptItf_UserVarRead(0,1,rAddr+1,&varR[1]);
		if(rtn != 0) { printf("写用户变量 错误 = %d",rtn); getch();return 1; }
		rtn = ScptItf_UserVarRead(0,2,rAddr+2,&varR[2]);
		if(rtn != 0) { printf("写用户变量 错误 = %d",rtn); getch();return 1; }
		rtn = ScptItf_UserVarRead(0,3,rAddr+3,&varR[3]);
		if(rtn != 0) { printf("写用户变量 错误 = %d",rtn); getch();return 1; }
		printf("读用户变量值: %.0f  %.0f  %.0f  %.0f \r",varR[0],varR[1],varR[2],varR[3]);
		Sleep(500);
	}

	return 0;
}

