Jump to content

Serial data manipulation


terence

Recommended Posts

Hi guys,

I've got a VI that currently hooks up to a microcontroller that sends data to my labview program via serial. right now the serial and sending data bit works fine. the problem is with the accelerometer that is hooked up to my micro. basically the accelerometer sends in 12 bits. so i've made my microcontroller send the 12 bits in two 8 bit messages. so i send 16 bits and then a termination character (line feed) to labview.

the manipulation that i'm trying to do is to detect the first 8 bits after detecting the line feed. shifting the first byte left by 4bits. then shift the next byte right by 4 bits. then add these two bytes together to get my original 12 bits from the accelerometer.

i think i've done the manipulation correctly. i just can't figure out a way to distinguish the 1st 8 bits from the next 8 bits. i've attached the file. any help is appreciated!

Download File:post-4458-1145863834.vi

Link to comment

Terence,

I noticed that your VI has the "enable termination character" set to false on your configure step. I would suggest setting this to true so you do not timeout when reading the data on the serial port. Then when you do a read you will only get the data from the start of the buffer up to the first termination characther (0x0A). Otherwise you could get all the data at the serial port by connecting the "bytes at port" output to the byte count of the serial read and process the whole string. In this case the line feed will be part of the return string.

Next, I would convert the whole string to a byte array for easier manipulation. Use the string "String To Byte Array". Now you will have an array of bytes to work with instead of a string. After that there are a couple of vi that you can use to join integers togeater to create larger ones. Under numeric->data manuniplation there are two vi's join number and split number. Index the byte array to get your upper byte and lower byte and use the join number to get a 16 bit word containing your 12 bit conversion. (You can also use a type cast too.) Optionaly use an AND operation with a hex byte value of 0x0F to clear any incorrect data in the upper nibble of the byte that contains only 4 bits of the conversion data.

Check the attached VI for the changes...

Hi guys,

I've got a VI that currently hooks up to a microcontroller that sends data to my labview program via serial. right now the serial and sending data bit works fine. the problem is with the accelerometer that is hooked up to my micro. basically the accelerometer sends in 12 bits. so i've made my microcontroller send the 12 bits in two 8 bit messages. so i send 16 bits and then a termination character (line feed) to labview.

the manipulation that i'm trying to do is to detect the first 8 bits after detecting the line feed. shifting the first byte left by 4bits. then shift the next byte right by 4 bits. then add these two bytes together to get my original 12 bits from the accelerometer.

i think i've done the manipulation correctly. i just can't figure out a way to distinguish the 1st 8 bits from the next 8 bits. i've attached the file. any help is appreciated!

Download File:post-4832-1145886556.vi

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.