User Guide
- 43
–
16.7 Sample Code:
Example Borland C++ code for command “GLG” – Get light guide diameter
void __fastcall TForm1::Cmd33Click(TObject *Sender)
{
signed char Tries = 4;
float LG_diameter;
unsigned char *Command;
String Textcom= "GLG";
int Command_CRC;
Timer1->Enabled = false;
Cmd33->Enabled = false;
Command = Textcom.c_str();
Command_CRC = CalcCRC8(0, Command, 3);
// Calculate CRC8 for the
command “GLG”
Screen->Cursor = crHourGlass;
// Show hourglass
cursor
Application->ProcessMessages();
while (Tries--)
{
ComPort->FlushInBuffer();
ComPort->FlushOutBuffer();
ComPort->PutString(Textcom);
// send the
command “GLG”
ComPort->PutChar(Asc[Command_CRC>>4]);
// send the
CRC8 in hex string
ComPort->PutChar(Asc[Command_CRC & (0xF)]);
// send the CRC8
in hex string
ComPort->PutChar('\r');
a=0;
UnitResponse = "";
TimeOut = false;
TimeOutTimer = 1;
while (TimeOutTimer) Application->ProcessMessages();
if (a == '\r')
{
a = 0;
if (CompareCRC())
// Check if the data is
received correctly