您现在所在的是:

电脑编程

回帖:1个,阅读:1437 [上一页] [1] [下一页]
931
yangeryang
文章数:10
年度积分:50
历史总积分:931
注册时间:2007/5/14
发站内信
发表于:2007/5/17 8:55:00
#0楼
现在本人在做数据采集要用VB编程,以下是C语言的,请各位高手能把下面的源程序翻译成VB语言的吗??谢谢了!!!!!

#include <stdio.h>
# include <stdlib.h>
# include "conio.h"
#include "decl.h"
#include <string.h>
#include <dos.h>
#include "sdk.h"
#include <math.h>
#define POINTS 35
const unsigned int HYADDRESS=0x280;
char dat[16],rd1[512];
int ibrd(unsigned int address,int ud,char *rd,int cnt);
int ibwrt(unsigned int address,int ud,char *wrt,int cnt);
float hv_get(unsigned int bd_base,int chno); //ad6040
float dense_get(float t);
float  pv(float t);

extern int test_num,res_num,test_point,auto_hand; //测点数,结果点数,正在测试点号,采样控制,0-手动,1-自动
extern float Q[POINTS],H[POINTS],P2p[POINTS],EFFp[POINTS],NPSH[POINTS];//换算至额定转速流量,扬程,轴功率,泵效率,汽蚀余量
extern float nt[POINTS],Qn[POINTS],Hn[POINTS],Pn[POINTS],NPSHn[POINTS];//实测转速,流量,扬程,轴功率,汽蚀余量
extern float dense,mvz,Ivz,Pvz,g,nsp;
extern float qvz,hvz,avz; //流量,扬程,真空变送器零点
extern float h_k,p_k,p_c,npsh_k; //扬程变送器斜率,扭矩斜率,截距
extern float qv_zero,q_c,q_k,q_exp,vk,vkcav,pressurv;//流量标定电压零点,常数,系数,指数 ,速度头系数
extern float temp_start,temp_end,temp_air;
extern struct SAMPLEDAT
{
struct time t;
float qv[10],hv[10],mv[10]; //流量,扬程,扭矩采样值
float nv[10],av[10],Pv[10]; //转速,真空,备用采样值
float hz;     //扬程测量点距水面高度
float az,num;     //真空测量水位,备用
} sj[POINTS];
extern int test_point;
extern int zero_flag,adjust_flag,adjust_num;
void auto_win(void);
//正常自动采样
void voltget(void)
{
WINDOWS *wnd;
int i,j,k,m,gainnum,sign,data;
const unsigned int address=0x310;
char command[30],*p,*pt,*pe,a[20],x;
float b[10],qver,hver,npshver,zvb[10][3],cavb[10];
int texth,textw;
wnd=UC_GetCurrentWindow();
texth=25;
setcolor(3);
settextstyle(0,0,texth);
UC_WindowPrintf(wnd, 170, 60+35*0, DT_NOOVER,"扬程(V)");
UC_WindowPrintf(wnd, 290, 60+35*0, DT_NOOVER,"流量(V)");
UC_WindowPrintf(wnd, 410, 60+35*0, DT_NOOVER,"扭矩(N.m)");
UC_WindowPrintf(wnd, 535, 60+35*0, DT_NOOVER,"转速(r/min)");
UC_WindowPrintf(wnd, 690, 60+35*0, DT_NOOVER,"真空(V)");
UC_WindowPrintf(wnd, 30, 100+35*0, DT_NOOVER,"采样值0");
UC_WindowPrintf(wnd, 30, 100+35*1, DT_NOOVER,"采样值1");
UC_WindowPrintf(wnd, 30, 100+35*2, DT_NOOVER,"采样值2");
UC_WindowPrintf(wnd, 30, 100+35*3, DT_NOOVER,"采样值3");
UC_WindowPrintf(wnd, 30, 100+35*4, DT_NOOVER,"采样值4");
UC_WindowPrintf(wnd, 30, 100+35*5, DT_NOOVER,"采样值5");
UC_WindowPrintf(wnd, 30, 100+35*6, DT_NOOVER,"采样值6");
UC_WindowPrintf(wnd, 30, 100+35*7, DT_NOOVER,"采样值7");
UC_WindowPrintf(wnd, 30, 100+35*8, DT_NOOVER,"采样值8");
UC_WindowPrintf(wnd, 30, 100+35*9, DT_NOOVER,"采样值9");
setcolor(12);
again:reset(address);
init_talk_listen(address);
  if(zero_flag==0)
   {
    strcpy(command,"F7,2");
    delay(20);
    ibwrt(address,3,command,strlen(command));
    delay(50);
  }
  gainnum=0;
reh:delay(20);
  strcpy(command,"U7M0R3T1I3N1C0D0Y0");
  ibwrt(address,12,command,strlen(command));
  delay(20);
  m=1;
 for(i=0;i<8;i++)
  {  UC_WindowPrintf(wnd, 170, 60+35*(i+1), DT_OVER,"      ");
//     UC_WindowPrintf(wnd, 290, 60+35*(i+1), DT_OVER,"      ");
  }
for(i=0;i<8;i++)   //voltget
{
  ibrd(address,m+11,rd,10);
  delay(30);
  printf("%s\n",rd);
  if(strlen(rd)<9) goto reh;
  if(rd[0]!='+') goto reh;
  zvb[i][m]=atof(rd);
  if(m==1)  UC_WindowPrintf(wnd, 170, 60+35*(i+1), DT_NOOVER,"%5.3f",zvb[i][m]);
  else  UC_WindowPrintf(wnd, 290, 60+35*(i+1), DT_NOOVER,"%5.3f",zvb[i][m]);
  }
req:   delay(20);
  strcpy(command,"U7M0R3T1I3N1C0D0Y0");
  ibwrt(address,13,command,strlen(command));
  delay(30);
  m=2;
 for(i=0;i<8;i++)
  { // UC_WindowPrintf(wnd, 170, 60+35*(i+1), DT_OVER,"      ");
    UC_WindowPrintf(wnd, 290, 60+35*(i+1), DT_OVER,"      ");
  }
for(i=0;i<8;i++)   //voltget
{
  ibrd(address,m+11,rd,10);
  delay(30);
  printf("%s\n",rd);
  if(strlen(rd)<9) goto req;
  if(rd[0]!='+') goto req;
  zvb[i][m]=atof(rd);
  if(m==1)  UC_WindowPrintf(wnd, 170, 60+35*(i+1), DT_NOOVER,"%5.3f",zvb[i][m]);
  else  UC_WindowPrintf(wnd, 290, 60+35*(i+1), DT_NOOVER,"%5.3f",zvb[i][m]);
cavb[i]=hv_get(HYADDRESS,0);
delay(40);
}
qver=0;hver=0;npshver=0;
for(i=0;i<8;i++)// printf("qv=%9.5f    hv=%9.5f\n",zvb[i][1],zvb[i][2]);
 { qver=qver+zvb[i][2];
   hver=hver+zvb[i][1];
   npshver=npshver+cavb[i];
}
if(zero_flag==1)
   { qvz=qver/8;
     hvz=hver/8;
 //     测水温,室温
  temp_start=qv_zero*(hv_get(HYADDRESS,1)-1.0);
  temp_air=q_c*(hv_get(HYADDRESS,2)-1.0);
  temp_end=npsh_k*(hv_get(HYADDRESS,0)-1.0);
  dense=dense_get(temp_start);
  pressurv=pv(temp_start);

     goto  ext;
   }
  sj[test_point-1].qv[gainnum]=qver/8;
  sj[test_point-1].hv[gainnum]=hver/8;
  sj[test_point-1].av[gainnum]=npshver/8;
  strcpy(command,"D1");
  delay(20);
  ibwrt(address,3,command,strlen(command));
  delay(50);
  ibrd(address,3,rd1,25);
  delay(50);
//   printf("%s",rd1);
  x=',';
  p= strchr(rd1,x);
  x='\n';
  pe=strchr(rd1,x);
  if (p)
    { sign=1;
      for(i=0;i<11;i++)  a[i]=rd1[i];
      if(a[0]=='-') sign=-1;
      a[0]=' ';
      sj[test_point-1].mv[gainnum]=atof(a)*sign;
//      if(sj[test_point-1].mv[gainnum]>=0.0) goto again;
      p++;i=0;
      for(pt=p;pt<pe;pt++) { a[i]=rd1[i+12];i++;}
      sj[test_point-1].nv[gainnum]=atof(a);
     UC_WindowPrintf(wnd, 410, 60+35*(gainnum+1), DT_OVER,"      ");
     UC_WindowPrintf(wnd, 410, 60+35*(gainnum+1), DT_NOOVER,"%5.1f",-sj[test_point-1].mv[gainnum]/10);
     UC_WindowPrintf(wnd, 535, 60+35*(gainnum+1), DT_OVER,"      ");
     UC_WindowPrintf(wnd, 535, 60+35*(gainnum+1), DT_NOOVER,"%5.0f",sj[test_point-1].nv[gainnum]);
     UC_WindowPrintf(wnd, 645, 60+35*(gainnum+1), DT_OVER,"      ");
     UC_WindowPrintf(wnd, 645, 60+35*(gainnum+1), DT_NOOVER,"%5.3f",sj[test_point-1].av[gainnum]);
    }
  else goto again;
  gainnum=gainnum+1;
  if(gainnum<10)     goto reh;
// 结束采样
  strcpy(command,"F7,0.5");
  delay(5);
  ibwrt(address,3,command,strlen(command));
  delay(30);
ext:  reset(address);
  delay(50);
return;
}

//float q_cal_auto(int num);
//float h_cal_auto(int num,float qz);
void My2_redraw(WINDOWS *wnd);
void adjust_voltget(void)
{
int i,j,k,m,sign,data;
unsigned int address=0x310;
char command[30],*p,*pt,*pe,a[20],x;
float b[10],qver,hver,npshver,zvb[10][3],cavb[10];
int texth,textw;
float nk=1,qz,hz,pz,npshz,effz,nz;
WINDOWS *wnd;
qz=0;hz=0;pz=0,npshz=0;effz=0;nz=0;
wnd=UC_GetCurrentWindow();
texth=35;
setcolor(3);
settextstyle(0,0,texth);

UC_WindowPrintf(wnd, 130, 40+35*0, DT_NOOVER,"流量采样电压");
UC_WindowPrintf(wnd, 130, 40+35*1, DT_NOOVER,"扬程采样电压");
UC_WindowPrintf(wnd, 130, 40+35*2, DT_NOOVER,"扭矩  采样值");
UC_WindowPrintf(wnd, 130, 40+35*3, DT_NOOVER,"真空采样电压");
UC_WindowPrintf(wnd, 130, 60+35*4, DT_NOOVER,"实 测  流 量");
UC_WindowPrintf(wnd, 130, 60+35*5, DT_NOOVER,"实 测  扬 程");
UC_WindowPrintf(wnd, 130, 60+35*6, DT_NOOVER,"汽 蚀  余 量");
UC_WindowPrintf(wnd, 130, 60+35*7, DT_NOOVER,"实 测  转 速");
UC_WindowPrintf(wnd, 130, 60+35*8, DT_NOOVER,"实 测  功 率");
UC_WindowPrintf(wnd, 130, 60+35*9, DT_NOOVER,"实 测  效 率");
setcolor(12);
if(adjust_num>0) goto rej;
reset(address);
init_talk_listen(address);
re2:   strcpy(command,"F7,0.5");
  delay(20);
  ibwrt(address,3,command,strlen(command));
  delay(50);
re:delay(20);
  strcpy(command,"U7M0R3T1I3N1C0D0Y0");
  delay(20);
  ibwrt(address,12,command,strlen(command));
  delay(30);
  ibwrt(address,13,command,strlen(command));
  delay(30);
  adjust_num=adjust_num+1;
rej: for(i=0;i<1;i++)   //voltget
{
for(m=1;m<3;m++)
{
  ibrd(address,m+11,rd,10);
  delay(30);
  if(strlen(rd)<9) goto re;
  if(rd[0]!='+') goto re;
  zvb[i][m]=atof(rd);
}
}
qver=0;hver=0;
   qver=qver+zvb[0][2];
   hver=hver+zvb[0][1];
  sj[test_point-1].qv[0]=qver;
  sj[test_point-1].hv[0]=hver;
  sj[test_point-1].av[0]=hv_get(HYADDRESS,0);
  strcpy(command,"D1");
  ibwrt(address,3,command,strlen(command));
  delay(50);
  ibrd(address,3,rd1,25);
  delay(50);
//   printf("%s",rd1);
  x=',';
  p= strchr(rd1,x);
  x='\n';
  pe=strchr(rd1,x);
  if (p)
    { sign=1;
      for(i=0;i<11;i++)  a[i]=rd1[i];
      if(a[0]=='-') sign=-1;
      a[0]=' ';
      sj[test_point-1].mv[0]=atof(a)*sign;
      p++;i=0;
      for(pt=p;pt<pe;pt++) { a[i]=rd1[i+12];i++;}
      sj[test_point-1].nv[0]=atof(a);
    }
  else goto re2;
qz=qz+q_k*(sj[test_point-1].qv[0]-qvz);
hz=hz+h_k*(sj[test_point-1].hv[0]-hvz)*1000.0/(dense*g)+vk*qz*qz;
nz=nz+sj[test_point-1].nv[0];
pz=pz+(-p_k*(sj[test_point-1].mv[0]/10+mvz));
npshz=((sj[test_point-1].av[0]-1.0)*npsh_k-pressurv*10*g)*1000.0/(dense*g)+qz*qz*vkcav;
pz=pz*(2*3.1415926*nz/60000);
if(pz>1e-8) effz=dense*g*qz*hz/pz/10000;
if(nz>1)  nk=nsp/nz;
else  nk=1;
qz=qz*nk;
hz=hz*nk*nk;
npshz=npshz*nk*nk;
pz=pz*nk*nk*nk;
   UC_WindowPrintf(wnd, 370, 40+35*0, DT_OVER,"                         ");
   UC_WindowPrintf(wnd, 370, 40+35*0, DT_NOOVER,"    %7.3f (V)",sj[test_point-1].qv[0]);
   UC_WindowPrintf(wnd, 370, 40+35*1, DT_OVER,"                    ");
   UC_WindowPrintf(wnd, 370, 40+35*1, DT_NOOVER,"    %7.3f (V)",sj[test_point-1].hv[0]);
   UC_WindowPrintf(wnd, 370, 40+35*2, DT_OVER,"                    ");
   UC_WindowPrintf(wnd, 370, 40+35*2, DT_NOOVER,"    %7.1f (N.m)",-sj[test_point-1].mv[0]/10);
   UC_WindowPrintf(wnd, 370, 40+35*3, DT_OVER,"                    ");
   UC_WindowPrintf(wnd, 370, 40+35*3, DT_NOOVER,"    %7.3f (V)",sj[test_point-1].av[0]);
   UC_WindowPrintf(wnd, 370, 60+35*4, DT_OVER,"                    ");
   UC_WindowPrintf(wnd, 370, 60+35*4, DT_NOOVER,"    %7.1f (l/s)",qz);
   UC_WindowPrintf(wnd, 370, 60+35*5, DT_OVER,"                    ");
   UC_WindowPrintf(wnd, 370, 60+35*5, DT_NOOVER,"    %7.3f (m)",hz);
   UC_WindowPrintf(wnd, 370, 60+35*6, DT_OVER,"                    ");
   UC_WindowPrintf(wnd, 370, 60+35*6, DT_NOOVER,"    %7.2f (m)",npshz);
   UC_WindowPrintf(wnd, 370, 60+35*7, DT_OVER,"                    ");
   UC_WindowPrintf(wnd, 370, 60+35*7, DT_NOOVER,"    %7.0f (r/min)",sj[test_point-1].nv[0]);
   UC_WindowPrintf(wnd, 370, 60+35*8, DT_OVER,"                    ");
   UC_WindowPrintf(wnd, 370, 60+35*8, DT_NOOVER,"    %7.2f (kW)",pz);
   UC_WindowPrintf(wnd, 370, 60+35*9, DT_OVER,"                    ");
   UC_WindowPrintf(wnd, 370, 60+35*9, DT_NOOVER,"    %7.2f (%)",effz);
//reset(address);

return;
}
int ibrd(unsigned int address,int ud,char *rd,int cnt)
{
int i,retu=0,data;
receive_ready(address,ud,0);
// delay(30);
for(i=0;i<cnt;i++)
{
 data=receive_data(address);
 if(data==0xff) {retu=1;break;}
 rd[i]=data;
 }
 return retu;
 }
int ibwrt(unsigned int address,int ud,char *rd,int cnt)
{
int i,retu=0;
send_ready(address,0,ud);
// delay(30);
for(i=0;i<cnt;i++)
retu=send_data(address,rd[i]);
send_EOI(address);
return retu;

}

/*电压采样*/
int ftest(int chno,int pts,unsigned int *bit12,int adsetdly,int dly)
{
int is,js,x,y,z;
outp(0x378,chno);  delay(adsetdly);
outp(0x378,0x20+chno);  delay(1);
for(is=0;is<pts;is++)
  {
  for(;;)
    {
    js=inp(0x379);
    if(js&8)     break;
    }
    outp(0x378,0x40);  delay(1);
    x=inp(0x379);   x=x/16;
    outp(0x378,0x60);  delay(1);
    y=inp(0x379);   y=y/16;
    outp(0x378,0x80);  delay(1);
    z=inp(0x379);   z=z/16;
    *bit12=x*256+y*16+z;
    bit12++;
    delay(dly);
  }
  return 1;
      }


float hv_get(unsigned int bd_base,int chno)
{
int pts,adsetdly,dly,i;
float hv,vz;
unsigned int bit12[128];
pts=64;
ftest(chno,pts,bit12,1,1);
vz=0.0;
for(i=0;i<pts;i++)  vz=vz+10.0*bit12[i]/4096;
hv=vz/pts;
return(hv);
}


float dense_get(float t)
{
float des;
des=1000.29-0.44339e-2*t-0.501523e-2*t*t;
return des;
}
float  pv(float t)    //kg/cm2
{ float pressurev;
pressurev=0.534261e-2+0.690471e-3*t-0.341767e-5*t*t+0.747502e-6*t*t*t;
return pressurev;
}
931
yangeryang
文章数:10
年度积分:50
历史总积分:931
注册时间:2007/5/14
发站内信
发表于:2007/5/17 8:56:00
#1楼
我的QQ是398286872
油箱是yangeryang01@163.com

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

124.8008