Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VC++ 488.2 CString and Send

Hello, thanks for all the information stored away here. It is a great help.

Now, my question, I am having a horrible time trying to get VC++ 6.0, CString, 488.2, and GPIB to all work together.

This works just fine:
Send(GPIB0,7,"*IDN?",5L,NLend);

But I want to be able to use dynamic strings, and the string I have is in the form of a CString.
Send(GPIB0,7,(LPCTSTR)msg,msg.GetLength(),NLend);

I have tried various modifications of the above code with no avail.

I get various error messages, all at compile time, but similar to this:
'Send' : cannot convert parameter 3 from 'class CString' to 'void *'

So if anybody can help me convert this CString into a usable format for Send, or Ibwrt for that matter, I would be very grea
tful.

Thanks in advance,

Paul
0 Kudos
Message 1 of 4
(3,709 Views)
The NI-488.2 Send command takes a "void *" instead of a char *. This is because NI-488.2 can send binary data. That is why you are getting the error code. The fix is to typecast it to a void * before calling send.

Send(GPIB0,7,(void *)((LPCTSTR)msg),msg.GetLength(),NLend);

I have kept your typecast on the message so that you convert the CString into a char *. I then convert the character pointer to a void pointer to make NI-488.2 happy.

Good luck.
Message 2 of 4
(3,709 Views)
Thank you... Works like a charm...

Any reading or books that you would suggest? I learned a PowerBasic at my job by the seat of my pants, but given the extra power and complications of C++, I have not been able to really figure C++ out yet. Casting and pointers are still pretty hazy. Especially (void *), a "void type"???

Thanks again,

Paul
0 Kudos
Message 3 of 4
(3,709 Views)
Trust me, it gets even more confusing. I did a C-style cast. There are four different types of C++ style casts
static_cast (variable)
reinterpret_cast (variable)
const_cast (variable)
dynamic_cast (variable)

There are a few good C and C++ books. I generally think that Schildt writes a very easy-to-read set of books. Not necessarily the most comprehensive, but for a good basic idea of programming in C or C++, he does a good job.

FYI. A void type is one that doesn't have any implicit type or size. For example, a char pointer takes up 1 byte per location. A double pointer takes up 8 bytes per location. A void type is not interpreted at all by the host. NI-488.2 uses void since they allow you to pass in a dou
ble pointer and they don't want to interpret the data bytes incorrectly. Normally, there would be some automatic typecasting (which is why ibwrt "*IDN?" works), but because you used the explicit typecast to get the data from the CString, the explicit typecast to void * was necessary.

For example, if you used the method GetBuffer on the msg object, you would only need to do:
Send(GPIB0,7,msg.GetBuffer (0),msg.GetLength(),NLend);

However, I am not an expert on the GetBuffer method and it looks like the use of it may not be like I want it. But, feel free to do some research on the method. It retrieves the buffer and returns the same LPTSTR, but because it is implicit, the compiler will automatically convert it to a void * for you.

Hope that I haven't confused you too much!
0 Kudos
Message 4 of 4
(3,709 Views)