473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

how to read this string

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
Jul 22 '05 #1
2 1385
marco wrote:
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::ostringstream 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 .
Jul 22 '05 #2
After some experimenting everything works, thanx

marco

Victor Bazarov wrote:
marco wrote:
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::ostringstream 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 .

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Jason Heyes | last post by:
Does this function need to call eof after the while-loop to be correct? bool read_file(std::string name, std::string &s) { std::ifstream in(name.c_str()); if (!in.is_open()) return false; ...
9
by: John Howard | last post by:
How can I read a text file that is on a UNIX server in VB.Net? Please keep it simple. Thanks, John
5
by: JenHu | last post by:
Hi experts, I wrote a function which retrieves a file in the folder, the file path is : Dim sr As New StreamReader(strFilepath & ReturnFileName) What if I have more than 1 file_name in...
3
by: Ray | last post by:
Hello World, I made a Windowsform that reads data from a CSV file. It works fine, but when I have read the data of a record I have to re-Debug the form to read another record. So when I put a...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
0
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the...
5
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a...
2
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Is there any way to Read an INIFile from a string or Stream instead of a physical file ??? I want to read the INIFile into a string then store in a db but when I read the string from the...
3
by: maneshborase | last post by:
Hi friends, I am facing one serious problem in my application. I am trying to open dicom image file (.dcm) has size around 400 MB. But I am getting and unhandy exceptions, Some time, ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.