how to read this string

M

marco

hi,

i'm trying to get a board with relays working under c++, i have a sample
code in visual basic to compose a string that is send to the serial port
but i am confused how to translate it to a c++ string
here is the vb code:

messagestring = Chr$(13) & Chr$(address) & "S6" & Chr$(checksum)

where adress is an integer from 1 to 255 and checksum is also an integer

how does this string look like? can anyone help?

thanx

marco
 
V

Victor Bazarov

marco said:
i'm trying to get a board with relays working under c++, i have a sample
code in visual basic to compose a string that is send to the serial port
but i am confused how to translate it to a c++ string
here is the vb code:

messagestring = Chr$(13) & Chr$(address) & "S6" & Chr$(checksum)

where adress is an integer from 1 to 255 and checksum is also an integer

how does this string look like? can anyone help?

Try

std::eek:stringstream os;
os << '\r' << (unsigned char)address << "S6" << checksum;
std::string str_to_output(os.str());

and if you need the const char*, use

str_to_output.c_str()

HTH

Victor

P.S. AFAIK, Chr$(13) is the "carriage return", and that's why I used \r
in the output statement. It makes it a bit more portable, although you
could just as well use (char)13 .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top