CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

HOW TO SEND DATA IN RS232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
feitanx



Joined: 21 Mar 2010
Posts: 37

View user's profile Send private message Yahoo Messenger

HOW TO SEND DATA IN RS232
PostPosted: Tue Jun 01, 2010 7:11 am     Reply with quote

What should I use in sending data (NUMERICAL DATA) over RS232 PRINTF(), PUTS() or others? What is the appropriate? And how to put distinction on them like a frame so it wont be mixed.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Jun 01, 2010 8:42 am     Reply with quote

Do you want to send binary or ascii data to represent those numbers?

Binary is typically more compact - but not exactly human readable.

ASCII is great as it can be watched from a terminal program, but the receiver now has to parse strings that are numbers.

It depends on what you want.

To stuff these things out a port,

Any time you want to convert a number to be represented in a string, you'd use PRINTF.

But if you want to send a glob of binary data, you can use printf (with %c) or putc.

That's the quick version. If you want more intense examples, look over all the examples in the CCS examples directory... I'm also assuming from your question you have no books on the 'C' programming language. Consider going to the book store and getting one.. I have "The C Programming Language" from Kernighan and Ritchie -- ISBN 0-13-110362-8

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
feitanx



Joined: 21 Mar 2010
Posts: 37

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Jun 01, 2010 7:25 pm     Reply with quote

If I use any of these will it be decodable in VB? Will I be able to use the data in VB?

What I want to send is the result from the adc and I will use it in the VB for conversion and display. Which is correct and more easy way printf() or putc?

what are the ways to put a header on data so it will not be interchange with other data?
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Jun 01, 2010 8:30 pm     Reply with quote

feitanx wrote:
If I use any of these will it be decodable in VB? Will I be able to use the data in VB?


Don't know - I don't write in VB.

Now, I have, in the past written scripts to accept stuff in TCL, and that tends to lend to ASCII rather than binary data.

Quote:

What I want to send is the result from the adc and I will use it in the VB for conversion and display. Which is correct and more easy way printf() or putc?


Depends on how you structure your protocol.

If you go with ASCII, printf is probably nicer for you.
If you go binary, then putc or sprintf to a binary string would fit better.

Quote:

what are the ways to put a header on data so it will not be interchange with other data?


By preceding all packets with a known sequence of information that is possibly unlikely to occur elsewhere in the packet? Ultimately it's up to you.

Consider doing ASCII if speed isn't an issue since debugging is a lot easier as I mentioned before. CR/LF terminated fields are nice too if you want to work it that way.

Ultimately, you have to decide for yourself what you want to do.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
feitanx



Joined: 21 Mar 2010
Posts: 37

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Jun 01, 2010 9:21 pm     Reply with quote

Can you give me example on how to put a header with a known sequence? I have no idea to how to do this

What CR/LF?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group