LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-06-2010, 05:13 AM   #1
eryn
Member
 
Registered: Jul 2009
Posts: 43

Rep: Reputation: 15
Function successfully called but it did not run device properly


Good Day everyone,

I am stucked again with my project.

I have our own C written program code which is communicating with a third party C++ written program code to run a moving device.

We have successfully communicated with the third party code with wrapper functions. (Thanks to member in LQ that helped me solved this.)

Now, we tried to run some functions to move the device. I think it is better for me to attach the related code first.

pro.c (The source code we used to run the device)
Code:
#include<stdio.h>
#include "wrapper.h"

int main ( )
{
        int pro=0;

        libInit();
        pro = PROconnectToDevice((char*) "192.168.1.87" );
        printf("\nDevice Connected, Return Code = %d\n", pro);

        pro = PROinitializeAndCalibrate ();
        printf("\nDevice Initialized and Calibrated, Return Code = %d\n",pro);

        pro = PROtakeTool(1);
        printf("\nDevice Take Tool, Return Code = %d\n", pro);

        PROdisconnectDevice ();
        printf("\nDevice Disconnected, Return Code = %d\n", pro);
 
        libClose();

        return pro;
}
wrapper.cpp (Source code needed to communicate between C and C++ code)
Code:
#include <iostream>
#include "ProjectApplication.h"
#include "wrapper.h"

ProjectApplication *w;

int libInit ( void )
{
        w = new ProjectApplication;
        return 0;
}

int PROinitializeAndCalibrate ( void )
{
        return w->initializeAndCalibrate();
}

int PROtakeTool ( unsigned int PROtool )
{
        unsigned int tool;
        tool = PROtool;

        return w->takeTool( tool );
}

int PROconnectToDevice( char* PROipAddr )
{
        char* ipAddr;
        ipAddr = PROipAddr;

        return w->connectToDevice( ipAddr );
}

void PROdisconnectDevice( void )
{
        return w->disconnectDevice();
}

void libClose ( void )
{
        delete w;
        return;
}
After debugging, we will run "./pro".

The device is successfully connected and moved according to the statement in "initializeAndCalibrate ()" and return no error. Then, it turns to "takeTool(1)". The function did called successfully, we also get a return value of 0 that means no error. But, the device not moving at all. The device then disconnect straight away and exiting the routine of "main()".

The execution of statement in routine "main()" pause a while after it call "initializeAndCalibrate ()" until the device finish the movement before it execute the next statement.

After that, no more. Other statements just run so fast and it exit the program with all the statements it executed returned no error.

We are confirmed that there is no problem with the hardware that is the device and the third party software as we test run it before using other test tool and it works well.

We have been finding around for all possible causes for this problem but we just can't get the right one.

Hoping there is someone that can give us some ideas.

Thank you very much.
 
Old 01-06-2010, 10:33 PM   #2
eryn
Member
 
Registered: Jul 2009
Posts: 43

Original Poster
Rep: Reputation: 15
Is there something wrong with our wrapper.cpp or the pro.c?

Looking forward for the reply... :X
 
Old 01-12-2010, 08:52 PM   #3
eryn
Member
 
Registered: Jul 2009
Posts: 43

Original Poster
Rep: Reputation: 15
I am wondering if I pass parameter wrongly that made the function did not read the value passed. The function just been called and did not carry out any task and return a value that indicate no error.
 
Old 01-12-2010, 10:31 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,541

Rep: Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878
I can't see anything wrong with your code (I guess nobody else did either since you got no response). Does it work without the wrapper, ie does the following code work?
Code:
#include <iostream>
#include "ProjectApplication.h"

int main()
{
    ProjectApplication *w = new ProjectApplication();
    char ipAddr[] = "192.168.1.87";
    
    w->initializeAndCalibrate();
    w->connectToDevice(ipAddr);
    w->takeTool(1);
    w->disconnectDevice();
    
    delete w;
    return 0;
}
 
Old 01-13-2010, 01:04 AM   #5
eryn
Member
 
Registered: Jul 2009
Posts: 43

Original Poster
Rep: Reputation: 15
This code is to be save as .cpp file? But I need to call using .c file.
 
Old 01-13-2010, 02:50 AM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
The code look fine. The advice from ntubski is sound, use it as an interim debugging solution. By removing the wrapper you eliminate one potential source of errors.

A possible reason for your problem is that whilst you function has returned the external device may not have finished the task and then you disconnect, meaning that it will not attempt to complete the task given. Check to see if there are any further methods that you could use to wait until the task has been completed.

Last edited by graemef; 01-13-2010 at 02:54 AM.
 
Old 01-14-2010, 03:52 AM   #7
eryn
Member
 
Registered: Jul 2009
Posts: 43

Original Poster
Rep: Reputation: 15
To graemef,

The program ought to be wait until the task finish before the function is exiting. The program is written by third party, we tried the program on its before integrate into ours, it runs OK.

Also, another proof that it should not be a wait for process to stop problem is, the 'initializeAndCalibrate' function is doing just fine. This function is called, the device moved and until the movement is complete, the function exit with a return value.

However, the device is broken mechanically by now and no testing is able to carry out at this time.

I can only debug all the suggestion but not test it out on the device.
Anyway, I will try the suggestion when the device is ready for test.

Get back for the reply soon.

Thank you guys!
 
Old 05-17-2010, 03:22 AM   #8
eryn
Member
 
Registered: Jul 2009
Posts: 43

Original Poster
Rep: Reputation: 15
This problem is solved.
Anyone who would like to know the solution, you may refer to the following link.
http://www.linuxquestions.org/questi...c-code-807507/
 
  


Reply

Tags
c++, device, execute, function, moving, wrapper


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sleeping function called from invalid context kushneeraj Programming 8 04-16-2013 09:25 PM
Where is a PCI module's Probe function called? jbreaka4lyfe Linux - General 2 05-18-2010 04:07 AM
JavaScript function disappears after getting called for once mohtasham1983 Programming 1 01-15-2008 09:31 AM
segfault caused depending on how a function is called emge1 Programming 6 04-04-2007 04:48 PM
what is the kernel function called when a file is created viv_nan Linux - General 2 03-08-2007 07:09 AM


All times are GMT -5. The time now is 09:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration