LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert from int To String

I really need help on this i have been trying all morning. IM trying grab the value from the temp and send it to my gui , I can't seem to get it to work.

 

and yes i am debugging it. in c++ plus i and do itoa, you can do that in c for some reason. or you can do IntToStr. in CVI im tried everything i know.

 

Im setting the temp from my gui and what ever that value is , im trying to somehow get to the send_data thats in the ComWrt. I cant get it to work.

 

Im going to post the project.check the aattachment also

 

***********************************

 

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

int temp=0;
char send_data[100]={0};
char msg1[80]={"hello"};

        
    switch (event)
    {
        case EVENT_COMMIT:
            
          
               bytes_sent = OpenComConfig (1, "COM4", baudrate, parity, databits, stopbits, inputq, outputq);


               GetCtrlVal (chiller,CHILLER_TEMP_SET,&temp);

               SetCtrlVal(chiller,CHILLER_TEMP_SET,temp);
               
               
                        

               bytes_sent=ComWrt(1,send_data,5);
               
            
                
            break;
    }
    return 0;    

}

0 Kudos
Message 1 of 12
(5,599 Views)

darnell,

 

Try this:

 

___________________________________

 

...

 

SetCtrlVal(chiller,CHILLER_TEMP_SET,temp);

 

sprintf(send_data, "%5d", temp)

 

bytes_sent=ComWrt(1,send_data,5);

 

...

___________________________________

 

You can tweak the way "temp" is represented by changing "sprintf" format string.

Hope this helps.

 

0 Kudos
Message 2 of 12
(5,573 Views)

yea it works, i finally got it to work last nite, it took me about two hours. I dont know why i didnt think about sprint in the first place. but yeah i found that out for myself last nite. i was so mad. I couldnt believe myself. lololololololol

 

can you give me some advice on some explanation on what the time monitor does. basically i have on my gui a  monitor actual time. so do it suppose to monitor the temp on the machine, or the set point that i set it on my gui. im trying to figure this out. im trying to put the logic together now.

 


int CVICALLBACK temp_monitor (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
//int temp_setting;   
    switch (event)
    {
        case EVENT_GOT_FOCUS://check on this for viability
           

        //    ComRd (1, read_data, read_cnt);//RS232 CMD;
                         

        //    GetCtrlVal(chiller,CHILLER_TEMP_MON,&temp_setting);
           
           
            break;
    }
    return 0;   

}

 

 

 

0 Kudos
Message 3 of 12
(5,555 Views)

Darnell:

 

CVI ships with a timer example.  Looking at it will give you a good idea on how timers work.

 

Generally, the event you're looking for on a timer is EVENT_TIMER_TICK.  A timer is not a visible control when the program is running, so EVENT_GOT_FOCUS is not a useful event to try to trap for a timer.  The idea for your program is to periodically read the temperature from the machine using ComRd, and display it as the Actual Temperature on your UIR.  Control how often you read the temperature using the Interval property of your timer control.  If you double-click on the timer on your UIR in the UIR editor, you can change the Interval.

 

The timer has nothing to do with the temperature set point control on your UIR.  Don't read from the control in your timer callback, read from the chiller.  Read from the temperature set point control on EVENT_COMMIT in the callback for the set point control.

 

Now to reply to your initial question in this thread on itoa:

 

Before you post a new message, try searching this forum for a previous question on the same topic.  There is a wealth of information already here (including previous questions on itoa). 

 

When you're on this forum, there is a search box just below the LabWindows/CVI header, just to the left of a button labeled GO.   The search box at the top of the window searches all of NI by default; the search box under the LabWindows/CVI header searches only the LabWindows forum by default.

 

If you had searched this forum for itoa, you would have found a couple of previous messages on the same topic.  You would have found an answer much quicker than "trying all morning" before posting a question that has already been answered.  You may feel like you're breaking new ground and at a dead end because "I tried everything I know", but you're not.  You're not the first person that came to CVI from c++, and you're not the first person that needs to learn what other resources you have available before posting questions to this board.

 

Regarding the code you pasted into your first message, why do you SetCtrlVal of the same value you just read from the same control?

      GetCtrlVal (chiller,CHILLER_TEMP_SET,&temp);

      SetCtrlVal(chiller,CHILLER_TEMP_SET,temp);     // this statement doesn't do anything.  The temp value is already in the TEMP_SET control: you just read it.

 

Here are some etiquette suggestions for your use of the forum.

1. Search the forum before you post a question.  There are years worth of questions and answers here.

2. Get a good C reference book and use it.  My books are well worn and have multiple book marks in them.  One of my replies to another of your posts listed some reference books I like, but there are a lot of good books out there.  http://forums.ni.com/ni/board/message?board.id=180&message.id=42486&query.id=915622#M42486

3. As I suggested before, don't post your .exe file, .cdb file, or your cvibuild directory.  Your post will be much smaller and you won't be cluttering up NI's servers and our PC's with unnecessary large files.  We typically need just the .prj, .c, .h, and .uir files.

4. Don't post your whole project just to ask a simple question (like on itoa).  We typically just need your project if we can't duplicate the problem you're having.

5. Tell us what you have already tried.  When you say "i tried everything i know", that doesn't tell us much.

6. Stay on topic in a thread.  Your previous posts seem to just continue to add new topics with each new reply.  itoa is a different topic than timers.  Start new threads for a new topic (after referring to items 1 and 2 in this list).

7. Let people know when their answer has solved your problem.  If you think they've gone the extra mile to solve your problem, give them a Kudo.

 

We're happy to help you with problems, but your goal should be to learn as much as you can, not to have someone else write your project for you.

 

Message 4 of 12
(5,549 Views)
cool. let me working on the timer problem now, I will be back
0 Kudos
Message 5 of 12
(5,545 Views)
so you saying on the gui if im using the event timer click : it will change the time periodically. i will see the number changing on my gui
0 Kudos
Message 6 of 12
(5,543 Views)

//so with this call back how is it going to be reading the data from the actual chiller.  do i got to call it some where us. I know you siad ComRd. so basically the read_data //variable is going to be reading the temperature from the device. 

 

int CVICALLBACK temp_monitor (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
//int temp_setting;   
    switch (event)
    {
        case EVENT_TIMER_TICK://check on this for viability
           

            ComRd (1, read_data, read_cnt);//RS232 CMD;
                         

            GetCtrlVal(chiller,CHILLER_TEMP_MON,&temp_setting);
           
           
            break;
    }
    return 0;   

}

0 Kudos
Message 7 of 12
(5,540 Views)
In your callback for the timer, check for EVENT_TIMER_TICK.  Whenever the timer ticks (as often as you want it to by setting the timer Interval), you need to read the temperature of the chiller using ComRd() then SetCtrlVal the Actual Temperature control.  You'll be reading a string from the chiller using ComRd().  If your Actual Temperature control is a string, you can use SetCtrlVal direrectly on the string returned by ComRd.  If your Actual Temperature is a numeric, you can use sscanf() to read the string into a numeric variable for use with SetCtrlVal().
0 Kudos
Message 8 of 12
(5,539 Views)

im having problems with the temp monitor. this is what i have. the actual is not changing

 

int CVICALLBACK temp_monitor (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
double temp;   
    switch (event)
    {
        case EVENT_TIMER_TICK://check on this for viability
           
            OpenComConfig (1, "COM4", baudrate, parity, databits, stopbits, inputq, outputq);


            GetCtrlVal(chiller,CHILLER_TIMER,&temp);

            

            GetCtrlVal(chiller,CHILLER_TEMP_MON,&temp);

            ComRd (1, read_data, read_cnt);//RS232 CMD;
                         

           
           
            break;
    }
    return 0;   

}
 

0 Kudos
Message 9 of 12
(5,524 Views)

the value on your GUI won't change until you use SetCtrlVal() to change it.

I presume the value you want to set it to is the value you read from the chiller via comRd.

0 Kudos
Message 10 of 12
(5,522 Views)