//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "Detect.h" #include "Aiousb.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { TDetectForm *DetectForm; unsigned long Status; DeviceIndex = diOnly; Status = QueryDeviceInfo(DeviceIndex, NULL, NULL, NULL, NULL, NULL); if (Status != ERROR_SUCCESS) { DetectForm = new TDetectForm(NULL); DeviceIndex = DetectForm->ShowModal(); DeviceIndex = DetectForm->DeviceIndex; } instructions->Caption = "Clicking on the \"Write Port A\" and \"Write Port B\" will write the values entered into the edit boxes to the relays\r\n"; instructions->Caption = instructions ->Caption + "Clicking on the lights above the edit boxes will change the relays one at a time."; unsigned long outdata = 0; DIO_WriteAll(DeviceIndex, &outdata); } //--------------------------------------------------------------------------- void __fastcall TForm1::WriteAClick(TObject *Sender) { char outMask; outMask = StrToInt("0x" + EditA->Text); DIO_Write8(DeviceIndex, 0, outMask); if (outMask & 0x01) outPanelA0->Color = clLime; else outPanelA0->Color = clRed; if (outMask & 0x02) outPanelA1->Color = clLime; else outPanelA1->Color = clRed; if (outMask & 0x04) outPanelA2->Color = clLime; else outPanelA2->Color = clRed; if (outMask & 0x08) outPanelA3->Color = clLime; else outPanelA3->Color = clRed; if (outMask & 0x10) outPanelA4->Color = clLime; else outPanelA4->Color = clRed; if (outMask & 0x20) outPanelA5->Color = clLime; else outPanelA5->Color = clRed; if (outMask & 0x40) outPanelA6->Color = clLime; else outPanelA6->Color = clRed; if (outMask & 0x80) outPanelA7->Color = clLime; else outPanelA7->Color = clRed; } //--------------------------------------------------------------------------- void __fastcall TForm1::WriteBClick(TObject *Sender) { char outMask; outMask = StrToInt("0x" + EditB->Text); DIO_Write8(DeviceIndex, 1, outMask); if (outMask & 0x01) outPanelB0->Color = clLime; else outPanelB0->Color = clRed; if (outMask & 0x02) outPanelB1->Color = clLime; else outPanelB1->Color = clRed; if (outMask & 0x04) outPanelB2->Color = clLime; else outPanelB2->Color = clRed; if (outMask & 0x08) outPanelB3->Color = clLime; else outPanelB3->Color = clRed; if (outMask & 0x10) outPanelB4->Color = clLime; else outPanelB4->Color = clRed; if (outMask & 0x20) outPanelB5->Color = clLime; else outPanelB5->Color = clRed; if (outMask & 0x40) outPanelB6->Color = clLime; else outPanelB6->Color = clRed; if (outMask & 0x80) outPanelB7->Color = clLime; else outPanelB7->Color = clRed; } //--------------------------------------------------------------------------- void __fastcall TForm1::EditBKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_RETURN) WriteBClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TForm1::EditAKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_RETURN) WriteAClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelA0Click(TObject *Sender) { if (outPanelA0->Color == clLime) { DIO_Write1(DeviceIndex, 0, false); //0 is the bit index we are writing to outPanelA0->Color = clRed; //valid values output bits for this board } // are 0 through 15 else { DIO_Write1(DeviceIndex, 0, true); outPanelA0->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelA1Click(TObject *Sender) { if (outPanelA1->Color == clLime) { DIO_Write1(DeviceIndex, 1, false); outPanelA1->Color = clRed; } else { DIO_Write1(DeviceIndex, 1, true); outPanelA1->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelA2Click(TObject *Sender) { if (outPanelA2->Color == clLime) { DIO_Write1(DeviceIndex, 2, false); outPanelA2->Color = clRed; } else { DIO_Write1(DeviceIndex, 2, true); outPanelA2->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelA3Click(TObject *Sender) { if (outPanelA3->Color == clLime) { DIO_Write1(DeviceIndex, 3, false); outPanelA3->Color = clRed; } else { DIO_Write1(DeviceIndex, 3, true); outPanelA3->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelA4Click(TObject *Sender) { if (outPanelA4->Color == clLime) { DIO_Write1(DeviceIndex, 4, false); outPanelA4->Color = clRed; } else { DIO_Write1(DeviceIndex, 4, true); outPanelA4->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelA5Click(TObject *Sender) { if (outPanelA5->Color == clLime) { DIO_Write1(DeviceIndex, 5, false); outPanelA5->Color = clRed; } else { DIO_Write1(DeviceIndex, 5, true); outPanelA5->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelA6Click(TObject *Sender) { if (outPanelA6->Color == clLime) { DIO_Write1(DeviceIndex, 6, false); outPanelA6->Color = clRed; } else { DIO_Write1(DeviceIndex, 6, true); outPanelA6->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelA7Click(TObject *Sender) { if (outPanelA7->Color == clLime) { DIO_Write1(DeviceIndex, 7, false); outPanelA7->Color = clRed; } else { DIO_Write1(DeviceIndex, 7, true); outPanelA7->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelB0Click(TObject *Sender) { if (outPanelB0->Color == clLime) { DIO_Write1(DeviceIndex, 8, false); outPanelB0->Color = clRed; } else { DIO_Write1(DeviceIndex, 8, true); outPanelB0->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelB1Click(TObject *Sender) { if (outPanelB1->Color == clLime) { DIO_Write1(DeviceIndex, 9, false); outPanelB1->Color = clRed; } else { DIO_Write1(DeviceIndex, 9, true); outPanelB1->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelB2Click(TObject *Sender) { if (outPanelB2->Color == clLime) { DIO_Write1(DeviceIndex, 10, false); outPanelB2->Color = clRed; } else { DIO_Write1(DeviceIndex, 10, true); outPanelB2->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelB3Click(TObject *Sender) { if (outPanelB3->Color == clLime) { DIO_Write1(DeviceIndex, 11, false); outPanelB3->Color = clRed; } else { DIO_Write1(DeviceIndex, 11, true); outPanelB3->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelB4Click(TObject *Sender) { if (outPanelB4->Color == clLime) { DIO_Write1(DeviceIndex, 12, false); outPanelB4->Color = clRed; } else { DIO_Write1(DeviceIndex, 12, true); outPanelB4->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelB5Click(TObject *Sender) { if (outPanelB5->Color == clLime) { DIO_Write1(DeviceIndex, 13, false); outPanelB5->Color = clRed; } else { DIO_Write1(DeviceIndex, 13, true); outPanelB5->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelB6Click(TObject *Sender) { if (outPanelB6->Color == clLime) { DIO_Write1(DeviceIndex, 14, false); outPanelB6->Color = clRed; } else { DIO_Write1(DeviceIndex, 14, true); outPanelB6->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::outPanelB7Click(TObject *Sender) { if (outPanelB7->Color == clLime) { DIO_Write1(DeviceIndex, 15, false); outPanelB7->Color = clRed; } else { DIO_Write1(DeviceIndex, 15, true); outPanelB7->Color = clLime; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { char inMask; DIO_Read8(DeviceIndex, 2, &inMask); //2 is the byte index for the read //valid values for this board are 2 and 3 if (inMask & 0x01) inPanelA0->Color = clLime; else inPanelA0->Color = clRed; if (inMask & 0x02) inPanelA1->Color = clLime; else inPanelA1->Color = clRed; if (inMask & 0x04) inPanelA2->Color = clLime; else inPanelA2->Color = clRed; if (inMask & 0x08) inPanelA3->Color = clLime; else inPanelA3->Color = clRed; if (inMask & 0x10) inPanelA4->Color = clLime; else inPanelA4->Color = clRed; if (inMask & 0x20) inPanelA5->Color = clLime; else inPanelA5->Color = clRed; if (inMask & 0x40) inPanelA6->Color = clLime; else inPanelA6->Color = clRed; if (inMask & 0x80) inPanelA7->Color = clLime; else inPanelA7->Color = clRed; DIO_Read8(DeviceIndex, 3, &inMask); //2 is the byte index for the read //valid values for this board are 2 and 3 if (inMask & 0x01) inPanelB0->Color = clLime; else inPanelB0->Color = clRed; if (inMask & 0x02) inPanelB1->Color = clLime; else inPanelB1->Color = clRed; if (inMask & 0x04) inPanelB2->Color = clLime; else inPanelB2->Color = clRed; if (inMask & 0x08) inPanelB3->Color = clLime; else inPanelB3->Color = clRed; if (inMask & 0x10) inPanelB4->Color = clLime; else inPanelB4->Color = clRed; if (inMask & 0x20) inPanelB5->Color = clLime; else inPanelB5->Color = clRed; if (inMask & 0x40) inPanelB6->Color = clLime; else inPanelB6->Color = clRed; if (inMask & 0x80) inPanelB7->Color = clLime; else inPanelB7->Color = clRed; } //---------------------------------------------------------------------------