67
Example Program Using Turbo C
#include <stdio.h>
#include <conio.h>
#define COM1 0x3f8
#define COM2 0x2f8
#define COM3 0x3e8
#define COM4 0x2e8
#define RS232 COM1
void init_rs232(void);
void send(char);
char read(void);
void send_buffer(char*);
void tkecho(char*);
char* tkdata(char*);
int scan_key(void);
int err;
void main(void)
{
char buffer[35];
clrscr(); //Clear screen
init_rs232(); //Initial RS232 interface
printf("Initial RS232....\n"); //Print "Initial RS232....”on screen
send_buffer("RST\015\n"); //Send “RST” to meter.
tkecho("=>\015\n"); //'Waiting "=>" and checking if the command is executed successfully.
tkecho("*>\015\n") //Waiting "*>" to make sure the meter is in power on initial state.
send_buffer("S101\015\n"); //Send “S101” to meter.
tkecho("=>\015\n"); //'Waiting "=>" and checking if the command is executed successfully.
send_buffer("S21\015\n") //Send “S21” to meter.
tkecho("=>\015\n"); //'Waiting "=>" and checking if the command is executed successfully.
sleep(3); // Wait for 3 seconds.
send_buffer("R1\015\n"); //Send “R1” to meter. Read primary display reading.
printf("%s",tkdata(buffer)); //Print primary display reading on computer screen.
tkecho("=>\015\n"); //'Waiting "=>" and checking if the command is executed successfully.
send_buffer("R2\015\n"); //Send “R2” to meter. Read primary reading.
printf ("%s",tkdata(buffer)); //Print secondary display reading on computer screen.
tkecho("=>\015\n"); //'Waiting "=>" and checking if the command is executed successfully.
printf("Press any key to continue");
getch(); //Wait for a key.
}