blaza
19th August 2007, 17:30
First of all Hi...
This is my first post... I need some help!
I have made some code for reading from parallel port. It work very good compiled with VSC++ like console application... It read LPT 1 sending results to screen and to file...
When I tried to compile with qt, my first problem is that I need to call 3 *.lib for LPT communication...(or load dll library! how)
Second problem is how to send result value to Qt form?!
#include <stdafx.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <windows.h>
#define E 8
#define DIN 32
#define CS 64
#define CLK 128
#define DOUT 128
#define LPT 888
#define vref 2.5
short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);
int main()
{
int prs, lima, p, limas, ps;
int ks, k, i, c, s;
int CONF[8]= {142,206,158,222,174,238,190,254};
double volt[20], voltr[4], temp[4], DATO;
FILE * f_one;
f_one = fopen("a_m.txt", "w+");
for (s=0; s<=2; s++)
{
for (c=1; c<=8; c++)
{
for (i=7; i>-1; i--)
{
lima=pow(2.0,i);
p=CONF[c]&lima;
if (p==lima) {Out32(LPT,DIN+E);}
else Out32(LPT,E);
Out32(LPT,E+CLK);
Out32(LPT,E);
}
DATO=0;
for (i=11; i>-1; i--)
{
Out32(LPT,E+CLK);
Out32(LPT,E);
ps=Inp32(LPT+1)&DOUT;
limas=pow(2.0,i);
if (ps==0) {DATO=(DATO+limas);}
}
Out32(LPT,E+CS);
k=(c+8*s);
if (k<=20)
{volt[k] = DATO * (vref / 4095);
printf (" %.2f", volt[k]); //print to screen
fprintf (f_one,"%.2f ", volt[k]);} //print to file
if (k>20)
{ks=24-k;
voltr[ks] = DATO * (vref / 4095);
temp[ks]=voltr[ks]/10;
printf (" %.1f", temp[ks]); //print to screen
fprintf (f_one,"%.1f ", temp[ks]);} //print to file
Sleep(25);
}
}
Sleep(25);
printf ("\n");
fprintf (f_one,"\n");
fclose(f_one);
}
This is my first post... I need some help!
I have made some code for reading from parallel port. It work very good compiled with VSC++ like console application... It read LPT 1 sending results to screen and to file...
When I tried to compile with qt, my first problem is that I need to call 3 *.lib for LPT communication...(or load dll library! how)
Second problem is how to send result value to Qt form?!
#include <stdafx.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <windows.h>
#define E 8
#define DIN 32
#define CS 64
#define CLK 128
#define DOUT 128
#define LPT 888
#define vref 2.5
short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);
int main()
{
int prs, lima, p, limas, ps;
int ks, k, i, c, s;
int CONF[8]= {142,206,158,222,174,238,190,254};
double volt[20], voltr[4], temp[4], DATO;
FILE * f_one;
f_one = fopen("a_m.txt", "w+");
for (s=0; s<=2; s++)
{
for (c=1; c<=8; c++)
{
for (i=7; i>-1; i--)
{
lima=pow(2.0,i);
p=CONF[c]&lima;
if (p==lima) {Out32(LPT,DIN+E);}
else Out32(LPT,E);
Out32(LPT,E+CLK);
Out32(LPT,E);
}
DATO=0;
for (i=11; i>-1; i--)
{
Out32(LPT,E+CLK);
Out32(LPT,E);
ps=Inp32(LPT+1)&DOUT;
limas=pow(2.0,i);
if (ps==0) {DATO=(DATO+limas);}
}
Out32(LPT,E+CS);
k=(c+8*s);
if (k<=20)
{volt[k] = DATO * (vref / 4095);
printf (" %.2f", volt[k]); //print to screen
fprintf (f_one,"%.2f ", volt[k]);} //print to file
if (k>20)
{ks=24-k;
voltr[ks] = DATO * (vref / 4095);
temp[ks]=voltr[ks]/10;
printf (" %.1f", temp[ks]); //print to screen
fprintf (f_one,"%.1f ", temp[ks]);} //print to file
Sleep(25);
}
}
Sleep(25);
printf ("\n");
fprintf (f_one,"\n");
fclose(f_one);
}