Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to update old turbo c program

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
A programer wrote the following program which reads the weight from the scales. He graduated from school & left. We now want to add a second scale, but the data stream is different and takes forever to read. Our foxpro programmer does not know C. I need to know what program to use & what to change to read data stream correctly.

#include<dos.h>
#include<stdio.h>

#define IER 1
#define MCR 4
#define DTR 1
#define RTS 2
#define LSR 5
#define RCVRDY 1
#define RX 0

#define OVRERR 2
#define PRTYERR 4
#define FRMERR 8

int portbase - 0x2f8;

main()
{

FILE #handle;
register unsigned long i, j = OL;
register int c = 0, inpstat;
register int a[340];

outportb(portbase + IER, 0);
outportb(portbase + MCR, DTR : RTS);

handle = fopen(&quot;SAMPLE.DAT&quot;,&quot;w&quot;);
for(i=OL;i<17*7500;i++)
{
if(j >= 340) break;

inpstat = inportb(portbase + LSR);
if(inpstat & RCVRDY)
{
c = inportb(portbase + RX);

if(inpstat & (OVRERR : PRTYERR : FRMERR))
{
printf(&quot;\b&quot;);
c = -1;
}

}
else
{
c = -1;
}

if( c != -1)
{
a[j] = c;
j++;
}
}

for(i=OL;i<j;i++)
{
fputc(a,handle);
}
fclose(handle);
}


The output for this program in the sample.dat file looks like this
[][]* 0042 0000

The new scales output looks like this
[] 000042LG
[] 000042LG (there are 19 of the [] 000042LG)
[]

Any help appreciated!
 
Well... it's been a long time since I've done any DOS
programming but from the looks of it, I'm assuming you have
a device (scale?) attached to the serial port at COM2
from the line...

int portbase = 0x2f8; /* I assume you meant &quot;=&quot; and not &quot;-&quot; */

...Again, making (lots of) assumptions, I will assume you are
connecting a second device to COM1.
With a somewhat simplistic approach you can just
duplicate what you have, somthing like...

#include<dos.h>
#include<stdio.h>

#define IER 1
#define MCR 4
#define DTR 1
#define RTS 2
#define LSR 5
#define RCVRDY 1
#define RX 0

#define OVRERR 2
#define PRTYERR 4
#define FRMERR 8

int portbase1 = 0x3f8; /* serial port at COM1 */
int portbase2 = 0x2f8; /* serial port at COM2 */

main()
{
FILE *handleA, *handleB; /* again, I assume &quot;*&quot; instead of &quot;#&quot; */
register unsigned long i, j = 0L; /* also &quot;0&quot; instead of &quot;O&quot; */
register int c1 = 0, c2 = 0, inpstat;
register int a[340], b[340];

handleA = fopen(&quot;SAMPLEA.DAT&quot;,&quot;w&quot;);
handleB = fopen(&quot;SAMPLEB.DAT&quot;,&quot;w&quot;);

for(i=0L;i<17*7500;i++) /* again &quot;0&quot; not &quot;O&quot; */
{
if(j >= 340) break;

inpstat = inportb(portbase1 + LSR);
if(inpstat & RCVRDY)
{
c1 = inportb(portbase + RX);
if(inpstat & (OVRERR : PRTYERR : FRMERR))
{
printf(&quot;\b&quot;);
c1 = -1;
}
}
else
{
c1 = -1;
}
if( c1 != -1)
{
a[j] = c1;
j++;
}
}
for(i=0L;i<j;i++) /* again &quot;0&quot; not &quot;O&quot; */
{
fputc(a,handleA);
}
fclose(handleA);

for(i=0L;i<17*7500;i++) /* again &quot;0&quot; not &quot;O&quot; */
{
if(j >= 340) break;

inpstat = inportb(portbase2 + LSR);
if(inpstat & RCVRDY)
{
c2 = inportb(portbase + RX);
if(inpstat & (OVRERR : PRTYERR : FRMERR))
{
printf(&quot;\b&quot;);
c2 = -1;
}
}
else
{
c2 = -1;
}
if( c2 != -1)
{
b[j] = c;
j++;
}
}

for(i=0L;i<j;i++)
{
fputc(b, handleB);
}
fclose(handleB);
}


...again, I am making many assumptions and I may not correctly
understand your configuration.
 
Sorry I did not make myself clear. We are attaching a new scales to a new computer (com2)and the new scales data stream output is as follows:

STX / Space or - / 6 weight digits / L / G for gross /
if negative N for net

Space or a / Carriage Return / Line Feed
M if in motion or
O if in overload


The data output from the scales in the program above is as follows:

STX / POL / 6 weight digits / SP / LB / SP / GR / CR / LF
NT

Can this DOS program be updated to Some current program or do we try to adjust this one?
 
Well if you're going with new equipment,
I would also go with new software. I would
think that you would get some Windows GUI
software with the new scales anyway.
In any case, you may have difficulties building the
Borland code on the new system.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top