Danke im Voraus
Code: Select all
#include <iostream>
#include <windows.h>
#include "iowkit.h"
using namespace std;
typedef CHAR special_report[8];
double gettemp(IOWKIT_HANDLE iohandle)
{
char temp_high=0;
char temp_low=0;
double temp=0.0;
ULONG ret;
cout << "Setting Write-Register" << endl;
special_report report;
report[0]=2;
report[1]=2;
report[2]=0x4C;
report[3]=0x01;
report[4]=0;
report[5]=0;
report[6]=1;
report[7]=1;
ret=IowKitWrite(iohandle,1,report,8);
cout << "Write-Register set" << endl;
if(ret==8){
cout << "Sending Read-Request" << endl;
report[0]=3;
report[1]=1;
report[2]=0x4C;
report[3]=0;
report[4]=0;
report[5]=0;
report[6]=0;
report[7]=0;
ret=IowKitWrite(iohandle,1,report,8);
cout << "Read-Request send" << endl;
report[0]=3;
report[1]=0;
report[2]=0;
report[3]=0;
report[4]=0;
report[5]=0;
report[6]=0;
report[7]=0;
cout << "Getting Results of High-Byte" << endl;
ret=IowKitRead(iohandle,1,report,8);
cout << "Got Results" << endl;
for(int i=0;i<=8;i++) {
int x=0;
x=report[i];
cout << x << endl;
}
if(report[0]==2){
cout << "Writing to Variable" << endl;
temp_high=report[1];
}
}
else cout << "Fehler!" << endl;
cout << "Setting Write-Register" << endl;
report[0]=2;
report[1]=2;
report[2]=0x4C;
report[3]=0x10;
report[4]=0;
report[5]=0;
report[6]=1;
report[7]=1;
ret=IowKitWrite(iohandle,1,report,8);
cout << "Write-Register set" << endl;
if(ret==IOWKIT_SPECIAL_REPORT_SIZE){
cout << "Sending Read-Request for Low-Byte" << endl;
report[0]=3;
report[1]=2;
report[2]=0x4C;
report[3]=0;
report[4]=0;
report[5]=0;
report[6]=0;
report[7]=0;
ret=IowKitWrite(iohandle,1,report,8);
cout << "Read-Request send" << endl;
report[0]=3;
report[1]=0;
report[2]=0;
report[3]=0;
report[4]=0;
report[5]=0;
report[6]=0;
report[7]=0;
cout << "Getting Resulsts for Low-Byte" << endl;
ret=IowKitRead(iohandle,1,report,8);
for(int i=0;i<=8;i++) {
int x=0;
x=report[i];
cout << x << endl;
}
if(report[0]==2){
cout << report[0] << endl;
cout << report[1] << endl;
cout << report[2] << endl;
temp_low=report[1];
}
}
else cout << "Fehler!" << endl;
switch(temp_low){
case 0:temp=temp+0.0;break;
case 64:temp=temp+0.25;break;
case 128:temp=temp+0.5;break;
case 192:temp=temp+0.75;break;
default:break;
}
temp=temp+(double)temp_high;
return temp;
}
int main()
{
cout << "Start!" << endl;
IOWKIT_HANDLE iohandle;
cout << "create iohandle" << endl;
iohandle = IowKitOpenDevice();
cout << "Device open" << endl;
if(iohandle!=NULL){
cout << "Start IIC" << endl;
ULONG res;
special_report start_iic;
start_iic[0] = 1;
start_iic[1] = 1;
start_iic[2] = 0;
start_iic[3] = 0;
start_iic[4] = 0;
start_iic[5] = 0;
start_iic[6] = 0;
start_iic[7] = 0;
res=IowKitWrite(iohandle,1,start_iic,8);
cout << "IIC started" << endl;
if(res!=8){
cout << "Fehler!" << endl;
}
else{
special_report send_rep;
send_rep[0]=2;
send_rep[1]=3;
send_rep[2]=0x4C;
send_rep[3]=0x0A;
send_rep[4]=0x0A;
send_rep[5]=0;
send_rep[6]=1;
send_rep[7]=1;
cout << "Setting up ADT" << endl;
res=IowKitWrite(iohandle,1,send_rep,8);
Sleep(1000);
cout << "ADT set up" << endl;
double x = gettemp(iohandle);
cout << "Got temp" << endl;
cout << x << endl;
cout << "Fertig" << endl;
}
}
else{
cout << "Fehler: Kann IOWarrior nicht oeffnen!" << endl;
}
IowKitCloseDevice(iohandle);
}