****SOLVED*****
***Look at EDIT 2! ********
For one, I didn't that CreateThread(...) existed...
But the main reason is that I'm programing on windows environment and I'm trying to debug the code on windows is because the host platform as no display, or Human to Machine interface.
The final code will run from an ARM platform called ARMus, that run a small linux derived OS. That platform control an FPGA that does the work input and output.
Look up on youtube ARMus Sherbrooke to see the platform, the video "Grande Course" is pretty demonstrative.
So the way it really work is: The librairy libarmus.h is responsible for all the communication between Armus platform and the FPGA... Read_Encoder(int) ask the FPGA to return the number of "ticks" from the encoder since the last call. That mean that each time Read_Encoder is called, the value is reset to zero. The program I making kept in memory the last MAX_MEMORY return value of Read_Encoder so that more than one part of the program may intake the value of the encoder. And thus a thread is needed to read the encoder...
I made a libarmus cpp file just so that I can get error report from other program than the appropriate IDE, where debugging is... not very useful...
The ARMus platform as "native" support for pthread, but I doubt i could support any other threading library, as it need to be compiled for ARM (7 by memory), but not native ARM as the program is run from the Linux.
I actually found how to fix the pthread_create(...)... I just had to put the thread 'th_encoder' static and a pointer...
So:
.h
static void* Encoder_Out::Th_encoder(void *);
.cpp
1 2 3 4
|
Encoder_Out::Th_encoder(void *traSh)
{
/Code here
}
|
The errors are related are indeed linking error, but even linking manually failed:
Link.bat
1 2 3 4 5 6 7
|
set compiler_path="C:\Program Files (x86)\CodeBlocks\MinGW\bin"
set obj_path=C:\Users\Layfon\Documents\Project-Cpp\encoder_out\obj\Debug
set compiller=mingw32-g++.exe
cd /d %compiler_path%
%compiller% -o %obj_path%\ecod_debug %obj_path%\encoder_class.o %obj_path%\libarmus2.o %obj_path%\main.o
pause
|
But trying to compile without pthread on VS2010 instead of Code::Block output these errors: I believe they might be more significant:
1>------ Build started: Project: encod, Configuration: Debug Win32 ------
1>Build started 19/10/2011 6:44:18 PM.
1>InitializeBuildStatus:
1> Touching "Debug\encod.unsuccessfulbuild".
1>ClCompile:
1> encoder_class.cpp
1> Generating Code...
1> Compiling...
1> main.cpp
1> Generating Code...
1>encoder_class.obj : error LNK2001: unresolved external symbol "private: static unsigned short (* Encoder_Out::m_encoder_val)[100]" (?m_encoder_val@Encoder_Out@@0PAY0GE@GA)
1>encoder_class.obj : error LNK2001: unresolved external symbol "private: static bool * Encoder_Out::m_act_encoder" (?m_act_encoder@Encoder_Out@@0PA_NA)
1>encoder_class.obj : error LNK2001: unresolved external symbol "private: static unsigned short Encoder_Out::m_counter" (?m_counter@Encoder_Out@@0GA)
1>C:\Users\Layfon\Desktop\VIP\encod\Debug\encod.exe : fatal error LNK1120: 3 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.31
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== |
Thank you Computergeek01 for you're help and you're time!
EDIT: Found how to make pthread_create work!
EDIT 2:
For some reason, I managed to get it to work... I still don't understant why it didn't work with thread commented, however, it looks like a static fonction can't see a class variables... So I passed the pointer to the class to my static fonction, and linked the fonction var call to the class.
Now it "works" well it compiles... But if I try to Encoder.Get_RIGHT_ENCODER(), than printing the output... it fails...
Do not work:
1 2 3 4 5 6 7 8 9 10
|
for (int i=0; i<100; i++) {
printf("L=%d,R=%d\n", enc_out[ENCODER_LEFT][i], enc_out[ENCODER_RIGHT][i]);
enc_out[ENCODER_LEFT][i] = Encoder.Get_LEFT_ENCODER();
enc_out[ENCODER_RIGHT][i] = Encoder.Get_RIGHT_ENCODER();
printf("L=%d,R=%d\n", enc_out[ENCODER_LEFT][i], enc_out[ENCODER_RIGHT][i]);
THREAD_MSleep(DELAY);
}
|
Works:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
for (int i=0; i<100; i++)
{
printf("L=%d,R=%d\n", enc_out[ENCODER_LEFT][i], enc_out[ENCODER_RIGHT][i]);
enc_out[ENCODER_LEFT][i] = Encoder.Get_LEFT_ENCODER();
enc_out[ENCODER_RIGHT][i] = Encoder.Get_RIGHT_ENCODER();
count[i]= Encoder.GetCounter();
THREAD_MSleep(DELAY);
}
for (int i=0; i<100; i++)
{
printf("L=%d,R=%d\n", enc_out[ENCODER_LEFT][i], enc_out[ENCODER_RIGHT][i]);
}
}
|
Also, enc_out[ENCODER_LEFT][i] always seem to keep the value 0, not the return of ENCODER_Read().
So, well, even though it compiles, it still doesn't work.
EDIT 3:
I identified the source of the problem:
(thptr->m_encoder_val[enc_num][(thptr->m_counter)])=ENCODER_Read(enc_num);
I can't seem to access de array...
If you could help me, I would be grateful!
*Also: removed cmd output now pretty useless, and it's was pretty much the same than last post...
EDIT 4: FOUND ALL OF MY ERRORS, YOUPPI!
Thanks for all the help!