Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

problems with flex_read_port function

u8 boardID = boardID_Nr;     // Board Identification number
 i16 iStatus = 0;// Errocode 0= ok
  u16 csr = 0;    // Communication Status Register

 u8 port1=01;      // Port number   !!input!!!
 u8 port2=02;      // Port number   !!output!!!
 //u16 csr = 0;     // Communication Status Register
 u8 returnVector;     // include the x- x+ y- y+ Limits // !!negative logic
 u8  polarity;     // Polarity of the DIO  
 u8  bit = 255;      // Bit of the port !! value to write!!
 i32 scanVar;     // Scan variable to read in values not supported bu
 //         //  by the scanf function
 // //Variables for modal error handling
 u16 commandID;     // The commandID of the function
 u16 resourceID;     // The resource ID
 i32 errorCode = 0;
 BOOL runMethode = TRUE;
 BOOL ifzweig = FALSE;
 BOOL elsezweig = FALSE;
 u8 movingFree= 255;
 try
 {
  HWND m_hWnd=NULL;
  err = flex_set_port_pol(boardID,port1,255);// input
  err = flex_set_port_pol(boardID,port2,255);// output
  if (err!=0)
   throw "flex_set_port_pol";
  //CheckError;
  //
  // //Set the port2 direction
  err = flex_set_port_direction(boardID,port1,0x00FF); // input 
  if (err!=0)
   throw "flex_set_port_direction";
  err = flex_set_port_direction(boardID,port2,0); // output
  
  if (err!=0)
   throw "flex_set_port_direction";
 
  //Wait for move to complete on the axis AND
  //also check for modal errors at the same time.
  do{
   //TRACE("  maxDifference :   %i \n", maxDifference );
   //Read the current position of axis
  err = flex_read_port( boardID, port1,  returnVector); this function returned an error ! Wir benutzen eine 7344 PCI Karte und NI-Motionsoftware 6.1.2.Der flex_set_port Befehl arbeitet korrekt.
gibts bei NI ein Beispiel für das Lesen der DIO ports ?.MfG H.Bröker 
  if (err!=0)
   throw "flex_read_port";
  
  movingFree= 255;//-returnVector;
   Sleep(1);

   if (SolarMotionParameter->stop)
   {
    m_mutex.Lock();
    //// motors stop
    err = flex_set_port(boardID,port2,0x0F,0xF0,0xFF);
    m_mutex.Unlock();
    if (err!=0)
     throw "flex_set_port Motor stop";
   }
   else
   { 
    // motors can be moved
    m_mutex.Lock();
    err = flex_set_port(boardID,port2,0xF0,movingFree,0xFF);
    //err = flex_set_port(boardID,port2,0xF0,0x02,0xFF);
    
    m_mutex.Unlock();
    if (err!=0)
     throw "flex_set_port Motor move";
   }
 
   runMethode=!SolarMotionParameter->methodeStop;
 

  }
  while (runMethode); //Test against the move complete bit
  TRACE("runMethode = false");     
  m_mutex.Lock();
  //// motors stop
  err = flex_set_port(boardID,port2,0x0F,0xF0,0xFF);
  m_mutex.Unlock();
  if (err!=0)
   throw "flex_set_port Motor stop";
 }
 catch(char * str)
 {
  TRACE(" initialization: %d \n", str);
  MessageBox(m_hWnd,str,"error!",MB_OK);
 }
 //HWND m_hWnd=NULL;
 //MessageBox(m_hWnd,"methode zu ende" ,"error!",MB_OK);
 //SolarMotionParameter->error=TRUE;
 return;  // Exit the Application
 
 
0 Kudos
Message 1 of 3
(3,282 Views)

Hi

Have you already look at the NI Hompage for examles?

Maybe you can find some examples on this page:

http://zone.ni.com/devzone/devzone.nsf/webcategories/69771825AE23E98E86256786000BEA02

I hope that helps

Manuel

0 Kudos
Message 2 of 3
(3,269 Views)

hbroeker,

What error are you getting?  It looks like your variable "returnVector" is uninitialized.

Rodger S.

Message 3 of 3
(3,263 Views)