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

📄 9111int.c

📁 PCI9111卡的采集例子程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "resource.h"
#include "dask.h"

#define IDM_EXIT        110
#define IDC_ADDR        200
#define IDC_SCROLL      207
#define IDC_START       208
#define IDC_STOP        209
#define IDC_PAUSE       210
#define IDC_EDIT        211
#define IDC_CHAN        214
#define IDC_SHOW        213
#define NONE              0

int PASCAL      WinMain(HANDLE, HANDLE, LPSTR, int);
long  PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
BOOL  PASCAL ShowINT(HWND, UINT, WPARAM, LPARAM);

HANDLE  hInst;
HWND hListBox;
HWND hChanComboBox, hCardComboBox;
HWND hADScroll;
HWND hEdit,hEdit1,hData;
int input=0, output=0;
int oldinput[8], adinput;

HBRUSH  hBlackBrush;
HPEN    hRedPen;

long  sample_rate=10000;
unsigned int base_addr=NONE,gain=1;
I16 card = -1, card_number =0;;
I16 Card_Type=PCI_9111DG;
long  data_size=10240;
U16   channel=0, range = AD_B_5_V;

DWORD  mem_size = 0;
static HANDLE hMem=NULL;
I16 *ai_buf;
I16 card_value[2] = {PCI_9111DG, PCI_9111HR};
LPSTR Card_Name[2]={"PCI9111DG", "PCI9111HR"};


POINT input_pos[16]= {{470, 280},  {440, 280},
                       {410, 280},  {380, 280},
                       {350, 280},  {320, 280},
                       { 290, 280},  {260, 280},
                       {230, 280},  {200, 280},
                       {170, 280},  {140, 280},
                       {110, 280},  {80, 280},
                       { 50, 280},  { 20, 280},
                      };

POINT output_pos[16] ={
                       {470, 340},  {440, 340},
                       {410, 340},  {380, 340},
                       {350, 340},  {320, 340},
                       { 290, 340},  {260, 340},
                       {230, 340},  {200, 340},
                       {170, 340},  {140, 340},
                       {110, 340},  {80, 340},
                       { 50, 340},  { 20, 340},
                      };

POINT io_pos[16] ={
                       {395, 40},  {370, 40},
                       {345, 40},  {320, 40},
                       {295, 40},  {270, 40},
                       { 245, 40},  {220, 40},
                       {195, 40},  {170, 40},
                       {145, 40},  {120, 40},
                       {95, 40},  {70, 40},
                       { 45, 40},  { 20, 40},
                      };

HBRUSH  hLTGreenBrush,hGreenBrush,hBlueBrush,hYellowBrush,hRedBrush,hBlackBrush,hWhiteBrush
        ,hLTRedBrush,hLTBlueBrush;
HPEN    hRedPen,hYellowPen,hGreenPen,hBluePen,hLTBluePen,hLTRedPen,hLTGreenPen,hWhitePen;

BOOL InitApplication(HANDLE);
BOOL InitInstance(HANDLE, int);

int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance, hPrevInstance;
LPSTR lpCmdLine;
int nCmdShow;
{
  MSG msg;

  if (!hPrevInstance)
     if (!InitApplication(hInstance))  return(FALSE);
  if (!InitInstance(hInstance, nCmdShow)) return(FALSE);
  while (GetMessage(&msg, NULL, NULL, NULL)) {
     TranslateMessage(&msg);
     DispatchMessage(&msg);
  }
  return(msg.wParam);
}

BOOL InitApplication(hInstance)
HANDLE hInstance;
{
  WNDCLASS wc;

  /* Main Window Class */
  wc.style = NULL;
  wc.lpfnWndProc = (WNDPROC)MainWndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = hInstance;
  wc.hIcon = LoadIcon(hInstance, "MyIcon");
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = "GenericWClass";
  if (!RegisterClass(&wc)) return(FALSE);
}

BOOL InitInstance(hInstance, nCmdShow)
HANDLE hInstance;
int nCmdShow;
{
  HWND hWnd;
  HMENU hSampleMenu;

  hInst = hInstance;
  hSampleMenu = LoadMenu(hInstance, "U7120Menu");
  hWnd = CreateWindow("GenericWClass",
                      (LPCSTR)"9111 Autoscan Interrupt",
                      WS_OVERLAPPEDWINDOW,
                      CW_USEDEFAULT,
                      CW_USEDEFAULT,
                      520,
                      400,
                      NULL,
                      hSampleMenu,
                      hInstance,
                      NULL);
  if (!hWnd) return(FALSE);
  ShowWindow(hWnd, nCmdShow);
  UpdateWindow(hWnd);
  return(TRUE);
}

BOOL PASCAL setup(HWND hWnd, unsigned message, WPARAM wParam, LPARAM lParam)
{
  int i,k;
  char n[16];
  char s[50];
      switch (message) {
         case WM_INITDIALOG:
              for (i=0;i<2;i++) {
                 SendMessage(GetDlgItem(hWnd,IDC_COMBO1), CB_ADDSTRING, NULL, (LONG)Card_Name[i]);
			  }
              SendMessage(GetDlgItem(hWnd,IDC_COMBO1) , CB_SETCURSEL, 0, 0L);
              for (i=0;i<16;i++) {
                wsprintf(n, "%d", i);
                _strupr(n);
                SendMessage(GetDlgItem(hWnd,IDC_COMBO2), CB_ADDSTRING, NULL, (LONG)(LPSTR) n);
              }
              SendMessage(GetDlgItem(hWnd,IDC_COMBO2) , CB_SETCURSEL, 0, 0L);
              break;
         case WM_COMMAND:
              switch(LOWORD(wParam)) {

                case IDC_COMBO1:
                     if (HIWORD(wParam) == CBN_CLOSEUP) {
                        i = (int)SendMessage(GetDlgItem(hWnd,IDC_COMBO1), CB_GETCURSEL, 0, 0L);
                        SendMessage(GetDlgItem(hWnd,IDC_COMBO1), CB_GETLBTEXT, i, (LPARAM)((LPCSTR)n));
						Card_Type = card_value[i];
                     }
                     return(TRUE);
                case IDC_COMBO2:
                     if (HIWORD(wParam) == CBN_CLOSEUP) {
                        i = (int)SendMessage(GetDlgItem(hWnd,IDC_COMBO2), CB_GETCURSEL, 0, 0L);
                        SendMessage(GetDlgItem(hWnd,IDC_COMBO2), CB_GETLBTEXT, i, (LPARAM)((LPCSTR)n));
                        card_number = i;
                     }
                     return(TRUE);
                case IDOK://采集  注册采集卡
                     if ((card=Register_Card(Card_Type, card_number)) < 0) {
                        wsprintf(s, "Register_Card Error = %d\n", card);
                        MessageBox(hWnd, s, "Error", MB_OK);
                        SendMessage(hWnd, WM_CLOSE, 0, 0L);
                       break;
                     }
                     EndDialog(hWnd, TRUE);
                     InvalidateRect(hWnd, NULL, FALSE);
                     return (TRUE);
                case IDCANCEL:
                     EndDialog(hWnd, TRUE);
                     return (TRUE);
              }
              break;
      }
      return (FALSE);
}

long  PASCAL MainWndProc(hWnd, message, wParam, lParam)
HWND hWnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
  HDC hDC;
  PAINTSTRUCT ps;
  int i;
  int cur_channel;
  char s[50];
  char n[6];
  static   int pos=0;
  static int count,status;
  I16 err;

  switch(message) {
    case WM_CREATE:
           DialogBox(hInst,IDD_DIALOG2, hWnd, setup);//显示第一个对话框,按OK才返回
		   if(card<0) {
		     SendMessage(hWnd, WM_CLOSE, 0, 0L);
		     break;
		   }
           hChanComboBox = CreateWindow("ComboBox", NULL,
                   CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_VSCROLL,
                   input_pos[10].x, input_pos[15].y+18, 100, 160, hWnd, IDC_CHAN, hInst, NULL);
           SendMessage(hChanComboBox, CB_ADDSTRING, NULL, (LONG)(LPSTR)"CH0");
           SendMessage(hChanComboBox, CB_ADDSTRING, NULL, (LONG)(LPSTR)"CH0 ~ CH1");
           SendMessage(hChanComboBox, CB_ADDSTRING, NULL, (LONG)(LPSTR)"CH0 ~ CH2");
           SendMessage(hChanComboBox, CB_ADDSTRING, NULL, (LONG)(LPSTR)"CH0 ~ CH3");
           SendMessage(hChanComboBox, CB_ADDSTRING, NULL, (LONG)(LPSTR)"CH0 ~ CH4");
           SendMessage(hChanComboBox, CB_ADDSTRING, NULL, (LONG)(LPSTR)"CH0 ~ CH5");
           SendMessage(hChanComboBox, CB_ADDSTRING, NULL, (LONG)(LPSTR)"CH0 ~ CH6");
           SendMessage(hChanComboBox, CB_ADDSTRING, NULL, (LONG)(LPSTR)"CH0 ~ CH7");
           SendMessage(hChanComboBox ,CB_SETCURSEL, 0, 0L);
           hEdit=CreateWindow("EDIT", NULL,
                   WS_CHILD | WS_VISIBLE | ES_LEFT,
                   output_pos[13].x-30, input_pos[15].y+20,40, 20, hWnd, IDC_EDIT, hInst, NULL);

           wsprintf(n,"%d",sample_rate/1000);
           SetWindowText(hEdit,n);

           CreateWindow("SCROLLBAR", NULL,
                   WS_CHILD | WS_VISIBLE | SBS_VERT,
                   output_pos[13].x+10, input_pos[15].y+20,20, 20, hWnd, IDC_SCROLL, hInst, NULL);

           CreateWindow("BUTTON","Start" ,
                   WS_CHILD | WS_VISIBLE ,
                   output_pos[10].x+140, input_pos[10].y+10,70, 30, hWnd, IDC_START, hInst, NULL);

           hData=CreateWindow("BUTTON","Data Value"   ,
                   WS_CHILD | WS_VISIBLE ,
                   output_pos[10].x+230, input_pos[10].y+10,80, 30, hWnd, IDC_SHOW, hInst, NULL);

           hLTGreenBrush = CreateSolidBrush(RGB(0, 255, 0));
           hGreenBrush = CreateSolidBrush(RGB(0, 128, 0));
           hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
           hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
           hYellowBrush= CreateSolidBrush(RGB(255,255,0));
           hBlackBrush= CreateSolidBrush(RGB(0,0,0));
           hLTBlueBrush= CreateSolidBrush(RGB(0,255,255));
           hLTRedBrush= CreateSolidBrush(RGB(255,128,0));
           hWhiteBrush= CreateSolidBrush(RGB(255,255,255));
           hRedPen= CreatePen(PS_SOLID,1,RGB(255,0,0));
           hYellowPen= CreatePen(PS_SOLID,1,RGB(255,255,0));
           hBluePen= CreatePen(PS_SOLID,1,RGB(0,0,255));
           hGreenPen= CreatePen(PS_SOLID,1,RGB(0,255,0));
           hLTBluePen= CreatePen(PS_SOLID,1,RGB(0,128,255));

⌨️ 快捷键说明

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