Re: C++/TCL Need Solution to Compile Error c2784
- From: JesusChuyCampos@xxxxxxxxx
- Date: 13 Apr 2007 00:54:43 -0700
On Apr 12, 9:55 am, David Gravereaux <davyg...@xxxxxxxxx> wrote:
JesusChuyCam...@xxxxxxxxx wrote:
Any help is greatly appreciated.
Hi Jesus,
I can't hold back.. I must say my real thoughts..
Automation sux!
Be it CPPTCL or even SWIG, your interfaces never turn-out the way you really want
it. Don't put me in a box, please. Forget the c++ template error thing for the
moment.
Last weekend I wrote an interface library for a PC-controlled USB oscilloscope.
It has a whooping 82 function calls and took me 2 days to get it 70% done. But
the work was well worth it as I can specify all parameters for exactly how I want
the interface to be.
You do need to know how Tcl works on the inside but the learning curve isn't all
that steep. Once you have an extension framework, adding more commands for the
externals isn't that hard, and more than likely all the functions are somewhat
orthogonal so you end-up reusing error checking and param decoding code.
Spend the time to learn Tcl's C API and hack away at your extension without
fighting those helper tools. Just ask questions here, if you get a bit stuck on
some concepts like Tcl_Obj reference counting, or whatever.
Here's an example of one of the calls from the scope library I turned into a Tcl
command..
word SetSensitivity(byte byCh, double *dSens); /* from scope control dll */
becomes:
Tcl_ObjCmdProc SetSensitivityCmd;
__declspec(dllexport) int
Tpscope_Init (Tcl_Interp *interp)
{
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
....
# define MAKECMD(name) \
Tcl_CreateObjCommand(interp, STRINGIFY(JOIN(tiepie::,name)), \
JOIN(name,Cmd), 0L, 0L);
....
MAKECMD(SetSensitivity);
....
}
int
SetSensitivityCmd (ClientData clientData, Tcl_Interp *interp,
int objc, struct Tcl_Obj * CONST * objv)
{
word ok;
byte ch;
double sensitivity;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "channel sensitivity");
return TCL_ERROR;
}
if (GetChannelFromObj(interp, objv[1], &ch) != TCL_OK) {
return TCL_ERROR;
}
if (Tcl_GetDoubleFromObj(interp, objv[2], &sensitivity) != TCL_OK) {
return TCL_ERROR;
}
ok = SetSensitivity(ch, &sensitivity);
if (TiePieResultOK(interp, ok)) {
/* return actual */
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(sensitivity));
return TCL_OK;
}
return TCL_ERROR;
}
byte
GetChannelFromObj(Tcl_Interp *interp, Tcl_Obj *obj, byte *ch)
{
int channel;
*ch = 0;
if (Tcl_GetIntFromObj(interp, obj, &channel) != TCL_OK) {
return TCL_ERROR;
}
if (channel < 0 || channel > 4) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("channel out-of-range",-1));
return TCL_ERROR;
}
*ch = (byte)channel;
return TCL_OK;
}
int
TiePieResultOK (Tcl_Interp *interp, word result)
{
const char *msg, *eName;
switch (result) {
case E_NO_ERRORS:
return 1;
case E_NO_HARDWARE:
eName = "E_NO_HARDWARE";
msg = "Hardware is not connected";
break;
case E_NOT_INITIALISED:
eName = "E_NOT_INITIALISED";
msg = "Hardware is not initialized";
break;
case E_NOT_SUPPORTED:
eName = "E_NOT_SUPPORTED";
msg = "Feature is not supported in your hardware";
break;
case E_NO_GENERATOR:
eName = "E_NO_GENERATOR";
msg = "Hardware doesn't have an AWG";
break;
case E_INVALID_CHANNEL:
eName = "E_INVALID_CHANNEL";
msg = "Invalid channel";
break;
case E_INVALID_VALUE:
eName = "E_INVALID_VALUE";
msg = "Invalid input value";
break;
case (E_LAST<<1):
eName = "E_NO_SUCH_API";
msg = "API not found in DLL";
break;
default:
eName = "????";
msg = "Unknown error";
break;
}
if (interp) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
Tcl_SetErrorCode(interp, "TIEPIE", eName, msg, NULL);
}
return 0;
}
--
A voice crackles in Calvin's radio:
"Enemy fighters at two o'clock!"
"Roger. What should I do until then?"
signature.asc
1KDownload
hi David,
Like Hemut, I just want to thank you for your time. Wow 82 functions
that have to TCL friendly. Looking at your example and others I found
on the net, have scared me to take that approach, which is why BOOST/
CPPTCL and now even SWIG seem promising. I was given three weeks to
complete this task. The first week was choosing which Language I would
build the project on (TCL was selected) and since I needed a compiler
to create a TCL friendly DLL it took the rest of that week, due to non
Admin permissions on my PC. After trying to get the vendors example
code to compile, I spent most of the second week trying to get help
from the vendor. Doesn't help when they are three hours ahead and I
work a late 2nd shift. The vendor did fix their SDK, but couldn't help
me with CPPTCL since they are not familiar with it. After looking for
answers, I decided to post a question. It always sucks when the
simple "hello world" program works, but the real thing breaks. I' will
be looking into SWIG, because just like CPPTCL, if the SDK changes
rebuilding the DLL will be a breeze. But if worse comes to worse, I
guess I will have to learn the TCL C API like you mention and get it
done.
.
- Follow-Ups:
- Re: C++/TCL Need Solution to Compile Error c2784
- From: Christian Gollwitzer
- Re: C++/TCL Need Solution to Compile Error c2784
- References:
- C++/TCL Need Solution to Compile Error c2784
- From: JesusChuyCampos
- Re: C++/TCL Need Solution to Compile Error c2784
- From: David Gravereaux
- C++/TCL Need Solution to Compile Error c2784
- Prev by Date: Re: C++/TCL Need Solution to Compile Error c2784
- Next by Date: Re: Tcl_DeleteInterp() crashes my C++ program every single time (Tcl 8.4.13)
- Previous by thread: Re: C++/TCL Need Solution to Compile Error c2784
- Next by thread: Re: C++/TCL Need Solution to Compile Error c2784
- Index(es):
Relevant Pages
|