Stoppt die Vorratsdatenspeicherung! Jetzt klicken && handeln!Willst du auch bei der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:
 
K8055 USB Interface - Teil 1
von Plapperkatze am 10.Juli 2006 um 21:25
zurück zur Kategorie "Tutorials"

Für Besitzer eines K8055 Boards von Vellemann (erhältlich bei Conrad Elektronik) http://www.velleman.be/product/view/?lan~~2?3~~id=351346 hier eine Zusammenfassung meiner Ergebnisse, Teil 1



Ich bin nicht schuld, wenn ihr euer Board kaputtmacht. Ihr handelt auf eigene Verantwortung.

Als großes Manko erscheint mir die Benutzung der K8055D.dll, der mitgelieferten Treiber-Bibliothek. Einstweilen werde ich sie aber verwenden.

Lauflicht mit K8055 USB Interface (Konsole)
//----------------------------------------------------------------------
// lauflicht fuer K8055 USB Interface von plapperkatz
// bcc32 version, card + k8055d.dll benoetigt
//----------------------------------------------------------------------
// als karte wird addresse 0 angenommen (Jumper SK5 und SK6 gebrückt)
#define K8055ADRESS 0
//----------------------------------------------------------------------
// Achtung! Schliessen des Programms vor myCloseDevice(K8055ADRESS)
// führt zu einem Laufzeitfehler.
//----------------------------------------------------------------------
#include <windows.h> // for DLL usage
#include <conio.h> // for kbhit()
#include <time.h> // for GetTickCount()

void wait(long msec)
{
 DWORD k,l;  
 k=GetTickCount();
 l=k;
 while (k<(l+msec))
 {
   k=GetTickCount();
 }  
}

int main(int argc, char *argv[])
{
 long l=1,dir=0;

 typedef long __stdcall (*tOpenDevice)(long);
 typedef void __stdcall (*tSetAllDigital) ();
 typedef void __stdcall (*tWriteAllDigital) (long);
 typedef void __stdcall (*tCloseDevice)(long);
 typedef void __stdcall (*tClearAllDigital) ();
 typedef long __stdcall (*tReadAnalogChannel) (long);
   
   tOpenDevice myOpenDevice;
   tWriteAllDigital myWriteAllDigital;
   tCloseDevice myCloseDevice;
   tReadAnalogChannel myReadAnalogChannel;
 
   HMODULE myDll;
   myDll = LoadLibrary("K8055D.DLL");
   if (!myDll)exit(1);
 
   myOpenDevice = (tOpenDevice)GetProcAddress(myDll,"OpenDevice");
   myCloseDevice = (tCloseDevice)GetProcAddress(myDll,"CloseDevice");
   myWriteAllDigital = (tWriteAllDigital)GetProcAddress(myDll,"WriteAllDigital");
   myReadAnalogChannel = (tReadAnalogChannel)GetProcAddress(myDll,"ReadAnalogChannel");

   myOpenDevice(K8055ADRESS);


   while(!kbhit())
   {
     int j;
     j=myReadAnalogChannel(1);
     if(dir==0)
     {
       l=l*2;
       if(l>255)dir=-1;
     }
     else
     {
       l=l/2;
       if(l<1){l=1;dir=0;}
     }
     myWriteAllDigital(l);
     wait(j);
   }

   myWriteAllDigital(0);
   myCloseDevice(K8055ADRESS);
   FreeLibrary(myDll);

   return EXIT_SUCCESS;
}

http://katze.dead-men.de/upload/40_lauflicht.rar

"Oszilloskop" mit K8055 USB Interface (Win32-App)
//----------------------------------------------------------------------
// oszi fuer K8055 USB Interface von plapperkatz
// bcc32 version, card + k8055d.dll benoetigt
//----------------------------------------------------------------------
// als karte wird addresse 0 angenommen (Jumper SK5 und SK6 gebrückt)
#define K8055ADRESS 0
//----------------------------------------------------------------------
// Achtung! Schliessen des Programms vor myCloseDevice(K8055ADRESS)
// führt zu einem Laufzeitfehler.
//----------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <math.h>

   const char szAppName[]    = "K8055-Oszi von der Plapperkatz";

   LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

   // knob class
   #include "knobclass.cpp"
   KNOB knob1(340,30,40,1,10,1);

   HBITMAP hBmp;

   HMODULE myDll;

   LONGLONG Frequency, CurrentTime, LastTime;
   double TimeElapsed, TimeScale;
   BOOL CounterAvailable=FALSE;

   typedef long __stdcall (*tOpenDevice)(long);
   typedef void __stdcall (*tSetAllDigital) ();
   typedef void __stdcall (*tWriteAllDigital) (long);
   typedef void __stdcall (*tCloseDevice) ();
   typedef void __stdcall (*tVersion) ();
   typedef void __stdcall (*tClearAllDigital) ();
   typedef long __stdcall (*tReadAnalogChannel) (long);
   typedef void __stdcall (*tOutputAnalogChannel) (long,long);

   tOpenDevice myOpenDevice;
   tSetAllDigital mySetAllDigital;
   tWriteAllDigital myWriteAllDigital;
   tCloseDevice myCloseDevice;
   tVersion myVersion;
   tClearAllDigital myClearAllDigital;
   tReadAnalogChannel myReadAnalogChannel;
   tOutputAnalogChannel myOutputAnalogChannel;

int WINAPI WinMain(  HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
{
 MSG        msg;
 HWND       hWnd;
 WNDCLASS   wc;

 wc.style               = NULL; // diesmal nicht CS_HREDRAW | CS_VREDRAW;
 wc.lpfnWndProc         = WndProc;
 wc.cbClsExtra          = 0;
 wc.cbWndExtra          = 0;
 wc.hInstance           = hInstance;
 wc.hCursor             = LoadCursor(NULL, IDC_ARROW);
 wc.hIcon               = LoadIcon(NULL, IDI_APPLICATION);
 wc.hbrBackground       = (HBRUSH)GetStockObject(LTGRAY_BRUSH);//hBrush;
 wc.lpszClassName       = szAppName;
 wc.lpszMenuName        = NULL;
 
 RegisterClass(&wc);
 
 hWnd = CreateWindow(   szAppName,
                        szAppName,
                        WS_OVERLAPPED|WS_SYSMENU,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        396,
                        290+24,
                        NULL,
                        NULL,
                        hInstance,
                        NULL);
                       

 // timer initialisieren
 SetTimer(hWnd,        // handle to main window
   1,                  // timer identifier
   1,                  // ms interval
   (TIMERPROC) NULL);  // no timer callback


 ShowWindow(hWnd, iCmdShow);
 UpdateWindow(hWnd);

 while (GetMessage(&msg, NULL, 0, 0))
 {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
 }
 return msg.wParam;
}

int old=240;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 HDC hDC,hBmpDC;
 PAINTSTRUCT ps;
 RECT r={10,10,330,250};
 HBRUSH hBrush;
 HPEN hPen;
 char c[256];

 switch (message)
 {
   case WM_CREATE:
     hBmp=CreateBitmap(320,240,1,32,NULL);

     myDll = LoadLibrary("K8055D.DLL");
     if (!myDll)exit(1);
 
     myOpenDevice = (tOpenDevice)GetProcAddress(myDll,"OpenDevice");
     myCloseDevice = (tCloseDevice)GetProcAddress(myDll,"CloseDevice");
     myVersion = (tVersion)GetProcAddress(myDll,"Version");

     myClearAllDigital = (tClearAllDigital)GetProcAddress(myDll,"ClearAllDigital");
     mySetAllDigital = (tSetAllDigital)GetProcAddress(myDll,"SetAllDigital");
     myWriteAllDigital = (tWriteAllDigital)GetProcAddress(myDll,"WriteAllDigital");
     myReadAnalogChannel = (tReadAnalogChannel)GetProcAddress(myDll,"ReadAnalogChannel");
     myOutputAnalogChannel = (tOutputAnalogChannel)GetProcAddress(myDll,"OutputAnalogChannel");

     myOpenDevice(K8055ADRESS);
     myOutputAnalogChannel(2,255);

     break;
   case WM_TIMER:
   {
     InvalidateRect(hWnd,&r,FALSE);
     return 0;
   }
   case WM_PAINT:
   {
     hDC = BeginPaint(hWnd, &ps);
     hBmpDC=CreateCompatibleDC(hDC);
     SelectObject(hBmpDC,hBmp);

     int d=knob1.knobValue;

     BitBlt(hBmpDC,0,0,319-d,240,hBmpDC,d,0,SRCCOPY);

     hPen=CreatePen(PS_SOLID,1,RGB(16,16,16));
     SelectObject(hBmpDC,hPen);

     hBrush=CreateSolidBrush(RGB(16,16,16));
     SelectObject(hBmpDC,hBrush);

     Rectangle(hBmpDC,319-d,0,320,240);

     DeleteObject(hPen);
     DeleteObject(hBrush);

     hPen=CreatePen(PS_SOLID,1,0x40FFC1);
     SelectObject(hBmpDC,hPen);

     MoveToEx(hBmpDC,319-d,old,NULL);
     double j=(double)myReadAnalogChannel(1)/256;
     old=239-(int)(j*240);
     LineTo(hBmpDC,319,old);

     DeleteObject(hPen);

     BitBlt(hDC,10,10,319,240,hBmpDC,1,0,SRCCOPY);

     SetBkColor(hDC,RGB(192,192,192));
     sprintf(c,"X: %1.1lf",knob1.knobValue);
     TextOut(hDC,340,10,c,strlen(c));

     DeleteDC(hBmpDC);
     EndPaint(hWnd, &ps);
   }
   break;

   case WM_COMMAND:
     break;

   case WM_DESTROY:
   {
     PostQuitMessage(0);
     DeleteObject(hBmp);
     myOutputAnalogChannel(2,0);
     myCloseDevice();
     FreeLibrary(myDll);
     return 0;
   }
 }
 
 if(knob1.knobProc(hWnd,message,wParam,lParam))
 {
   InvalidateRect(hWnd,&r,FALSE);
 }

 return DefWindowProc(hWnd, message, wParam, lParam);
}

Hier das Source-Paket als RAR-Archiv:
http://katze.dead-men.de/upload/39_oszi_01b.rar

Ich habe eine kleine Test-Schaltung mit dem Operationsverstärker LM318 aufgebaut:


Die Ausgabe auf dem primitiven Oszilloskop sieht etwa so aus:


gruesse, die plapperkatz

zurück zur Kategorie "Tutorials"
[0 Kommentare]

Name


Kommentar




Bitte abtippen


 
(C) 2006-20012 Plapperkatze - 215314 Besucher seit dem 23.01.2012 Login