From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

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
Well, have you actually opened the port before starting the timer? Remember that the default status of a timer at creation is to be enabled: you can set it as disabled in the UIR editor. After opening the port you can enable the timer. Do not forget to disable it again when you close the port.

Regarding the communication with the instrument, in the timer callback you must do the following:
- check that no error is found in ComRdTerm
- Check that a complete message has been received: if not, accumulate message in a static buffer and wait for the following read
- Scan initial portion of the string and check if it is S1 or S2
- Scan the rest of the screen extracting measured value (speed or torque)
- Display the value in the appropriate indicator


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 31 of 47
(2,952 Views)

hey,Thanks

Actually my timer was enabled so it was showing error.Now its showing value in text box proper .

As I send you image in earlier message that S1 is coming first and then S2.So, should I write specific sacn function to read that ??and I am not getting which datatype should use I am using double type.

currently I am using this:-

 

Scan(read_data,"%s[i6]>%f",&torque);
Scan(read_data,"%s[i6]>%f",&rpm);
 

because I want to ignore first 6 byte (S1,NT,)  & (S2,NT,)  but its not working display dosen't show any value (torque,r.p.m).

 

 

0 Kudos
Message 32 of 47
(2,942 Views)

hey, can you please reply me answer as soon as possible beacuse I am working on this project 5 days more Smiley Indifferent

0 Kudos
Message 33 of 47
(2,880 Views)

Why don't you use the time to learn about

 

  • the debugging options in CVI... for example, setting a breakpoint after the line with the scan command; this way you can find out if 'read_data' contains the values you expect, and also if your scan function is working as expected, i.e., if torque shows the correct value. If so, you know that reading your value is o.k. and you need to search why it is not displayed ...
  • the interactive execution window to quickly try different formatting options; for example, using  Scan("S1,NT,-003.003","%s[i6]>%f",&torque);  immediately shows that the scan function is working as expected... so obviously something is wrong either with your read_data or with your code displaying the value of torque.

 

In programming, try to 'cut' your problem into small pieces and solve one by one...

Message 34 of 47
(2,876 Views)
Solution
Accepted by topic author vishalnit93

Hi,

 

Here is the code I promised. A little late, because of my holiday.

In the zip file attached you will find a CVI project, a screenshot showing the program in action and an Arduino code I used to simulate the sensors. It generates random sensor values.

 

If you have an Arduino Uno compatible board you can upload the code in it and try the program even if you do not have the sensor with you. But this is completely OPTIONAL.

 

If the information you gave about the sensor output is accurate, I expect this code should work.

Open the CVI project and build it to create the executable.

 

Execute the program select the COM port number and hit "Start".

The 2 numeric displays should start displaying the values.

 

In the sample sensor output you have posted, the values were very small (around zero) so increase the actual RPM and torque in the system if possible. Otherwise the displays wil not move at all and you may think it is not working while it is working but only showing zero.

 

Hope this helps you solve your problem.

Regards,

S. Eren BALCI
IMESTEK
Message 35 of 47
(2,859 Views)

hey,

Many thanks for your help. Can you please tell me that the program you made I think is in new version of CVI but I am using version 6.0 can I change Run time engine from older version to new one??

If yes can you please tell me how??

0 Kudos
Message 36 of 47
(2,852 Views)

hey Wolfgang,

 

Can you please tell me that is it better to save file in excel format or some other beacause I dont know much about this...and tell me example referance to write this incoming data into excel or any format so that I can understand this.

 

Thanks

0 Kudos
Message 37 of 47
(2,835 Views)

Hehe... for this kind of question my preferred answer is: it depends... Smiley Wink

 

Personally I would save the data as a simple text file because this is the most general method and the data can easily be used (imported) by other programs.

 

So the sketch of my code would like like:

 

OpenFile ( ...)

 

for ( index = 0; index < number_of_data_points; index ++ )

{

FmtFile ( file_handle, "%f[e3p16]%s%f[e3p16]%s", x_data [ index ], ",", y_data [ index ], "\n" );

}

 

CloseFile ( ...);

 

Of course the formatting options are a matter of personal needs and taste: the precision, floating point..., delimiter (comma in my case);

 

instead of FmtFile you can also use fprintf (...);

 

Remember that you can conveniently test the different formatting options in the interactive execution window...

Message 38 of 47
(2,834 Views)
It is not about the run time version.
Your IDE is complaining probably because the UIRfile is prepared with a newer version.
I'll resave the file in 6.0 format and post it here.
S. Eren BALCI
IMESTEK
Message 39 of 47
(2,828 Views)

Here is the UIR file saved in 7.1 format.

This is the earliest version I can save.

 

When the warning message about the UIR version comes up, hit Continue.

Maybe the 6.0 version IDE can open a 7.1 UIR file.

 

I think it worths a try.

 

Note: Let us know if the project works or not

S. Eren BALCI
IMESTEK
Message 40 of 47
(2,811 Views)