serCread/ serCwrite examples

Hello. I am an EE student doing a summer project at my college. I’ll mention this now, I am a tremendously novice programmer, having only taken an entry-level C++ course.

At this point in my project, I am trying to find a way to take in data through a serial port. 3 bytes of data will be sent every second from the device I’m trying to read in data for. To my knowledge, there is nothing separating each byte. I’ve been looking at the forums, and going through the example code for a while now, and have made little progress.
For the curious, I am reading in from an OEM III Module from Nonin Medical Inc. The major setback so far is just being able to read in the data.

The sample I’ve been focusing on has been SIMPLE3WIRE. It looks to be best fitting for my purposes. The problem is that this deals specifically with CHAR data types, and I need to be able to read the bytes of data as their decimal values. After poking and prodding the other sample codes, this board, and the mighty internet, I haven’t gotten much useful done.

My first question, is there anywhere I have overlooked with a simple explanation/ usable sample for serCread and serCwrite?

My next question is more of a general how-to programming question. I have been looking online and haven’t made much progress here either. Is it possible to just keep reading in each byte as an ascii char and have some way to read each of its individual bits (ex. ‘a’=01100001). I tried reading up on pointers, and haven’t gotten far on that yet.

I don’t only want to do this project to fulfill graduation requirements, I do want to learn more about programming. It’s not my main focus in life, and I don’t have a lot of time to devote myself to it, but I would appreciate any help I can get.

Thanks!

Don’t know what you mean when you say you need to read the bytes of data as their decimal values…

You can use serCread to read your 3-byte packet, then check that you got a valid packet by confirming that bit 7 is set in the first byte. Assuming you have read the bytes into a buffer named buf, that looks something like this:
if (buf[0] & 0x80)
{
// Packet is valid - process it here
}
else
{
// Packet is invalid - discard it, report error, whatever
}

Similarly, to check for the SNSD, OOT, LPRF, MPRF, ARTF conditions, you mask with the appropriate flag value.

To get the full 9-bit heart rate value, you do something like this:
rate = (buf[0] & 0x03) << 7 | buf[1];

Thanks! I figured out that I can just do int = char, and get the data I need.

Also, thanks for the coding suggestions. When I first read your pose, I didn’t know bitwise operations even existed, and was quite confused. Now, I can’t imagine doing what I have done without them! The two devices communicate nicely now, and am starting to add other inputs and outputs to my project.