Re: C++/TCL Need Solution to Compile Error c2784
- From: David Gravereaux <davygrvy@xxxxxxxxx>
- Date: Thu, 12 Apr 2007 09:55:54 -0700
JesusChuyCampos@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?"
Attachment:
signature.asc
Description: OpenPGP digital signature
- Follow-Ups:
- Re: C++/TCL Need Solution to Compile Error c2784
- From: JesusChuyCampos
- Re: C++/TCL Need Solution to Compile Error c2784
- References:
- C++/TCL Need Solution to Compile Error c2784
- From: JesusChuyCampos
- C++/TCL Need Solution to Compile Error c2784
- Prev by Date: Re: URGENT: Command argument parsing
- Next by Date: Re: array of lists
- 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
|