below code write with c++ and save the weight in textfile but i dont work with c++
#include"stdio.h"
#include"stdlib.h"
#include"ctype.h"
#include"dos.h"
#include"conio.h"
#include"bios.h"
#include"time.h"
unsigned char data[32768];
int rx_ch(int port);
void tx_ch(int port,unsigned char ch);
void main(int argc,char *argv[])
{
unsigned int i,ch,chi,flag,byte2,count,checksum;
int end_flag,error_code,dp,state;
long weight;
double j;
int port,status,ser_counter,T0,T1;
FILE *fp;
char filename[13];
unsigned int module_beg,module_length;
port=0;
bioscom(0,0xfb,port); /* 9600 baud , even parity , 1 stop bit , 8 bit data */
clrscr();
end_flag=0;
while(!end_flag)
{
state=0;
do ch=rx_ch(port);
while( (ch!=1000) && ((ch&0x80)==0) );
if(ch==1000) end_flag=1;
if(!end_flag)
{
flag=ch;
dp=ch&0x07;
}
if(!end_flag)
{
ch=rx_ch(port);
if(ch==1000) end_flag=1;
if(ch&0x80)state=0;
else { weight=ch&0x03; byte2=ch; state=1; }
}
if( (!end_flag) && (state==1) )
{
ch=rx_ch(port);
if(ch==1000) end_flag=1;
else if(ch&0x80)state=0;
else { weight = (weight<<7) + (ch&0x7f); state=2; }
}
if( (!end_flag) && (state==2) )
{
ch=rx_ch(port);
if(ch==1000) end_flag=1;
else if(ch&0x80)state=0;
else { weight = (weight<<7) + (ch&0x7f); state=3; }
}
if( (!end_flag) && (state==3) )
{
ch=rx_ch(port);
if(ch==1000) end_flag=1;
else if(ch&0x80)state=0;
else
{
weight = (weight<<7) + (ch&0x7f);
if(byte2&0x08)
weight = -weight;
state=4;
}
}
if( (!end_flag) && (state==4) )
{
fp=fopen("out.txt", "wt");
gotoxy(10,10);
if(flag&0x10){ printf(" ");fprintf(fp," ");}
else{printf("M");fprintf(fp,"M");}
gotoxy(10,12);
if(flag&0x08){printf("Z");fprintf(fp,"Z");}
else {printf(" ");fprintf(fp," ");}
j=1;
for(i=0;i<dp;i++)
j*=10;
gotoxy(12,11); printf(" ");fprintf(fp," ");
gotoxy(12,11);
if( ((byte2&0x10)==0) && ((byte2&0x20)==0) )
{printf("%10lf ",(double)(weight)/j);
fprintf(fp,"%10lf ",(double)(weight)/j);
}else
{printf("--------- ");
fprintf(fp,"--------- ");
}
fclose(fp);
end_flag=1;
}
}
}
//---------------------------------------------------------------------------
int rx_ch(int port)
{
int status,keyhit=0;
do{
status = 0X100 & bioscom(3,0,port);
if(!status) status=keyhit=kbhit();
}
while( !status );
if(keyhit) return(1000);
else return( 0xff & bioscom(2,0,port) );
}
//---------------------------------------------------------------------------
void tx_ch(int port,unsigned char ch)
{
// printf("%3d ",ch);
bioscom(1,ch,port);
}