C++ 2 Serial COM port reads Needed

Hello All: I have exhausted several google searches trying to find the code I need to finish my project. I admit, I am a novice at C++ and have probably already seen the code I need, but don't know how to use it. I have never used Visual Basic, Visual C++, or any other new utility. I am looking to run this from a standart Windows DOS prompt and the only languages I'm familiar with are MicroC, C++, and assembly language. Anyway, I am looking for someone to just fill in the serial port reads that I need to complete my program. I am using Dev-C++ with Windows Vista x64 Home (I know, I know). My program is supposed to make two reads from two different serial COM ports and store the information in variables. The program is part of an electronic umpire system for Baseball so anyone feel free to use it at your desire. Oh, and in case this post loses my indent formatting, feel free to email me at puckboss3@yahoo.com and I will send you the .cpp file. Thanks in Advance!

#include <iostream>
#include <stdlib.h>
using namespace std;

//initialize the variables

int sensorDataInit1 = 0; //inital value read from serial port 1 to compare against
int sensorDataInit2 = 0; //inital value read from serial port 2 to compare against
int sensorDataNew1 = 0; //new value read from serial port 1 which constanly updates
int sensorDataNew2 = 0; //new value read from serial port 2 which constanly updates
int sensorData1 = 0; //variable used to signal whether or not serial read 1 has changed
int sensorData2 = 0; //variable used to signal whether or not serial read 2 has changed

int strike = 0; //counter for strikes
int ball = 0; //counter for balls
int out = 0; //counter for outs

//main program

int main()
{

/*
Routine to set up Initial Reading with lasers grid activated and no part of the beams broken
Get data from the two serial port reads here and store in sensorDataInit1 and sensorDataInit2
*/

for( int i = 1; i > 0; i++) //endless loop
{

/*
Routine to compare new reading from the serial ports to the initial reading to see if there's a chnage
Get data from the two serial port reads here and store in sendorDataNew1 and sensorDataNew2
*/

if ((sensorDataNew1 - sensorDataInit1 != 0) && (sensorDataNew2 - sensorDataInit2 != 0)) // repeat loop here until the sensor data changes
{
system("cls"); //clear the screen to display the new count
if (sensorDataNew1 - sensorDataInit1 != 0) //check to see if serial read 1 has changed
{
sensorData1 = 1; //signals that serial read 2 has changed
}
if (sensorDataNew2 - sensorDataInit2 != 0) //check to see if serial read 2 has changed
{
sensorData2 = 1; //signals that serial read 2 has changed
}
if ( ball < 4 && strike < 3 && out < 3) //check to allow an increment to a counter without needing a reset
{
if (sensorData1 > 0 && sensorData2 > 0) //check to see if both serial reads have changed
{
if( strike > 1) //check to see if there are 2 strikes
{
cout << "Strike 3, You're Out!" << endl;
out++;
strike = 0; //reset the counter
}
else
{
strike++;
cout << "Ball Strike Out" << endl; //displays the count
cout << " " << ball << " " << strike << " " << out << endl; //displays the count
}
}
else
{
if( ball > 2) //check to see if there are 3 balls
{
cout << "Ball 4, Take Your Base!" << endl;
ball = 0; //reset the counter
}
else
{
ball++;
cout << "Ball Strike Out" << endl; //displays the count
cout << " " << ball << " " << strike << " " << out << endl; //displays the count
}
}
}
else
{
strike = 0; //reset the counter
ball = 0; //reset the counter
out = 0; //reset the counter
}
}
return (0); //end main program
}
}

Topic archived. No new replies allowed.