LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Method of getting 2 values simultaneously using RS232C serial communication

Solved!
Go to solution

Hello,

 

I am new to NI/CVI LAB Windows. All I have to do is that :

 

Only I have to read 2 values simultaneously in 2 different numeric control panel using RS232C serial communication which is connected with sensors and after each equal interval of time I have to read this (suppose, I pressed start button and data come into numeric control panel then I will press stop button and note down the values then again press start button and next value will come on panels).

 

Can you please suggest me steps for this process.

 

ANY HELP WILL BE APPRECIATED

 

 

 

THANK YOU

0 Kudos
Message 1 of 47
(6,126 Views)

Suggested steps could be to

 

1) work through the 'Getting Started" manual which explains the basic concepts of CVI; it can be found here

2) use the example finder to study example projects dealing with a) UI operation and b) serial communication

0 Kudos
Message 2 of 47
(6,120 Views)

Thanks for your reply.

It will be convenient  for me if u will tell steps of process like..first configure the port  etc..

0 Kudos
Message 3 of 47
(6,106 Views)

if you would like to have equal time differences you should consider using a timer, either UI or asynchronous. In both cases suitable sample programs exist which you should use to get the idea...

 

On the other hand you mentioned that you would like to use a start and stop button.

 

So a scenario could be:

 

After pressing the start button, set up and open the serial port(s),start the timer, and in the timer callback read the serial port and display the values on your UI.

The stop button would stop the timer and close the ports.

Message 4 of 47
(6,097 Views)

hey,

 

well I am going through your method but I am still confuse how can I take 2 different value on 2 different numeric panel at the same time. should I use two different timer ??

0 Kudos
Message 5 of 47
(6,004 Views)

In your timer callback simply call

 

    if ( event == EVENT_TIMER_TICK )
    {

        GetCtrlVal ( panel_1, control_1, value_1 );       

        GetCtrlVal ( panel_2, control_2, value_2 );
    }

 

This is not 'at the same time' but usually close enough.

0 Kudos
Message 6 of 47
(5,997 Views)

I may be a bit lost on this but... where does serial communication come into this?

 

You may want to:

a. read 2 values on 2 different sensors connected via RS232c and display on screen, or

b. read 2 values from screen and... what? Send through rs232c? Or what?

 

Supposing you are in case a above, then you must decide what "simultaneously" means for you, in relation with sensor speed in communicating values over the serial channel. If you are using one serial channel only, then the best you can achieve is that measures are as close as the fastest sensor will give measurements back to you; we cannot judge if this is enough or not, only you can argue on this.

To get better than this you must use one separate RS232 channel per sensor and spend some time in trimming the system for the best (and most reproducible) performance.

Once you have the measurement in memory, displaying is a trivial task and does not affect measurement contemporarity.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 47
(5,986 Views)

hey,

 Actually sensor displays two value(torque,r.pm) and from sensor I am using single RS232 cable to take data into my laptop or you can say NI/CVI software. So, I have to measure  two different values(torque,r.p.m) on  two different numeric panel and moreover I want data in a real time means when I press start button value will be display frequently on 2 numeric panels and graph will plot according to data.

 

I am attaching my code I think that will help you much better to understand my problem. 

 

 

#include <utility.h>
#include <rs232.h>
#include <cvirte.h>  
#include <userint.h>
#include "new.h"
#include<formatio.h>
#include<string.h>

 

 

int panel_Handle,
    config_handle,
    comport,
    baudrate,
    portindex,
    parity,
    databits,
    stopbits,
    xmode,
    ctsmode,
    RS232Error,
    config_flag,
    port_open,
    com_status,
    read_term_index,
    read_term;
short read_cnt;
double timeout;
char devicename[30];
     read_data[30];

 

 

 

void SetConfigParms(void);
void GetConfigParms(void);

static int panelHandle;

int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; 
 if ((panelHandle = LoadPanel (0, "new.uir", PANEL)) < 0)
  return -1;
 DisplayPanel (panelHandle);
 RunUserInterface ();
 DiscardPanel (panelHandle);
 return 0;
}

void SetConfigParms (void)
{
    SetCtrlVal (config_handle, CONFIGURE_COMPORT, comport);
    SetCtrlVal (config_handle, CONFIGURE_BAUDRATE, baudrate);
    SetCtrlVal (config_handle, CONFIGURE_PARITY, parity);
    SetCtrlVal (config_handle, CONFIGURE_DATABITS, databits);
    SetCtrlVal (config_handle, CONFIGURE_STOPBITS, stopbits);
    SetCtrlVal (config_handle, CONFIGURE_CTSMODE, ctsmode);
    SetCtrlVal (config_handle, CONFIGURE_XMODE, xmode);
    SetCtrlVal (config_handle, CONFIGURE_TIMEOUT, timeout);
    SetCtrlIndex (config_handle, CONFIGURE_COMPORT, portindex);
}

void GetConfigParms (void)
{
    GetCtrlVal (config_handle, CONFIGURE_COMPORT, &comport);
    GetCtrlVal (config_handle, CONFIGURE_BAUDRATE, &baudrate);
    GetCtrlVal (config_handle, CONFIGURE_PARITY, &parity);
    GetCtrlVal (config_handle, CONFIGURE_DATABITS, &databits);
    GetCtrlVal (config_handle, CONFIGURE_STOPBITS, &stopbits);
    GetCtrlVal (config_handle, CONFIGURE_CTSMODE, &ctsmode);
    GetCtrlVal (config_handle, CONFIGURE_XMODE, &xmode);
    GetCtrlVal (config_handle, CONFIGURE_TIMEOUT, &timeout);
    GetCtrlIndex (config_handle, CONFIGURE_COMPORT, &portindex);
    #ifdef _NI_unix_
        devicename[0]=0;
    #else
        GetLabelFromIndex (config_handle, CONFIGURE_COMPORT, portindex,
                       devicename);
    #endif                  
}

int CVICALLBACK CONFIGURATIONPANEL (int panel, int event, void *callbackData,
  int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_GOT_FOCUS:

   break;
  case EVENT_LOST_FOCUS:

   break;
  case EVENT_CLOSE:

   break;
  }
 return 0;
}

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;
}

int CVICALLBACK LED (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:

   break;
  }
 return 0;
}

int CVICALLBACK TORQUE (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:

   break;
  }
 return 0;
}

int CVICALLBACK RPM (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:

   break;
  }
 return 0;
}

int CVICALLBACK TIMER (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{  double TORQUE;
  double RPM;
     double value;
 switch (event)
  {
  case EVENT_TIMER_TICK:
  
  GetCtrlVal(panelHandle,PANEL_TIME,&value);
  SetCtrlVal(panelHandle,PANEL_TIME,value+1);
  {
  
    GetCtrlVal(panelHandle,PANEL_TORQUE,&TORQUE);
    GetCtrlVal(panelHandle,PANEL_RPM,&RPM);
    PlotStripChart(panelHandle,PANEL_TORQUEGRAPH,&TORQUE,1,0,0,VAL_DOUBLE);
    PlotStripChart(panelHandle,PANEL_RPMGRAPH,&RPM,1,0,0,VAL_DOUBLE);
  
   }

   break;
  }
 return 0;
}

int CVICALLBACK CONFIGURATION (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:
  
  config_handle = LoadPanel(panelHandle,"new.uir",CONFIGURE);
  InstallPopup (config_handle);
  
  if(config_flag)
     SetConfigParms();
  else
      config_flag=1;

   break;
  }
 return 0;
}

int CVICALLBACK START (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:
  read_data[0]='0';
  SetCtrlAttribute(panelHandle,PANEL_TIMER,ATTR_ENABLED,1);
  SetCtrlVal(panelHandle,PANEL_LED,1);
  
  

   break;
  }
 return 0;
}

int CVICALLBACK STOP (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:
  SetCtrlAttribute(panelHandle,PANEL_TIMER,ATTR_ENABLED,0);
  SetCtrlVal(panelHandle,PANEL_LED,0);

   break;
  }
 return 0;
}

int CVICALLBACK RESET (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{  double value;
 switch (event)
  {
  case EVENT_COMMIT:
  
  GetCtrlVal(panelHandle,PANEL_TIMER,&value);
  ResetTimer(panelHandle,PANEL_TIMER);

   break;
  }
 return 0;
}

int CVICALLBACK CLOSE (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:
  
  port_open=0;
  GetConfigParms();
  DiscardPanel(config_handle);
  break;
  
   }
    return(0);
}


   
  
 


int CVICALLBACK TIME (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:

   break;
  }
 return 0;
}

int CVICALLBACK TORQUEGRAPH (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:

   break;
  }
 return 0;
}

int CVICALLBACK RPMGRAPH (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:

   break;
  }
 return 0;
}

0 Kudos
Message 8 of 47
(5,972 Views)

Unfortunately the code has little utility, it's an empty framework that really does nothing, you didn't even open the serial port!

 

It's difficult to try helping you at this stage, I'd suggest you to revise the project and design a conceptual framework to populate step by step with tested code.

 

The framework should at least include those tasks:

1. Open and close the com port with parameters read from screen

2. Read from sensors and get values in memory

3. Display values on numeric indicators on screen

4. Graph values

 

As far as I can tell from my experience, the serial communications is the hardest part, the first you should work on: you can  start by looking at shipping examples on serial communications and try developing your own code customized to actual sensors yo are using.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 9 of 47
(5,959 Views)

Thanks for your help.I will follow basic steps as suggested by you.

I still have a doubt in a serial communication example

When I am checking serial example - how to use the RS232 Library to send and receive commands to and from a device via a serial port. I have a problem:- 

Using my RS232 cable when I try to read signal I only get intial values of sensor means suppose before debugging project sensor showing 2 values(S1,NT,+000.000 & S2,NT,+000.002) then after debugging project I am getting this values in the read text box ..but my sensor is still running showing many different values but they are not showing by read box whenever I press read button only intial values are showing..not real time values by read text box.

0 Kudos
Message 10 of 47
(5,943 Views)