I am creating a terminal like program that will be used send SCPI commands to a micro controller over USB using the USBTMC class...
So here's my problem:
1 2 3 4 5 6 7 8 9 10
char *BulkOUT = newchar[commandSize];
//Bunch of stuff to create the header
String ^ commandStr = gcnew String(BulkOUT, 0, commandSize);
if(this->serialPort->IsOpen)
this->serialPort->WriteLine(commandStr);
else
//report error
I created a command header that I will need to send out, and I saved that command header in a char array BulkOUT. To use the WriteLine function, I need to save the command header as a String^, so I used the String constructor. My problem is that I DO NOT get the correct string! Why? Well I noticed that it only copies up to BulkOUT[2] when the command header (for testing purposes) is 24 characters long! I realized it does this because BulkOUT[3] = 0x00 {for the USBTMC class spec, the fourth byte is reserved and must be 0x00}.
So my problem is that I cant copy my char array because I have multiple instances of 0x00 at different indexes (not just index 3)...so what should I do?? How can I create a String^ if my character array has some 0x00 values? Is there another way to send a command through the comport that does not require the writing variable to be String^??
Don't use C++ CLR. If you want to use .Net just use C#. It just goes so much against what C++ does, if you are going to use mostly .net anyway then save yourself the trouble.
Don't use C++ CLR. If you want to use .Net just use C#.
this is true most times but in cases where you have native modules that need to be executed as well as managed ones, then C# is not a good choice as it offers no such means to call native and managed code within the same process.
Thanks JLBorges, I used the second solution and got everything to work
I havent tried booradley60 solution, using the String constructor with ASCII encoding...but it sounds simple enough, maybe I'll try it at a different time
You can... Maybe not C++ but it can definitely call C functions.
my mistake you are correct - I only considered cases where you have native c++ libraries you need to call from your managed code and want as little rewriting or creating of c wrappers ...