LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

"RS-232 Loop Back"

This is the code that I created. and I don't get the out put or got some characters.How can I fix it.
#include
#include
#include
#include
#include
#include
#include "Loopback.h"
static int data;
static int Length;

static int panelHandle;
void CVICALLBACK Read (int portNo,int eventMask,void *callbackData);

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "Loopback.uir", PANEL)) < 0)
return -1;

OpenComConfig (1, "", 9600, 0, 8, 1, 512, 512);

// Turn off Hardware handshaking (loopback test will not function with it on)
SetCTSMode (1, LWRS_HWHANDSHAKE_OFF);


// Make sure Serial buffers are empty
FlushInQ (1);
FlushOutQ (1);


DisplayPanel (panelHandle);
RunUserInterface ();

return 0;
}

int CVICALLBACK SendData (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{

char data[20];
char readBuf[20];
int err=0 ;

switch (event)
{
case EVENT_COMMIT:


GetCtrlVal (panelHandle, PANEL_STRING, data);

Length = StringLength (data);


ComWrt (1, data, Length);
Delay (1.0);
ComRd (1, readBuf, Length);


// Remove the carriage return and display the string.
readBuf[Length]=0;
SetCtrlVal (panelHandle, PANEL_STRING_2, readBuf);
SetActiveCtrl (panelHandle, PANEL_STRING);

break;
case EVENT_LEFT_CLICK:

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;
case EVENT_LEFT_CLICK:

break;
}
return 0;
}
0 Kudos
Message 1 of 4
(3,457 Views)
Please see attached sample program from our example program database and it's help.bmp for more informations.

Regards,
Heinrich Illig
National Instruments
0 Kudos
Message 2 of 4
(3,457 Views)
I went with this program.I placed a brake point at comRd() in callonme function and doesn't get there.Did you try this program yourself? Also,I call comRd() function after comWrt(),I got some characters. Please,verify these results.
regards
Jey11
0 Kudos
Message 3 of 4
(3,457 Views)
Yes, I tried out this program on my computer running CVI 6.0 and Windows XP Professional and it works fine. Do you have a loop back connector at your serial port which connects Pin 2 with Pin3 (transmit connected with receive line)? If yes, please try out to send and receive some bytes by using the CVI function panels (interactive execution). Here an example which worked fine on my computer as well:

_tmp1 = OpenComConfig (1, "", 14400, 0, 7, 1, 512, 512);
_tmp2 = ComWrt (1, "Test", 4);
_tmp3 = ComRd (1, buffer, 4);
_tmp4 = CloseCom (1);

If this doesn't work, please check if you are getting back any errors and if not, please try an other COM port.

Regards,
Heinrich Illig
National Instruments
0 Kudos
Message 4 of 4
(3,457 Views)