?? 9111prtg.c
字號:
CreateWindow("BUTTON","6" ,
WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | BS_LEFTTEXT | WS_GROUP,
output_pos[4].x+100, io_pos[0].y+31+20,25,15, hWnd,IDC_CH+6, hInst, NULL);
CreateWindow("BUTTON","7" ,
WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | BS_LEFTTEXT | WS_GROUP,
output_pos[4].x+100, io_pos[0].y+49+20,25,15, hWnd, IDC_CH+7, hInst, NULL);
//default channel 0
for (i=1;i<8;i++) bCheck[i]=FALSE;
bCheck[0] = TRUE;
channel = 0;
SendMessage(GetDlgItem(hWnd,IDC_CH), BM_SETCHECK, 1, 0);
hBlackBrush= CreateSolidBrush(RGB(0,0,0));
hRedPen= CreatePen(PS_SOLID,1,RGB(255,0,0));
hBlackPen= CreatePen(PS_SOLID,1,RGB(0,0,0));
break;
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
// DMA analog input box
SelectObject(hDC, GetStockObject(GRAY_BRUSH));
Rectangle(hDC, output_pos[15].x-10, io_pos[15].y-24, output_pos[0].x+26, io_pos[0].y+195);
SetTextColor(hDC,RGB(255,255,0));
SetBkColor(hDC, RGB(0, 0, 255));
TextOut(hDC, io_pos[15].x, io_pos[15].y-35, "DMA Input", 9);
SelectObject(hDC, hBlackBrush);
Rectangle(hDC, output_pos[15].x+35, io_pos[15].y-2, output_pos[4].x+41, io_pos[0].y+172);
SetBkMode(hDC,TRANSPARENT);
if(precheck)
TextOut(hDC,output_pos[13].x+70, input_pos[10].y-40,"PostCount",9);
TextOut(hDC,output_pos[13].x-60, input_pos[10].y,"Samping Rate",12);
TextOut(hDC,output_pos[13].x+30, input_pos[15].y+20,"KHZ",3);
TextOut(hDC,output_pos[13].x+70, input_pos[10].y,"Buffer Size",11);
TextOut(hDC,input_pos[2].x-10, io_pos[15].y+118,"Range: +-5V",11);
TextOut(hDC,input_pos[15].x, io_pos[15].y-19,"Volt",4);
TextOut(hDC,input_pos[15].x, io_pos[15].y-5,"5.00",4);
TextOut(hDC,input_pos[15].x, io_pos[15].y+36,"2.50",4);
TextOut(hDC,input_pos[15].x, io_pos[15].y+77,"0.00",4);
TextOut(hDC,input_pos[15].x-3, io_pos[15].y+118,"-2.50",5);
TextOut(hDC,input_pos[15].x-3, io_pos[15].y+159,"-5.00",5);
TextOut(hDC,input_pos[10].x+10, io_pos[10].y-19,"Signals",7);
TextOut(hDC,output_pos[4].x+60, io_pos[0].y-15,"Channel",7);
EndPaint(hWnd, &ps);
break;
// Sample Rate Spin Control
case WM_VSCROLL:
switch (LOWORD(wParam)) {
case SB_LINEUP :
sample_rate+=5000;
if (sample_rate > 50000 ) sample_rate=50000;
break;
case SB_LINEDOWN:
sample_rate-=5000;
if (sample_rate < 5000 ) sample_rate=5000;
break;
}
wsprintf(n,"%d",sample_rate/1000);
SetWindowText(hEdit,n);
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDM_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
case IDC_CH:
case IDC_CH+1:
case IDC_CH+2:
case IDC_CH+3:
case IDC_CH+4:
case IDC_CH+5:
case IDC_CH+6:
case IDC_CH+7:
if (!bCheck[wParam-IDC_CH]) {
SendMessage(GetDlgItem(hWnd,wParam), BM_SETCHECK, 1, 0);
SendMessage(GetDlgItem(hWnd,IDC_CH+channel), BM_SETCHECK, 0, 0);
bCheck[channel]=FALSE;
}
channel=wParam-IDC_CH;
bCheck[channel]=TRUE;
break;
case IDC_SHOW :
DialogBox(hInst, "DMABox", hWnd, ShowDMA);
break;
case IDC_START:
if (hMem != NULL) {
GlobalUnfix(hMem);
GlobalUnlock(hMem);
GlobalFree(hMem);
}
// allocate a memory for DMA
postCount = GetDlgItemInt(hWnd,IDC_EDIT2,NULL ,FALSE);
data_size=GetDlgItemInt(hWnd,IDC_EDIT1,NULL ,FALSE);
if (data_size%512) {
wsprintf(s, "Buffer Size should be devided by 512\n", postCount+2);
MessageBox(hWnd,s,"Data Size Error", MB_OK);
break;
}
mem_size=data_size * 2;
hMem = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,mem_size);
ai_buf = (U16 *)GlobalLock(hMem);
if (ai_buf == NULL ) {
MessageBox(hWnd,"DMA", "No Memory", MB_OK);
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
}
GlobalFix(hMem);
fstop =0;
if ((err=AI_9111_Config(card,TRIG_INT_PACER, precheck, postCount))!= NoError) {
wsprintf(s, "AI_Config Error = %d\n", err);
MessageBox(hWnd, s, "Error", MB_OK);
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
}
if ((err=AI_AsyncDblBufferMode (card, 1)) != NoError) {
wsprintf(s, "AI_AsyncDblBufferMode Error = %d\n", err);
MessageBox(hWnd, s, "Error", MB_OK);
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
}
if((err= AI_EventCallBack (card, 1, DBEvent, (U32) AI_DBCallBack)) != NoError) {
wsprintf(s, "AI_EventCallBack Error = %d\n", err);
MessageBox(hWnd, s, "Error", MB_OK);
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
}
if((err= AI_EventCallBack (card, 1, AIEnd, (U32) AI_CallBack)) != NoError) {
wsprintf(s, "AI_EventCallBack Error = %d\n", err);
MessageBox(hWnd, s, "Error", MB_OK);
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
}
if ((err=AI_ContReadChannel(card, channel, AD_B_5_V, ai_buf, data_size, (F64)sample_rate, ASYNCH_OP)) != NoError) {
wsprintf(s, "AI_ContReadPort Error = %d\n", err);
MessageBox(hWnd, s, "Error", MB_OK);
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
}
EnableWindow(hStart, FALSE);
EnableWindow(hStop, TRUE);
EnableWindow(hValue, FALSE);
hMainWnd = hWnd;
clear_op = FALSE;
MessageBeep(0);
break;
case IDC_STOP:
clear_op = TRUE;
AI_AsyncClear(card, &count);
EnableWindow(hStart, TRUE);
EnableWindow(hStop, FALSE);
EnableWindow(hValue, TRUE);
break;
default:
return(DefWindowProc(hWnd, message, wParam, lParam));
}
break;
case WM_DESTROY:
if (card >= 0) Release_Card(card);
DeleteObject(hBlackBrush);
DeleteObject(hRedPen);
GlobalUnfix(hMem);
GlobalUnlock(hMem);
GlobalFree(hMem);
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd, message, wParam, lParam));
}
return(NULL);
}
BOOL PASCAL ShowDMA(hDlg, message, wParam, lParam)
HWND hDlg;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
int nTabs[2] = {32, 92};
int i;
char cBuf[100];
char string[10]=" ";
char data_str[3]=" ";
I16 *pp;
switch (message) {
case WM_INITDIALOG:
hListBox = CreateWindow("LISTBOX", "Index Data (Hex)",
WS_CHILD | WS_VISIBLE | LBS_HASSTRINGS | LBS_STANDARD | LBS_USETABSTOPS |WS_CAPTION,
50, 40, 240, 180, hDlg, 100, hInst, NULL);
SendMessage(hListBox, LB_RESETCONTENT, 0, 0L);
SendMessage(hListBox, LB_SETTABSTOPS, 2, (DWORD)(LPINT) nTabs);
SetDlgItemText(hDlg, DMA_DESCP, "This ListBox can show at most 4000 data");
itoa( data_size, string, 10);
SetDlgItemText(hDlg, DMA_SPACE, string);
pp = (I16 *)ai_buf;
if (count > 4000) count = 4000;
if (!count) count = data_size;
for(i=0;i<count; i++) {
wsprintf(cBuf, "%5d\t %04x", i, pp[i]& 0xffff);
SendMessage(hListBox, LB_INSERTSTRING, -1, (DWORD)(LPSTR)cBuf);
}
ShowWindow(hListBox, SW_SHOW);
return (TRUE);
case WM_COMMAND:
if (LOWORD(wParam) == ID_STOP) {
DestroyWindow(hListBox);
EndDialog(hDlg, TRUE);
return (TRUE);
}
break;
}
return (FALSE);
}
void AI_DBCallBack()
{
HDC hDC;
int t =0;
U16 adinput;
U32 i, oldx, oldy, newx, newy, tfer_size;
hDC = GetDC(hMainWnd);
tfer_size = data_size/2; //Every time transfer half size of buffer
AI_AsyncDblBufferTransfer(card, ai_buf);
SelectObject(hDC, hBlackBrush);
SelectObject(hDC, hBlackPen);
Rectangle(hDC, output_pos[15].x+35, io_pos[15].y-2, output_pos[4].x+41, io_pos[0].y+172);
SelectObject(hDC, hRedPen);
for (i=0; i<tfer_size; i++) {
adinput = ai_buf[i]>>4;
newy = io_pos[0].y+86-(87*(I16)adinput)/2048;
newx = i*336/tfer_size+output_pos[15].x+35;
if (i==0)
MoveToEx(hDC, newx, newy, NULL);
else
MoveToEx(hDC, oldx, oldy, NULL);
LineTo(hDC, newx, newy);
oldx = newx;
oldy = newy;
}
ReleaseDC(hMainWnd, hDC);
}
void AI_CallBack()
{
HDC hDC;
int t =0;
U16 adinput;
U32 i, oldx, oldy, newx, newy, tfer_size;
char buf[25];
hDC = GetDC(hMainWnd);
tfer_size = data_size/2; //Every time transfer half size of buffer
EnableWindow(hStart, TRUE);
EnableWindow(hStop, FALSE);
EnableWindow(hValue, TRUE);
if(!clear_op)
AI_AsyncClear(card, &count);
AI_AsyncDblBufferTransfer(card, ai_buf);
SelectObject(hDC, hBlackBrush);
SelectObject(hDC, hBlackPen);
Rectangle(hDC, output_pos[15].x+35, io_pos[15].y-2, output_pos[4].x+41, io_pos[0].y+172);
SelectObject(hDC, hRedPen);
if (!count) count = tfer_size;
for (i=0; i<count; i++) {
adinput = ai_buf[i]>>4;
newy = io_pos[0].y+86-(87*(I16)adinput)/2048;
newx = i*336/tfer_size+output_pos[15].x+35;
if (i==0)
MoveToEx(hDC, newx, newy, NULL);
else
MoveToEx(hDC, oldx, oldy, NULL);
LineTo(hDC, newx, newy);
oldx = newx;
oldy = newy;
}
ReleaseDC(hMainWnd, hDC);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -