LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Programming for Paralel Port in CVI

Hi,
 
   I would like to simulate the SPI interface through my PC's parallel port. For that I need to generate a CLK freq.
   How do I use Lab Windows CVI functions to talk to my PC's Parallel port. I also need to syncronize the data out put to the
other end of SPI slave.
 
Regards
-Patil
0 Kudos
Message 1 of 6
(5,828 Views)
Hi Patil,
 
You can use the "outp" function together with the parallel port address which you can find from the Device Manager.
It is 0x378 most of the time.
The output pins are from 2(lsb) to 9(msb).
For example, if you call "outp (addr, 0x81);" 2nd and 9th pins will output 5V, others will be 0V.
Hope this helps.
S. Eren BALCI
IMESTEK
Message 2 of 6
(5,816 Views)
just  a   simple sample.Smiley Happy
//----------------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------------
#include <windows.h>
#include <ansi_c.h>
#include <utility.h>
#include <userint.h>
#include <cvirte.h>  
#include "CVI_Read_Write_LPT_Port.h"
static int panelHandle;

int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */
 if ((panelHandle = LoadPanel (0, "CVI_Read_Write_LPT_Port.uir", PANEL)) < 0)
  return -1;
 DisplayPanel (panelHandle);
 RunUserInterface ();
 DiscardPanel (panelHandle);
 return 0;
}
int CVICALLBACK COMMAND1 (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 int portNumber = 0x378;
 char byteRead;
 int loaded;
 char byteWritten;
 char byteToWrite[20];
 switch (event)
  {
  case EVENT_COMMIT:
 
   // Check whether the LabWindows/CVI low-level support
   // driver was loaded at startup.
   loaded = CVILowLevelSupportDriverLoaded ();
   
   // Read the port address
   GetCtrlVal (panel, PANEL_PORTADDR, &portNumber);
   
   // Write to the parallel port
   GetCtrlVal (panel, PANEL_BYTEWRITE, byteToWrite);
   byteWritten = outp(portNumber, byteToWrite[0]);
   
   // Read from the parallel port
   byteRead = inp (portNumber);
   SetCtrlVal (panel, PANEL_BYTEREAD, byteRead);
   
   break;
  }
 return 0;
}
//----------------------------------------------------------------------------
// Quit
//----------------------------------------------------------------------------
int CVICALLBACK Quit (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event) {
        case EVENT_COMMIT:
            QuitUserInterface (0);
            break;
    }
    return 0;
}
Sonic

Diffrent Strokes for Different Folks
Message 3 of 6
(5,771 Views)

Thank You So much. Eren BALCI


I could get it at the first intance only.

But is there a way to get a transmision rate above 2 MHz?

 

Best Regards

-Patil

0 Kudos
Message 4 of 6
(5,738 Views)
Thanks so much for the greate program.
0 Kudos
Message 5 of 6
(5,736 Views)

Hi Patil,

2 MHz is impossible to achieve. That makes the period 0.5 usec.
I do not think Windows will switch the parallel port bits between 0 and 1 so quickly, and there are also hardware limitations.

However, it would be best to give it a try. Connect a scope to one of the output pins of your parallel port and flip this bit to 0 and 1 continiously in a loop.
Make sure that there is no unncessary code lines in the loop so it is very fast. No user interface, no printf's, nothing but the loop.
It would be fastest with assembly codes but I do not know how to do that.
Run the program, and measure the square wave frequency on the scope. Do not forget to make it a finite loop..
My guess is you'll get something between 100-200 kHz.

Note that the speed of your code's execution will depend on other processes running on Windows or whatever your OS is.
If 2 MHz is critical, you should use a high-speed DIO board which is driven by its own hardware, not Windows.

Hope this helps.

S. Eren BALCI
IMESTEK
0 Kudos
Message 6 of 6
(5,725 Views)