From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Instrument issue in C++ builder! Help!

Recently, I tried to do a project about RS485. My software development tool was C++ builder. And I met one problem. That was I received the return data as byte array. But I don't know how to transfer the CWSerial->Read() data to a right format. I can not see the right data. I don't know whether someone had ever done the project by C++ builder. Hope you can give me a big hand! If there was an example, that would be better. Thank you very much!
0 Kudos
Message 1 of 3
(2,766 Views)
Terry, this looks identical to the question you posted here. Have you tried setting the DataAsString property on the CWserial object to false? From the MeasurementStudio documentation, "If this property is True, data is returned as a string. If this property is False, data is returned as an array of bytes. The default value is True."
0 Kudos
Message 2 of 3
(2,751 Views)
Thank you! I have settled the problem.
I'd like to share my experience to all.
If you wanna send the binary data, you send directly.
Example, send ASCII "A", the binary data was 65. Then I can program
int b;
b=65;
CWSerial1->Write(b);
If you wanna send more, I use the fool method.
int b,c,d;
b=65;
c=89;
d=255;
CWSerial1->Write(b);
CWSerial1->write(c);
CWSerial1->write(255);
If you wanna receive the data as binary. We need to use two method of Variant.
Variant receive;
unsigned int buff[4];
int count;
int i;
receive=CWSerial->Read();
count=receive.arrayHighBound(1);
for(i=0;i<=count;i++)
{
buff[i]=receive.GetElement(i);
}

Then you can see the return data in buff[4] array. This is my experience, I hope I can help other people in the future.

Regards!
Terry
0 Kudos
Message 3 of 3
(2,739 Views)