LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get a response messege from rs-232 controler??

I have a temperature controller that has a serial communication rs-232,the company of it provide all the necessary docs

Of the communication protocol of the controller.  When I sending a command  I am receiving a response command .

How can I see this response command ?

 

0 Kudos
Message 1 of 10
(4,573 Views)

Hello Sagielka,

What exactly is your problem? You do not know how to check when data is received? You do not know how to get the data from the serial port? Or you do not know how to display the received data in your User Interface?

 

0 Kudos
Message 2 of 10
(4,568 Views)

Hi Wim

when i'm transmit  data to the controller ,the controller shuold send a respolnse messege. here is the controller rs-232 protocol:

 

 

as far of writing to the device there is no problam. i just fill a 6 byte buffer and use comwrt().

i tried the comrd() but no luck there.

suggestions?

Thanks.

 

0 Kudos
Message 3 of 10
(4,553 Views)

Hello Sagielka,

The ComRd function should work fine. Are you sure that the device sends a response? If so, how long does it take for the device to respond? Is it possible to post a piece of your code? Maybe that could clear some things out...

0 Kudos
Message 4 of 10
(4,542 Views)
Do you pause between the read and write?
You can use GetInQLen() in a loop waiting for a non-zero return to delay.
Do you have a timeout on the read that is greater than zero? (use SetComTime)
Are you getting any bytes out?

0 Kudos
Message 5 of 10
(4,540 Views)
Hi.thx for the help
 
this is part of the code:
 
char Buffer[6]={0x01,0x04,0x10,0x00,0x00,0x01};
OpenComConfig (1, "", 9600, 0, 8, 1, 512, 512);
ComWrt (1, Buffer, 6);//command messege.working good
Delay(0.2);
ComRd(1,Buffer,6); // the respone messege (?)
 
i didn't configure time out for the port, you think is will solve anything?
 
 
0 Kudos
Message 6 of 10
(4,525 Views)

Oh and yes, when i'm using ComRd() i do get something,the Buffer is changed but

nothing understandble as should be.

0 Kudos
Message 7 of 10
(4,523 Views)
I would flush the buffer before the write so that it is clean for the read process.
I would configure a timeout of 2 seconds (at least for test purposes).
I would use a return value on your comRd and check to see what it is giving you.

These will help further diagnose the problem. It could very well be crud in the buffer that needed flushing.
0 Kudos
Message 8 of 10
(4,518 Views)

Thx.

it's working fine now but i have one more problam to solve. The ComRd() takes very long time,about 2sec and even more.

i set up timer that sould read data from 2 controllers. the data transmited in hex.

 here is a part of my code:

 

int CVICALLBACK Control_Timer (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 int statA=0,statB;
 unsigned char BufferA[20]={0},Read_BufferA[20]={0};
 unsigned char BufferB[20]={0},Read_BufferB[20]={0};
 char Temp[2];
 
 switch (event)
 {
  case EVENT_TIMER_TICK:
   
   
 
    BufferA[0]=Controller_A_PortNum;
    BufferA[1]=0x04;
    BufferA[2]=0x10;
    BufferA[3]=0x00;
    BufferA[4]=0x00;
    BufferA[5]=0x01;
   
    ComWrt (Controller_A_PortNum, BufferA, 6);
    
    DelayMili(50);
    
    ComRd (Controller_A_PortNum, Read_BufferA, 6);
    
    DelayMili(50);
    
    Temp[0]=Read_BufferA[4];
    Temp[1]=Read_BufferA[5];
    
    SV1=((Temp[0]<<8) | (Temp[1]));
    SetCtrlVal (panelHandle, PANEL_NUMERIC, SV1*0.1);
   
   
   
    
   break;
 }
 return 0;
}

 

 how can i improve the reading time?

0 Kudos
Message 9 of 10
(4,481 Views)

It would be an idea to read the return value from ComRd() - 2 seconds seems suspiciously similar to the timeout value suggested in a previous post so you should check the return value for errors. (-99 is the timeout code.)

JR

0 Kudos
Message 10 of 10
(4,476 Views)