Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

send binary fomrat bytes to PC

Status
Not open for further replies.

userx51

Junior Member level 2
Joined
Apr 21, 2013
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,432
let say my uC code has a function:

Code C - [expand]
1
2
3
4
void sendbinaryBytes (unsigned char b[4])
{
  Serial.writeToPC(b[0],4);
}


using sendbinaryBytes function, how to send 1.764 to PC RS232?. also, in PC upon getting the binary bytes, how to display it as 1.764?. any examples..? you can modify the sendbinaryBytes function.:idea:
 
Last edited by a moderator:

It depends on what the 'Serial.writeToPC' function does and in what format the PC expects the bytes to be. All 'sendbinaryBytes' does is pass the parameters you give it to 'Serial.writeToPC', without knowing what the function does with the parameters it's impossible to advise.

Brian.
 

Serial data transmission need a framing. When sending ASCII data, you have e.g. CR/LF termination to indicate a data entity. In binary transmission, you need other kinds of delimiters, e.g. unique start of frame and end of frame symbols. Unfortunately they can't be easily distinguished from same data bytes, so you need e.g. to use escape sequences.

In other words, your question is falling short. Before you consider how to transmit a single float value, you need to know how the transmission start can be uniquely marked.

A very simple scheme to transmit only a single number can be an interframe delay. Guarantee that before and after the 4 binary characters nothing is transmitted for e.g. 10 or 100 ms.
 

PC expects the data in binary format. sendbinaryBytes, sends the bytes in binary format. sendbinaryBytes sends four binary bytes and PC gets 4 binary bytes.
 

So what is the question? Presumably your floating point number is already 4 bytes long and binary, all you have to do is send them.

If you are asking how to split the floating point number into individual bytes, try declaring a union holding the floating point variable and four unsigned char variables. If you put a value in the floating point variable, because it shares addresses with the unsigned chars, each will hold one byte of its value.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top