Click here to Skip to main content
15,885,186 members
Articles / Programming Languages / C++

Homemade Alarm System

Rate me:
Please Sign up or sign in to vote.
4.84/5 (22 votes)
20 May 2011GPL32 min read 55.1K   8.4K   46  
A project to provide “hardware-software” alarm device
//---------------------------------------------------------------------------
#include "ComPort.h"
#include "mmsystem.h"

#include <vcl.h>
#pragma hdrstop

#include "UnitSettings.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSettings *FormSettings;
//---------------------------------------------------------------------------
__fastcall TFormSettings::TFormSettings(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TFormSettings::ButtonCheckClick(TObject *Sender)
{
	//checking of the edits "emptiness"
	if(EditCom->Text.IsEmpty())
	{
		EditCom->Text="Com1";
	}

	if(EditBaud->Text.IsEmpty())
	{
		EditBaud->Text="9600";
	}

	//to close the port
	ComPort_Close();

	//entering the number of the comport
	AnsiString ComPort=EditCom->Text;
	char *ComP = ComPort.c_str();

	//entering the baudrate of the comport
	AnsiString BaudRate=EditBaud->Text;
	unsigned long Baud = BaudRate.ToDouble();

	BOOL bOpened;
	ComPort_PresetParameters(Baud,8,NOPARITY,ONESTOPBIT);	// optional function
	bOpened = ComPort_Open(ComP);

	if(bOpened)
	{
		EditStatus->Text="Ready";

		//wellcome note
		DWORD fdwSound = SND_ASYNC | SND_FILENAME;
		PlaySound("sounds/wellcome.wav",NULL, fdwSound);

		FormSettings->Close();
	}
        else
	{
		EditStatus->Text="Bussy";

		//error note
		DWORD fdwSound = SND_ASYNC | SND_FILENAME;
		PlaySound("sounds/error.wav",NULL, fdwSound);
	}
}
//---------------------------------------------------------------------------
void __fastcall TFormSettings::EditBaudKeyPress(TObject *Sender, char &Key)
{
	//allow only digits, without symbols
	if ((Key < '0' || Key > '9') && Key != 8) Key= 0;
}
//---------------------------------------------------------------------------



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer Samsung SURC
Ukraine Ukraine
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions