//#include <iostream>

#include "stdafx.h"
#include <stdio.h>
#include "stdafx.h"
#include "visatype.h"
#include "visa.h"
#include "Functions.h"
#include "windows.h"
#include "time.h"

#pragma comment( lib, "visa32" )

#using<system.dll>
using namespace System;
using namespace System::IO;

bool Meranie(char* name,char* tcpip)
{


ViSession vi,defaultRM,buf;
double temp_1,temp_2,temp_3,temp_4,temp_5,PT100,Ni_A,Ni_B,NTC,Thetmocouple;
double list [2] = {10,0.000001};
/* Open session to GPIB device at address 22 */
viOpenDefaultRM(&defaultRM);
viOpen(defaultRM,tcpip , 0, 0,&vi) ;
/* Initialize device */
viPrintf(vi, "*RST\n");



viPrintf(vi, "MEAS:RES? (@101)\n", list);
// Read results
viScanf(vi, "%lf", &temp_1);

viPrintf(vi, "MEAS:RES? (@102)\n", list);
//* Read results
viScanf(vi, "%lf", &Ni_A);



viPrintf(vi, "MEAS:RES? (@101)\n", list);
// Read results
viScanf(vi, "%lf", &temp_2);

viPrintf(vi, "MEAS:RES? (@103)\n", list);
//* Read results *
viScanf(vi, "%lf", &Ni_B);



viPrintf(vi, "MEAS:RES? (@101)\n", list);
// Read results
viScanf(vi, "%lf", &temp_3);

viPrintf(vi, "MEAS:RES? (@104)\n", list);
//* Read results *
viScanf(vi, "%lf", &PT100);



viPrintf(vi, "MEAS:RES? (@101)\n", list);
// Read results
viScanf(vi, "%lf", &temp_4);

viPrintf(vi, "MEAS:RES? (@105)\n", list);
//* Read results *
viScanf(vi, "%lf", &NTC);



viPrintf(vi, "MEAS:RES? (@101)\n", list);
// Read results
viScanf(vi, "%lf", &temp_5);

viPrintf(vi, "MEAS:VOLT? (@106)\n", list);
//* Read results *
viScanf(vi, "%lf", &Thetmocouple);



viClose(vi);
viClose(defaultRM);

	temp_1= RtoTemp (temp_1);
	temp_2= RtoTemp (temp_2);
	temp_3= RtoTemp (temp_3);
	temp_4= RtoTemp (temp_4);
	temp_5= RtoTemp (temp_5);

	String ^ nam = gcnew String (name);
	StreamWriter^ sw = File::AppendText(nam);

	char tab='\t';

	sw->Write(System::Convert::ToString(temp_1));
	sw->Write(tab);
	sw->Write(System::Convert::ToString(Ni_A));
	sw->Write(tab);

	sw->Write(System::Convert::ToString(temp_2));
	sw->Write(tab);
	sw->Write(System::Convert::ToString(Ni_B));
	sw->Write(tab);

	sw->Write(System::Convert::ToString(temp_3));
	sw->Write(tab);
	sw->Write(System::Convert::ToString(PT100));
	sw->Write(tab);

	sw->Write(System::Convert::ToString(temp_4));
	sw->Write(tab);
	sw->Write(System::Convert::ToString(NTC));
	sw->Write(tab);

	sw->Write(System::Convert::ToString(temp_5));
	sw->Write(tab);
	sw->WriteLine(System::Convert::ToString(Thetmocouple));


   sw->Close();

   return true;
}