⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cpp

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        DRV_GetErrorMessage(m_ErrCde,(LPSTR)szErrMsg);
        Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
        return;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnStopClick(TObject *Sender)
{
   DWORD dwExitCode;
   PT_EnableEvent ptEnableEvent; // Enable event

   if (pchkThread)
   {
      GetExitCodeThread((void *)pchkThread->Handle, &dwExitCode);
      if (dwExitCode == STILL_ACTIVE)
      {
         TerminateThread((void *)pchkThread->Handle, dwExitCode);
         pchkThread->Terminate();
         delete pchkThread;
         pchkThread = NULL;
      }

   }
   btnStart->Enabled = true;
   btnStop->Enabled = false;
   txtWatchdogStatus->Text = "";

   m_ErrCde = DRV_WatchdogStop(m_DeviceHandle);
    if (m_ErrCde != SUCCESS)
    {
        DRV_GetErrorMessage(m_ErrCde,(LPSTR)szErrMsg);
        Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
        return;
    }

   ptEnableEvent.EventType = ADS_EVT_WATCHDOG_OVERRUN;
   ptEnableEvent.Enabled = 0;
   ptEnableEvent.Count = 1;
   m_ErrCde = DRV_EnableEvent(m_DeviceHandle, &ptEnableEvent);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnFeedClick(TObject *Sender)
{
   m_ErrCde = DRV_WatchdogFeed(m_DeviceHandle);
     if (m_ErrCde != SUCCESS)
    {
        DRV_GetErrorMessage(m_ErrCde,(LPSTR)szErrMsg);
        Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
        return;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::cmbPortChange(TObject *Sender)
{
   btnReadClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::txtWatchdogCounterChange(TObject *Sender)
{
  WatchdogCounter = StrToInt64(txtWatchdogCounter->Text);
   ulDataLength = sizeof(DWORD);
   m_ErrCde = DRV_DeviceSetProperty(m_DeviceHandle, CFG_WatchdogCounter,
      &WatchdogCounter, ulDataLength);
    szBuff.sprintf("%0.0f",WatchdogCounter*0.0001);
   labWatchdogTimer->Caption = szBuff;
}
//---------------------------------------------------------------------------
void  TfrmMain::CheckEventProc()
{

   PT_CheckEvent ptCheckEvent;
   USHORT usEventType;

   ptCheckEvent.EventType = &usEventType;
   ptCheckEvent.Milliseconds = INFINITE;

   while (true)
   {
      DRV_CheckEvent(m_DeviceHandle, &ptCheckEvent);
      if (usEventType == ADS_EVT_WATCHDOG_OVERRUN)
         txtWatchdogStatus->Text = "Overrun";

  }
}
//---------------------------------------------------------------------------


void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
   btnSelDevClick(Sender);
}
//---------------------------------------------------------------------------


void __fastcall TfrmMain::chkAutoFeedClick(TObject *Sender)
{
   AutoFeedTimer->Interval = txtAutoTimer->Text.ToInt();
   if (chkAutoFeed->Checked)
      AutoFeedTimer->Enabled = true;
   else
      AutoFeedTimer->Enabled = false;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::AutoFeedTimerTimer(TObject *Sender)
{
    DRV_WatchdogFeed(m_DeviceHandle);        
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::txtAutoTimerChange(TObject *Sender)
{
  AutoFeedTimer->Interval = txtAutoTimer->Text.ToInt();
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::btnSetPresetClick(TObject *Sender)
{
   AnsiString strHex;
   ULONG Value;

   strHex = "0x" + txtP1->Text;
   Value = StrToInt(strHex);
   DOpresetStatus[0] = Value & 0xFF;
   DOpresetStatus[1] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtP2->Text;
   Value = StrToInt(strHex);
   DOpresetStatus[2] = Value & 0xFF;
   DOpresetStatus[3] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtP3->Text;
   Value = StrToInt(strHex);
   DOpresetStatus[4] = Value & 0xFF;
   DOpresetStatus[5] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtP4->Text;
   Value = StrToInt(strHex);
   DOpresetStatus[6] = Value & 0xFF;
   DOpresetStatus[7] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtP5->Text;
   Value = StrToInt(strHex);
   DOpresetStatus[8] = Value & 0xFF;
   DOpresetStatus[9] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtP6->Text;
   Value = StrToInt(strHex);
   DOpresetStatus[10] = Value & 0xFF;
   DOpresetStatus[11] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtP7->Text;
   Value = StrToInt(strHex);
   DOpresetStatus[12] = Value & 0xFF;
   DOpresetStatus[13] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtP8->Text;
   Value = StrToInt(strHex);
   DOpresetStatus[14] = Value & 0xFF;
   DOpresetStatus[15] = (Value >> 8) & 0xFF;

   ulDataLength = sizeof(BYTE) * 16;
   m_ErrCde = DRV_DeviceSetProperty(m_DeviceHandle, CFG_DoPresetValue,
      &(DOpresetStatus[0]), ulDataLength);


}
//---------------------------------------------------------------------------


void __fastcall TfrmMain::btnWatchdogSetClick(TObject *Sender)
{
   AnsiString strHex;
   ULONG Value;

   strHex = "0x" + txtWP1->Text;
   Value = StrToInt(strHex);
   DOWatchdogStatus[0] = Value & 0xFF;
   DOWatchdogStatus[1] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtWP2->Text;
   Value = StrToInt(strHex);
   DOWatchdogStatus[2] = Value & 0xFF;
   DOWatchdogStatus[3] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtWP3->Text;
   Value = StrToInt(strHex);
   DOWatchdogStatus[4] = Value & 0xFF;
   DOWatchdogStatus[5] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtWP4->Text;
   Value = StrToInt(strHex);
   DOWatchdogStatus[6] = Value & 0xFF;
   DOWatchdogStatus[7] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtWP5->Text;
   Value = StrToInt(strHex);
   DOWatchdogStatus[8] = Value & 0xFF;
   DOWatchdogStatus[9] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtWP6->Text;
   Value = StrToInt(strHex);
   DOWatchdogStatus[10] = Value & 0xFF;
   DOWatchdogStatus[11] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtWP7->Text;
   Value = StrToInt(strHex);
   DOWatchdogStatus[12] = Value & 0xFF;
   DOWatchdogStatus[13] = (Value >> 8) & 0xFF;

   strHex = "0x" + txtWP8->Text;
   Value = StrToInt(strHex);
   DOWatchdogStatus[14] = Value & 0xFF;
   DOWatchdogStatus[15] = (Value >> 8) & 0xFF;

   ulDataLength = sizeof(BYTE) * 16;
   m_ErrCde = DRV_DeviceSetProperty(m_DeviceHandle, CFG_DoWatchdogValue,
      &(DOWatchdogStatus[0]), ulDataLength);
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::txtPChange(TObject *Sender)
{
 long lStart;
  long lLength;
  String sHex;
  TEdit *pEdit = (TEdit*)Sender;

  //
  // Bound the Pattern Match value in 0 ~ FFFFFFFFh
  //
  if (strlen(pEdit->Text.c_str()) > 4)
  {
    // Out of value bound
    lStart = pEdit->SelStart;
    lLength = pEdit->SelLength;
    if(lStart != 0)
      lStart--;
    
    pEdit->Text = IntToHex(pEdit->Tag, 2);
    
    pEdit->SelStart = lStart;
    pEdit->SelLength = lLength;
  }

  if(strlen(pEdit->Text.c_str()) == 0)
  {
    // 0 Value
    pEdit->Text = "0";
    pEdit->SelStart = 0;
  }
  //
  // Valid Patterm Match value,write this new property value to device.
  //
  sHex = "0x" + pEdit->Text;
  lStart = StrToInt(sHex);
  pEdit->Tag = lStart;


}

void __fastcall TfrmMain::txtWPKeyPress(TObject *Sender, char &Key)
{

   if(Key >= '0' && Key <= '9')
    return;
  if(Key == 8)
    return;

  if(Key >= 'A' && Key <= 'F')
    return;
  
  if(Key >= 'a' && Key <= 'f')
  {
    Key = Key + 'A' - 'a';
    return;
  }

  Key = 0;
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -