View previous topic :: View next topic |
Author |
Message |
feitanx
Joined: 21 Mar 2010 Posts: 37
|
HOW TO SEND DATA IN RS232 |
Posted: Tue Jun 01, 2010 7:11 am |
|
|
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
|
|
Posted: Tue Jun 01, 2010 8:42 am |
|
|
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
|
|
Posted: Tue Jun 01, 2010 7:25 pm |
|
|
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
|
|
Posted: Tue Jun 01, 2010 8:30 pm |
|
|
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
|
|
Posted: Tue Jun 01, 2010 9:21 pm |
|
|
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? |
|
|
|