?
Solved

Having trouble with Process.GetProcessesByName()

Posted on 2006-05-27
7
Medium Priority
?
682 Views
Last Modified: 2011-06-03
Hi,

I'm faving trouble detecting a running executable.xThe executable is calle "lt" (lower case L).  The program has the name "AirID LT Test".  But each of the following returns proc.Length == 0:

Process[] proc = Process.GetProcessesByName( "lt" );              
Process[] proc = Process.GetProcessesByName( "lt.exe" );              
Process[] proc = Process.GetProcessesByName( "AirID LT Test" );              

Can anyone suggest a remedy?

I also have the project and can compile this program.

Thanks,
Bob
0
Comment
Question by:ba272
  • 4
  • 2
7 Comments
 

Author Comment

by:ba272
ID: 16777421
Also, when I look at the Processes tab of the Windows Task Manager, it shows up as "lt".
0
 
LVL 11

Assisted Solution

by:anyoneis
anyoneis earned 800 total points
ID: 16777701
Is it a dotnet program? Try: "lt.vshost"

David
0
 
LVL 11

Expert Comment

by:anyoneis
ID: 16777708
Arghh... That's only if you are running in the debugger. Never mind. "lt" should have worked!

David
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ba272
ID: 16777716
I think it's MFC C++.  I've included the main .cpp file.  Maybe you can tell.

// ltDlg.cpp : implementation file
//

#include "stdafx.h"
#include "cport.h"
#include "lt.h"
#include "ltDlg.h"

#include <stdio.h>
#include <conio.h>
#include <iostream>
//#include <string>
//#include <time.h>
#include <fstream>
//#include <sstream>
//#include <iostream>
using namespace std;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

char outputPath[] = "C:\\Texselogic\\PizzaPilot\\DMS\\DMSData\\BadgeEvents\\";

class CAboutDlg : public CDialog
{
public:
      CAboutDlg();

// Dialog Data
      //{{AFX_DATA(CAboutDlg)
      enum { IDD = IDD_ABOUTBOX };
      //}}AFX_DATA

      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CAboutDlg)
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
      //}}AFX_VIRTUAL

// Implementation
protected:
      //{{AFX_MSG(CAboutDlg)
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};

//-------------------------------------------------------------------
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
      //{{AFX_DATA_INIT(CAboutDlg)
      //}}AFX_DATA_INIT
}

//-------------------------------------------------------------------
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CAboutDlg)
      //}}AFX_DATA_MAP
}

//-------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
      //{{AFX_MSG_MAP(CAboutDlg)
            // No message handlers
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLtDlg dialog

CLtDlg::CLtDlg(CWnd* pParent /*=NULL*/)
      : CDialog(CLtDlg::IDD, pParent)
{
      //{{AFX_DATA_INIT(CLtDlg)
            // NOTE: the ClassWizard will add member initialization here
      //}}AFX_DATA_INIT
      // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
      m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

//-------------------------------------------------------------------
void CLtDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CLtDlg)
            // NOTE: the ClassWizard will add DDX and DDV calls here
      //}}AFX_DATA_MAP
}

//-------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CLtDlg, CDialog)
      //{{AFX_MSG_MAP(CLtDlg)
      ON_WM_SYSCOMMAND()
      ON_WM_PAINT()
      ON_WM_QUERYDRAGICON()
      ON_BN_CLICKED(IDC_BUTTON5, OnGetTimeout)
      ON_BN_CLICKED(IDC_BUTTON1, OnGetBaseVersion)
      ON_BN_CLICKED(IDC_BUTTON2, OnSetAtten)
      ON_BN_CLICKED(IDC_BUTTON3, OnGetAtten)
      ON_BN_CLICKED(IDC_BUTTON4, OnSetTimeout)
      ON_BN_CLICKED(IDC_BUTTON6, OnGetIDs)
      ON_BN_CLICKED(IDC_CHECK1, OnCommCnct)
      ON_WM_TIMER()
      ON_BN_CLICKED(IDC_RADIO_XASYNC, OnRadioXasync)
      ON_BN_CLICKED(IDC_RADIO_XSYNC, OnRadioXsync)
      ON_BN_CLICKED(IDC_BUT_GETMD, OnButGetmd)
      ON_BN_CLICKED(IDC_BUT_SETMD, OnButSetmd)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLtDlg message handlers

BOOL CLtDlg::OnInitDialog()
{
      CDialog::OnInitDialog();

      // Add "About..." menu item to system menu.

      // IDM_ABOUTBOX must be in the system command range.
      ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
      ASSERT(IDM_ABOUTBOX < 0xF000);

      CMenu* pSysMenu = GetSystemMenu(FALSE);
      if (pSysMenu != NULL)
      {
            CString strAboutMenu;
            strAboutMenu.LoadString(IDS_ABOUTBOX);
            if (!strAboutMenu.IsEmpty())
            {
                  pSysMenu->AppendMenu(MF_SEPARATOR);
                  pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
            }
      }

      // Set the icon for this dialog.  The framework does this automatically
      //  when the application's main window is not a dialog
      SetIcon(m_hIcon, TRUE);                  // Set big icon
      SetIcon(m_hIcon, FALSE);            // Set small icon
      
      // TODO: Add extra initialization here
  // init our control states
  CButton *pRB;
      pRB = (CButton*)GetDlgItem(IDC_RADIO_COM1);
      if( pRB ) pRB->SetCheck(1);
      pRB = (CButton*)GetDlgItem(IDC_RADIO_XSYNC);
      if( pRB ) pRB->SetCheck(1);
      EnableCmds( FALSE );

  // miscellaneous data initialization
  bInAsyncXfr = FALSE;  // default to Sync mode
      pPort = NULL;
      nIDs = 0;
  InitAsyncProt();

  // set up timer for Async mode
  uiAsyncXfrTmr = SetTimer( ASYNCTMRID, 500, NULL );

      return TRUE;  // return TRUE  unless you set the focus to a control
}

//-------------------------------------------------------------------
void CLtDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
      if ((nID & 0xFFF0) == IDM_ABOUTBOX)
      {
            CAboutDlg dlgAbout;
            dlgAbout.DoModal();
      }
      else
      {
            CDialog::OnSysCommand(nID, lParam);
      }
}

//-------------------------------------------------------------------
// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CLtDlg::OnPaint()
{

      if (IsIconic())
      {
            CPaintDC dc(this); // device context for painting

            SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

            // Center icon in client rectangle
            int cxIcon = GetSystemMetrics(SM_CXICON);
            int cyIcon = GetSystemMetrics(SM_CYICON);
            CRect rect;
            GetClientRect(&rect);
            int x = (rect.Width() - cxIcon + 1) / 2;
            int y = (rect.Height() - cyIcon + 1) / 2;

            // Draw the icon
            dc.DrawIcon(x, y, m_hIcon);
      }
      else
      {
            CDialog::OnPaint();
      }
}

//-------------------------------------------------------------------
// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CLtDlg::OnQueryDragIcon()
{
      return (HCURSOR) m_hIcon;
}

//-------------------------------------------------------------------
BOOL CLtDlg::DestroyWindow()
{

      // TODO: Add your specialized code here and/or call the base class
  // release memory that we own
  if( pPort )
  {
    delete pPort;
    pPort = NULL;
  }
  if( uiAsyncXfrTmr )
  {
    KillTimer( uiAsyncXfrTmr );
    uiAsyncXfrTmr = 0;
  }

      return CDialog::DestroyWindow();
}

//-------------------------------------------------------------------
BEGIN_EVENTSINK_MAP(CLtDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CLtDlg)
      //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()


//-------------------------------------------------------------------
//-------------------------------------------------------------------
void CLtDlg::OnGetBaseVersion()
{
      BYTE CmdDataBuf[16];

  // erase some displayed text
  InitControls();
      SetDlgItemText(IDC_VerTxt, (LPTSTR)"");
  SendDlgItemMessage( IDC_VerTxt, EN_UPDATE );

  // build the command
  CmdDataBuf[0] = '0';      // obligatory 0 (lcl cmd)
      CmdDataBuf[1] = 'a';      // command number

      if( !SendBUPkt( CmdDataBuf, 2 ) )
      {
            if( !GetBUData( CmdDataBuf, 5 ) )
            {
                  CmdDataBuf[5] = 0;  // null terminate Version string
                  SetDlgItemText(IDC_VerTxt, (LPTSTR)&CmdDataBuf[2]);
            }
      }

}

//-------------------------------------------------------------------
void CLtDlg::OnSetAtten()
{
      BYTE CmdDataBuf[16];
      BYTE CmdData;
      int i;

  // erase some displayed text
  InitControls();

  // build the command
  i = GetDlgItemText(IDC_AttenTxt, (LPTSTR)CmdDataBuf, 15);
      if( !i )
  {
    SetDlgItemText(IDC_Notes, "Attenuation value: 0 to 3");
    return;
  }
      CmdData = ((CmdDataBuf[0] << 2) & 0x0c) | 0x30;

      CmdDataBuf[0] = '0';      // obligatory 0 (lcl cmd)
      CmdDataBuf[1] = 'd';      // command number
      CmdDataBuf[2] = CmdData;      // command data

      if( !SendBUPkt( CmdDataBuf, 3 ) )
      {
            GetBUData( CmdDataBuf, 2 );
      }
      
}

//-------------------------------------------------------------------
void CLtDlg::OnGetAtten()
{
      BYTE CmdDataBuf[16];
      char LclTxt[64];
      int retcode;

  // erase some displayed text
  InitControls();
      SetDlgItemText(IDC_AttenTxt, "");
  SendDlgItemMessage( IDC_AttenTxt, EN_UPDATE );

  // build the command
  CmdDataBuf[0] = '0';      // obligatory 0 (lcl cmd)
      CmdDataBuf[1] = 'e';      // command number

      if( !SendBUPkt( CmdDataBuf, 2 ) )
      {
            if( !GetBUData( CmdDataBuf, 3 ) )
            {
                  retcode = ((CmdDataBuf[2] >> 2) & 0x03); // | 0x30;
                  sprintf( LclTxt, "%d", retcode );
                  SetDlgItemText(IDC_AttenTxt, (LPTSTR)LclTxt);
            }
      }
      
}

//-------------------------------------------------------------------
void CLtDlg::OnSetTimeout()
{
      BYTE CmdDataBuf[16];
      BYTE CmdData;
      char LclTxt[64];
      int i;

  // erase some displayed text
  InitControls();

  // build the command
  i = GetDlgItemText(IDC_TkoTxt, (LPTSTR)CmdDataBuf, 15);
  CmdData = 0;
  if( i )
  {
        CmdData = (BYTE)(atoi( (const char *)CmdDataBuf ) & 0x00ff);
  }
  if( (CmdData < 1) || (CmdData > (255 - ('a'-1))) )
  {
            sprintf( LclTxt, "Timeout value: 1 - %d", (int)(255 - ('a'-1)) );
            SetDlgItemText(IDC_Notes, (LPTSTR)LclTxt);
    return;
  }
      CmdData += ('a' - 1);

      CmdDataBuf[0] = '0';      // obligatory 0 (lcl cmd)
      CmdDataBuf[1] = 'h';      // command number
      CmdDataBuf[2] = CmdData;      // command data

      if( !SendBUPkt( CmdDataBuf, 3 ) )
      {
            GetBUData( CmdDataBuf, 2 );
      }

}

//-------------------------------------------------------------------
void CLtDlg::OnGetTimeout()
{
      BYTE CmdDataBuf[16];
      char LclTxt[64];
      int retcode;

  // erase some displayed text
  InitControls();
      SetDlgItemText(IDC_TkoTxt, (LPTSTR)"");
  SendDlgItemMessage( IDC_TkoTxt, EN_UPDATE );

  // build the command
  CmdDataBuf[0] = '0';      // obligatory 0 (lcl cmd)
      CmdDataBuf[1] = 'i';      // command number

      if( !SendBUPkt( CmdDataBuf, 2 ) )
      {
            if( !GetBUData( CmdDataBuf, 3 ) )
            {
                  retcode = CmdDataBuf[2] - 'a' + 1;
                  sprintf( LclTxt, "%d", retcode );
                  SetDlgItemText(IDC_TkoTxt, (LPTSTR)LclTxt);
            }
      }

}


//-------------------------------------------------------------------
void CLtDlg::OnGetIDs()
{
      CListBox *pLB;
      BYTE CmdDataBuf[64];
      WORD TxRan, RxRan, *pus;
  BYTE *pTmrTbl;
  DWORD *pID;
      int i, j;

  // erase some displayed text
  InitControls();
      pLB = (CListBox*)GetDlgItem(IDC_LIST1);
  if( !pLB ) return;
      pLB->ResetContent();
  SendDlgItemMessage( IDC_LIST1, EN_UPDATE );

  // build the command
  TxRan = GenRanShort();
      CmdDataBuf[0] = '0';      // obligatory 0 (lcl cmd)
      CmdDataBuf[1] = 'j';      // command number
  pus = (WORD*)&CmdDataBuf[2];
  *pus = TxRan;

      if( !SendBUPkt( CmdDataBuf, 4 ) )
      {
            if( GetBUData( CmdDataBuf, 45 ) )
                  return;
      }
      else
      {
            return;
      }

      if( calc_chksum( &CmdDataBuf[1], 44 ) == 0 )
      {
            pus = (WORD*)&CmdDataBuf[2];
            RxRan = *pus;
            if( Authenticate( TxRan, RxRan, &CmdDataBuf[4], 8 ) )
            {
                  SetDlgItemText(IDC_Notes, "Authentic!");
            }
            else
            {
                  SetDlgItemText(IDC_Notes, "Bogus!");
            }
    // get the active IDs in muID[] array and list box
    pTmrTbl = (BYTE*)&CmdDataBuf[4];
    pID = (DWORD*)&CmdDataBuf[12];
    for( i = 0, j = 0; i < 8; ++i )
    {
      // if a timer entry is non-zero, the ID is Current
      if( *pTmrTbl )
      {
        muID[j++] = *pID;
                    sprintf( (char*)CmdDataBuf, "%lu = %08lX hex", *pID, *pID );
                    pLB->AddString((char*)CmdDataBuf);
      }
      pTmrTbl++;
      pID++;
    }
    nIDs = j;  // store the number of IDs found (?)
      }
      else
      {
            SetDlgItemText(IDC_Notes, "Bad CS in Get ID Table Data!");
      }

}

//-------------------------------------------------------------------
void CLtDlg::OnButSetmd()
{
      BYTE CmdDataBuf[16];
      BYTE CmdData;
      int i;

  // erase some displayed text
  InitControls();

  // build the command
  i = GetDlgItemText(IDC_ModeTxt, (LPTSTR)CmdDataBuf, 15);
  CmdData = 0;
  if( i )
  {
        CmdData = (BYTE)(atoi( (const char *)CmdDataBuf ) & 0x00ff);
  }
  if( CmdData > 1 )
  {
            SetDlgItemText(IDC_Notes, "Transfer Mode value: 0 or 1");
    return;
  }
      CmdData += '0';

      CmdDataBuf[0] = '0';      // obligatory 0 (lcl cmd)
      CmdDataBuf[1] = 'k';      // command number
      CmdDataBuf[2] = CmdData;      // command data
      CmdDataBuf[3] = 0;  // low byte of authentication word
      CmdDataBuf[4] = 0;  // high byte of authentication word

      if( !SendBUPkt( CmdDataBuf, 5 ) )
      {
            GetBUData( CmdDataBuf, 2 );
      }

}

//-------------------------------------------------------------------
void CLtDlg::OnButGetmd()
{
      BYTE CmdDataBuf[16];
      char LclTxt[64];
      int retcode;

  // erase some displayed text
  InitControls();
      SetDlgItemText(IDC_ModeTxt, "");
  SendDlgItemMessage( IDC_ModeTxt, EN_UPDATE );

  // build the command
  CmdDataBuf[0] = '0';      // obligatory 0 (lcl cmd)
      CmdDataBuf[1] = 'l';      // command number (little 'L')

      if( !SendBUPkt( CmdDataBuf, 2 ) )
      {
            if( !GetBUData( CmdDataBuf, 3 ) )
            {
                  retcode = CmdDataBuf[2] - '0';
                  sprintf( LclTxt, "%d", retcode );
                  SetDlgItemText(IDC_ModeTxt, (LPTSTR)LclTxt);
            }
      }

}

//-------------------------------------------------------------------
void CLtDlg::OnCommCnct()
{
      CButton *pCB, *pRB;
  WORD portnum;
  char txt[64];

      // TODO: Add your control notification handler code here
      pCB = (CButton*)GetDlgItem(IDC_CHECK1);
      if( !pCB ) return;

      // If unchecked, close comm port, Null handle, deactivate buttons
      if( !pCB->GetCheck() )
      {
            if( pPort ) pPort->Disconnect();
            EnableCmds( FALSE );
    bInAsyncXfr = FALSE;
      }
      // else get comm choice, open port, activate buttons
      else
      {
    InitControls();
    pRB = (CButton*)GetDlgItem(IDC_RADIO_COM1);
    if( !pRB )
    {
      Err("NULL Pointer to Control!");
      return;
    }
    if( pRB->GetCheck() ) portnum = 1;
    else portnum = 2;

    if( pPort )
    {
      if( pPort->IsConn() ) pPort->Disconnect();
    }
    else
              pPort = new CPort();
            if( !pPort )
            {
      Err("CPort Object not created!");
                  pCB->SetCheck(0);
                  return;
            }
    pPort->SetPort( portnum );
    pPort->SetBaud( CBR_9600 );
    pRB = (CButton*)GetDlgItem(IDC_RADIO_XASYNC);
    if( !pRB )
    {
      Err("NULL Pointer to Control!");
      return;
    }
    if( pRB->GetCheck() )
    {
      bInAsyncXfr = TRUE;
    }
    else
    {
      bInAsyncXfr = FALSE;
    }

    // timeouts will be maintained as 'async' to allow for quick return on no data...
    // The SendBUPkt() and GetBUData() routines will set the timeouts appropriately
    // and then switch them back before exit.
    SetAsyncModeCTO();  // always set this by default

    if( pPort->Connect() )
    {
              EnableCmds( TRUE );
    }
    else
    {
      sprintf( txt, "Unable to open port: %d!", portnum );
      Err( txt );
      pPort->Disconnect();
              EnableCmds( FALSE );
                  pCB->SetCheck(0);
      bInAsyncXfr = FALSE;
    }
      }
      
}

//-------------------------------------------------------------------
void CLtDlg::FlagAsyncXfrMode( BOOL state )
{
      CListBox *pLB;

  pLB = (CListBox*)GetDlgItem(IDC_LIST1);
  if( pLB && (bInAsyncXfr != state) ) // reset list box on change of monitor mode
    pLB->ResetContent();
  bInAsyncXfr = state;
}

//-------------------------------------------------------------------
void CLtDlg::OnRadioXasync()
{
  FlagAsyncXfrMode( TRUE );
}

//-------------------------------------------------------------------
void CLtDlg::OnRadioXsync()
{
  FlagAsyncXfrMode( FALSE );
}

//-------------------------------------------------------------------
void CLtDlg::Err( char *szErrStr )
{
    MessageBox(
             (LPCTSTR)szErrStr,  // error string
             NULL,  // caption - default 'Error'
             MB_ICONEXCLAMATION | MB_TASKMODAL
            );
}

//-------------------------------------------------------------------
void CLtDlg::InitControls( void )
{
      SetDlgItemText(IDC_BaseRetCode, (LPTSTR)"");
      SetDlgItemText(IDC_Notes, (LPTSTR)"");
  SendDlgItemMessage( IDC_BaseRetCode, EN_UPDATE, 0,0 ); //wparam_wparm, lparam_lparm );
  SendDlgItemMessage( IDC_Notes, EN_UPDATE, 0,0 ); //wparam_wparm, lparam_lparm );
}

//-------------------------------------------------------------------
void CLtDlg::EnableCmds( BOOL state )
{
      CButton *pPB;

      if((pPB = (CButton*)GetDlgItem(IDC_BUTTON1)) != NULL)
            pPB->EnableWindow( state );
      if((pPB = (CButton*)GetDlgItem(IDC_BUTTON2)) != NULL)
            pPB->EnableWindow( state );
      if((pPB = (CButton*)GetDlgItem(IDC_BUTTON3)) != NULL)
            pPB->EnableWindow( state );
      if((pPB = (CButton*)GetDlgItem(IDC_BUTTON4)) != NULL)
            pPB->EnableWindow( state );
      if((pPB = (CButton*)GetDlgItem(IDC_BUTTON5)) != NULL)
            pPB->EnableWindow( state );
      if((pPB = (CButton*)GetDlgItem(IDC_BUTTON6)) != NULL)
            pPB->EnableWindow( state );
      if((pPB = (CButton*)GetDlgItem(IDC_BUT_SETMD)) != NULL)
            pPB->EnableWindow( state );
      if((pPB = (CButton*)GetDlgItem(IDC_BUT_GETMD)) != NULL)
            pPB->EnableWindow( state );
}

//-------------------------------------------------------------------
// calculates the 1's compliment of sum of bytes and places at the
// end of the buffer (pbuf[cnt]).  Returns the calculated value as well.
// This is used to ready a pkt for xmsn and to check a rcvd pkt.
// !make sure there's room in buffer for the inserted chksum!
BYTE CLtDlg::calc_chksum( BYTE *pbuf, BYTE cnt )
{
  BYTE n, accum;

  if( !cnt ) return 0;
  accum = 0;
  for( n = 0; n < cnt; ++n )
  {
    accum += *pbuf;  // accumulate sum of bytes
    pbuf++;
  }
  accum = ~accum;  // take 1's compliment
  *pbuf = accum;  // store chksum at end of buffer
  return accum;  // return the chksum
}

//-------------------------------------------------------------------
WORD CLtDlg::GenRanShort( void )
{
  WORD i, ran, loopcnt;

  // Generate a 16-bit random number for each GetIDTable command transmission
  srand((unsigned)time( NULL ));  // seed the random number generator
  loopcnt = rand() & 0x000f;  // derive a pseudo-random number from seed
  for( i = 0; i < loopcnt; ++i )
  { // pull pseudo-random numbers from the generator
    ran = (WORD)rand();
  }
  return ran;
}

//-------------------------------------------------------------------
// TxChlng is the transmitted 2-byte number
// RxRsp is the returned 2-byte number
// pTmrTbl is a pointer to the start of the returned Timer table
// ntimers is the size of the timer table
int CLtDlg::Authenticate( WORD TxChlng, WORD RxRsp, BYTE *pTmrTbl, int ntimers )
{
  int i, nbits, carry;
  BYTE *pb;
  BYTE accum2[4];

  // static initializers for the generator polynomial
  static byte genply2[2] = { 0x10, 0x0D };

  // initialize the LFSR 2 with the transmitted Random number
  pb = (byte*)&TxChlng;
  accum2[0] = pb[0];
  accum2[1] = pb[1];

  // calculate the number of clocks to LFSR
  nbits = pb[0];
  for( i = 0; i < ntimers; ++i )
  {
    nbits ^= pTmrTbl[i];
  }
  nbits &= 0x0f;  // limit to 15 clocks
  if( !nbits ) nbits = 9;  // if 0 clocks, set to non-zero constant

  for( i = 0; i < nbits; ++i )
  {
    // LSFR 2 - 13 bit
    accum2[0] &= ~0x20; // pre(re)set the 'carry'
    carry = accum2[1] & 0x01;
    if( carry ) // must invert (xor w/'1') the accum
    {
      accum2[0] ^= genply2[0];
      accum2[1] ^= genply2[1];
      accum2[0] |= 0x20; // set the 'carry'
    }
    carry = accum2[0] & 0x01;
    accum2[0] >>= 1;
    accum2[1] >>= 1;
    if( carry ) accum2[1] |= 0x80;
  }

  pb = (byte*)&RxRsp;
  pb[0] &= 0x1f;
  accum2[0] &= 0x1f;
  if( accum2[0] == pb[0] )
  {
    if( accum2[1] == pb[1] )
      return 1;
  }
  return 0;
}

//-------------------------------------------------------------------
int CLtDlg::SendBUPkt( BYTE *pBuf, int nbytes )
{
      BYTE uc;
      char LclTxt[64];
  BOOL bOK;
  char *szErrStr = "SendBUPkt() Base Read Timeout!";

      InitControls();
  SetSyncModeCTO();  // load Sync mode timeout values into the Port object
  pPort->CommitCTOs();  // have port set the system up with the timeouts
  pPort->Flush();  // clear all port buffers

      // make sure we're in sync - send '\', wait for '0'
      pPort->Write( "\\", 1 );
  pPort->Flush();  // the Write should have stopped any Base xmsn, clear buffers again
  bOK = FALSE;
  do
  {
    if( pPort->Read( (char*)&uc, 1 ) != 1 ) break;
    if( uc != '0' )
    {
      szErrStr = "SendBUPkt() Out-of-Sync!";
      break;
    }

    // send the data
    pPort->Write( (char*)pBuf, nbytes );

    // get the Base return code - '0' is good
    if( pPort->Read( (char*)&uc, 1 ) != 1 ) break;

    bOK = TRUE;
  } while(0);
  // revert to Async timeouts
  SetAsyncModeCTO();
  pPort->CommitCTOs();
  pPort->Flush();

  if( !bOK )
  {
    // 'Send' failed
    SetDlgItemText(IDC_Notes, szErrStr);
    return -1;
  }

  // display the Base return code...
  sprintf( LclTxt, "%c", (WORD)uc );
      SetDlgItemText(IDC_BaseRetCode, (LPTSTR)LclTxt);

  if( uc == '0' ) return 0;
  return -1;
}

//-------------------------------------------------------------------
int CLtDlg::GetBUData( BYTE *pBuf, int nbytes )
{
  int i;
  char *cp;
  BOOL bOK;

  SetSyncModeCTO();
  pPort->CommitCTOs();
  pPort->Flush();
  cp = (char*)pBuf;

  bOK = TRUE;
  // each char must be 'dotted' out
  for( i = 0; i < nbytes; ++i )
  {
        pPort->Write( ".", 1 );
        if( pPort->Read( cp, 1 ) != 1 ) bOK = FALSE;
    cp++;
  }
  // revert to Async timeouts
  SetAsyncModeCTO();
  pPort->CommitCTOs();
  pPort->Flush();

  if( bOK ) return 0;
  // 'Receive' failed
  SetDlgItemText(IDC_Notes, "GetBUData() Failed");
  return -1;
}

//-------------------------------------------------------------------
void CLtDlg::SetSyncModeCTO( void )
{
  COMMTIMEOUTS cto;
  cto.ReadIntervalTimeout = 50;  // intercharacter delay MAX
  cto.ReadTotalTimeoutMultiplier = 10;  // x times nchars in 'Read' - milliseconds
  cto.ReadTotalTimeoutConstant = 500; // 500 milliseconds + Multiplier
  cto.WriteTotalTimeoutMultiplier = 50;
  cto.WriteTotalTimeoutConstant = 500;
  // just transfer values to Port Object,
  // actual 'commit' to WIN sys not done here
  pPort->SetCTOs( &cto );
}

//-------------------------------------------------------------------
void CLtDlg::SetAsyncModeCTO( void )
{
  COMMTIMEOUTS cto;
  // the 'Read' member combination forces immediate return
  // if no data is available.
  cto.ReadIntervalTimeout = MAXDWORD;
  cto.ReadTotalTimeoutMultiplier = 0;
  cto.ReadTotalTimeoutConstant = 0;
  cto.WriteTotalTimeoutMultiplier = 50;
  cto.WriteTotalTimeoutConstant = 500;
  // just transfer values to Port Object,
  // actual 'commit' to WIN sys not done here
  pPort->SetCTOs( &cto );
  InitAsyncProt();
}

//-------------------------------------------------------------------
void CLtDlg::InitAsyncProt( void )
{
  bAsyncRxProtInEsc = FALSE;
  AsyncMsgChrCnt = 0;
  AsyncMsgChkSum = 0;
}

//-------------------------------------------------------------------
BOOL CLtDlg::AsyncProtProcMsg( BYTE *msg )
{
  DWORD id;
  BYTE bextra;
  WORD wextra;
  char txt[32];
      CListBox *pLB;
  UINT ret;

  // get ptr to the ID container (LISTBOX in this case)
      pLB = (CListBox*)GetDlgItem(IDC_LIST1);
  if( !pLB ) return FALSE;  // highly unlikely

  // the ID is lilendium in first 4 bytes - direct cast to DWORD
  id = *((DWORD*)msg);
  // the 'extra' 1-byte in the packet is as yet undefined (tag flgs?).
  bextra = msg[4];  // not used but here it is...
  // the 'extra' 2-bytes are for authentication.
  wextra = *((WORD*)&msg[5]);  // not used but here it is...
  sprintf( txt, "%lu", id );  // make ID a string...
  // if it exists...
  ret = pLB->FindStringExact( -1, (LPCTSTR)txt );  // start at beginning
  if( ret != LB_ERR )
  { // delete it (newest goes at tail end)...
    pLB->DeleteString( ret );
  }
  // add it to end. (ListBox is set up to NOT SORT)
      ret = pLB->AddString( (LPCTSTR)txt );
  // time stamp it
  pLB->SetItemData( ret, (DWORD)time( NULL ) );

  // here I added the Texselogic code to output the RFIDs to text files
        char fileName[100] = "";
      char outputFile[200] = "";
      //char outputFileLog[200] = "";
      
      time_t t;
      struct tm *st;
      time(&t);
      st = gmtime(&t);   // here You've got year month ... in a structer
      char testDateStr[100] = "";
      sprintf( testDateStr, "%s", ctime(&t));  // or here in string
      
      char dateStr[15] = "";
      char timeStr[10] = "";
      char dateTimeStr[25] = "";
      sprintf( dateStr, "%02d/%02d/%04d", st->tm_mon+1, st->tm_mday, st->tm_year+1900 );
      sprintf( timeStr, "%02d:%02d:%02d", st->tm_hour, st->tm_min, st->tm_sec );
      sprintf( dateTimeStr, "%s %s\n", dateStr, timeStr );

      sprintf( fileName, "%s.RF", txt );
      sprintf( outputFile, "%s%s", outputPath, fileName );

      ofstream out;
      out.open( outputFile, ios_base::app );
      if (!out) {
            cout <<"could not open";
            exit(0);
      }

      string buff = dateTimeStr;
      out.write (buff.c_str(), buff.size());
      out.close();
      //////////////////////////

  return TRUE;
}

//-------------------------------------------------------------------
// this routine processes incoming (async) bytes into messages
// the protocol EndOfTransmission and Escape chars are defined in ltdlg.h
BOOL CLtDlg::AsyncProtPutBuf( BYTE *pbuf, WORD wcnt )
{
  WORD ui;
  BYTE c;
  BOOL bMsg;

  bMsg = FALSE;
  // go thru entire buffer, may be more than 1 pkt

  WORD count;
  for( ui = 0; ui < wcnt; ++ui )
  {
    c = pbuf[ui];
    switch( c )
    {
    case EOTCHR:  // end-of-transmission, packet?
      if( AsyncMsgChrCnt == IDCLRMSGLEN )
      { // pkt length OK
        if( AsyncMsgChkSum == 0xFF )
        { // checksum OK, process the message
          AsyncProtProcMsg( AsyncMsg );
          bMsg = TRUE;
        }
      }
      InitAsyncProt(); // reset the protocol state
      break;
    case ESCCHR:  // escape char, flag state and continue
      bAsyncRxProtInEsc = TRUE;
      break;
    default:  // other characters...
      if( bAsyncRxProtInEsc ) c = ~c; // escaped, compliment
      bAsyncRxProtInEsc = FALSE; // always do this
      AsyncMsg[AsyncMsgChrCnt] = c; // store character in msg buf
      // do additional check for message overrun (out of sync)
      if( AsyncMsgChrCnt < IDCLRMSGLEN ) AsyncMsgChrCnt++;
      AsyncMsgChkSum += c; // accumulate sum of un-escaped bytes
    }
      count = ui;
  }
  return bMsg;  // TRUE if at least 1 msg found, else FALSE
}

//-------------------------------------------------------------------
void CLtDlg::OnTimer(UINT nIDEvent) // fires every 1/2 sec
{
  DWORD dwcnt;
  BYTE lclbuf[128];
      CListBox *pLB;
  time_t t0;
  DWORD tspan;
  int itemcnt;

  while(  // not 'if' so we can 'break' out
     bInAsyncXfr              &&
     (nIDEvent == ASYNCTMRID) &&
     pPort                    &&
     pPort->IsConn()
    )
  { // check for received characters, new IDs.
    dwcnt = pPort->Read( (char*)lclbuf, 128 );
        pLB = (CListBox*)GetDlgItem(IDC_LIST1);
    if( !pLB ) break;  // bad news
    if( dwcnt )  // if any new received data...
      AsyncProtPutBuf( lclbuf, (WORD)dwcnt );  // let protocol process it.
    // The ID ListBox contains the ID string and system time of addition in ItemData.
    // The IDs are added at the END of the list as received (1st deleted if they exist).
    // So this next block only checks the first item since it is the OLDEST.
    itemcnt = pLB->GetCount();
    if( itemcnt )
    {
      t0 = (time_t)pLB->GetItemData( 0 );
      tspan = (DWORD)(time( NULL ) - t0);
      if( tspan > ASYNCIDTOSEC )  // expired?
        pLB->DeleteString( 0 );  // delete it.
    }
    // show current count of IDs
    sprintf( (char*)lclbuf, "count: %d", itemcnt );
        SetDlgItemText(IDC_Notes, (LPTSTR)lclbuf);
    break;
  }

  // call base class handler for other TIMER handlers
      CDialog::OnTimer(nIDEvent);
}

0
 
LVL 5

Accepted Solution

by:
aaronfeng earned 1200 total points
ID: 16777717
You should be able to do:

Process[] p = Process.GetProcesseByName("lt");

if you don't see anything try this to see all the process running and get the name off:

Process[] p = Process.GetProcesses();

Cheers,

Aaron
0
 

Author Comment

by:ba272
ID: 16777742
Aaron,

We may be getting closer to the problem.  I did as you suggested and ran GetProcesses().  But I saw exceptions.


ExitCode      <error: an exception of type: {System.InvalidOperationException} occurred>      int

ExitTime      <error: an exception of type: {System.InvalidOperationException} occurred>      System.DateTime

Also, for some reason the Watch window is showing arrays in hex.  So it shows ar array thusly:

[0x0]
[0x1]
[0x2]

Any idea what causes this?  Also, the exceptions may be causing
GetProcessByName() from working correctly.

Bob
0
 

Author Comment

by:ba272
ID: 16777863
Aaron,

I have it working now.  I think my directory and filename had a spelling error in it.

Shame on me.


Thanks,
Bob
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question