This is the CODE , it work fine in dos 😞
the user enter a numner 1-127 and send it by the serial port to the transmitter...
we search a reciver with the exact code and chang his stat, on\off...
all the data running on the power line...
some kind of a "smart home" device controled by the computer...
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#define com 1 //use com1
void initCom(void)
{
union REGS inregs, outregs;
inregs.h.ah = 0;
inregs.h.al = 0x43;
inregs.x.dx = - 0;
int86(0x14, &inregs, &outregs);
delay(200);
}
void send(char data)
{
union REGS inregs, outregs;
inregs.h.ah = 1;
inregs.h.al = data;
inregs.x.dx = - 0;
int86(0x14, &inregs, &outregs);
delay(200);
}
char receve(void)
{
union REGS inregs, outregs;
while (1) {
inregs.h.ah = 2;
inregs.x.dx = - 0;
int86(0x14, &inregs, &outregs);
if (outregs.h.ah == 0)
return(outregs.h.al);
}
}
void main(void)
{
unsigned char status;
char address [10];
int index;
clrscr();
initCom();
send('R');
send('S');
status = receve();
printf("Status : %X \n", status);
if (status == 0)
printf("transmitter ready\n");
else {
printf("transmitter NOT ready\n");
exit(1);
}
printf("enter code -->");
scanf("%s",address);
send('T');
for (index = 0; index < strlen(address); ++index)
send(address[index]);
send(';');
do {
send('S');
send(0xD);
status = receve();
/* printf("Status : %X \n", status); */
if ((status & 0x80) > 0)
printf("getting data\n");
if ((status & 0x40) > 0)
printf("sending data\n");
if ((status & 0x20) > 0) {
printf("I Did It\n");
exit(1);
}
} while ((status != 1) && (status != 0));
if (status == 1) printf("Unit On\n");
if (status == 0) printf("Unit Off\n");
}