LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trim a single bit from a byte?

Solved!
Go to solution

@crossrulz wrote:

@natasftw wrote:

@jpc335 wrote:

 

I was told by the manufacturer that the 3 bit hexadecimal string can then be converted into usable numbers.  So if its faster/easier to replace the first byte with a 0 or turn it into a 3 bit hex string.  Either will work.

 


You want to break yourself of this misuse of bit ASAP.  A bit is a single 1 or 0.  Hex requires 4 bits to find the values.  The purpose of hex is to reduce the number of bits you must write out so things are easier to read.


Now the OP has you doing it.  I'm sure you mean "characters".


I probably should have said "digits." 

0 Kudos
Message 11 of 28
(2,894 Views)

OK now I see how this works.  thank you.  Now how do i truncate the last byte?I tried FFF0 but that returns a zero for the last place.  I assume I still use little endian so the bytes are still flipped correct?

0 Kudos
Message 12 of 28
(2,885 Views)

Well the j1939 port was replaced with a deutsche connector so now I am going to try to use the CAN receive example from LabVIEW.  I was originally going to use Kvaser Light HS with Kvaser CanKing but thats not an option anymore (I think).  As you can tell Im very new to working with these systems.

0 Kudos
Message 13 of 28
(2,880 Views)

@jpc335 wrote:

Well the j1939 port was replaced with a deutsche connector so now I am going to try to use the CAN receive example from LabVIEW.  I was originally going to use Kvaser Light HS with Kvaser CanKing but thats not an option anymore (I think).  As you can tell Im very new to working with these systems.


Sorry, I have no idea what you're trying to say here. You need a card that allows you to plug the CAN network into your computer. CAN uses two wires, but as far as I know doesn't specify what physical connector to use, so I'm not sure what you mean about replacing the J1939 port with a deutsche connector. That should have no effect on which CAN card you use, although you might need an adapter to get the wires on the right connector and pins.

 

The CAN examples that ship with LabVIEW work only with specific CAN cards from National Instruments. If you don't have the right CAN card, then there's no reason to try the example that ships with LabVIEW. I believe Kvaser also supplies LabVIEW examples, if you decide to use their CAN card.

 

I've used both Kvaser and NI CAN cards in LabVIEW without problems.

0 Kudos
Message 14 of 28
(2,854 Views)
Solution
Accepted by topic author jpc335

@jpc335 wrote:

Now how do i truncate the last byte?I tried FFF0 but that returns a zero for the last place.


Use the Logical Shift function to move 4 bits to the right.

Spoiler
I have done way too many bit manipulations...


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 15 of 28
(2,833 Views)

Thank you for your help everyone! That part of my program is now functioning exactly how I intended. 

 

now I have some questions about the Kvaser LabVIEW  libraries.but I'm not sure if this is the correct place to ask them.  I've received CAN messages using their VI, however there are 7 CAN ID's on the system.  I am only concerned with one CAN ID's.  Does anyoine know how to filter the others out?

 

If not I will keep working at it or contact Kvaser.

 

Thanks again for the help!

0 Kudos
Message 16 of 28
(2,780 Views)

You can do it either in your code - if the can ID doesn't match, discard it - or you can use the canSetAcceptanceFilter function from the Kvaser library (sorry, I don't have the LabVIEW version available to see exactly how it's exposed there). If you're looking for one, specific, known ID, then you would set all bits in the mask to "1" and then set the code to the desired ID.

0 Kudos
Message 17 of 28
(2,774 Views)

How do I designate just the can ID though and not the full string?  I plan on integrating the VI's soon but am trying to get each one working independently.  Plus I cant test while trying new things due to the situation.  I cannot find that function in the KV libraries but I will keep looking.  I am using their example code and am trying to just add a constant to compare then discard the rest.

 

Thank you for the help!

0 Kudos
Message 18 of 28
(2,767 Views)

Sorry, no idea what you mean by "just the CAN ID and not the full string." Full string of what? What function are you using to read the data from the CAN bus that returns a string in which all the data is concatenated together? If that's really the case, you can use string subset to isolate the bytes that contain the ID.

 

Can you post a screenshot of your code?

0 Kudos
Message 19 of 28
(2,728 Views)

Sorry I just re read that and it didnt make much sense even to me.  I am just using the KvCanExample and trying to modify from there.  there is a KvCanRead (icon on block diagram but a sub VI on the tree) with one input to it.  this traces out of the loops through CAN bus on and then to two KvCanAccept out side the loops.  I'm not sure if where to put the code and cant find the filter VI you were talking about.

 

I was assuming it was one string coming in but that is a baseless assumption only from the fact there is one wire going into the can read.  I cannot post the code right now as I'm not at work anymore.  I got it all from Kvaser Website.

 

I did however find a KvCanReadSpecific VI that should do what I want, but when I tried to enter the CAN ID on the front panel of that VI it would not let me and reverted to 0.  Do I need the replace KvCanRead with KvCanReadSpecific? and set a constant of the CAN address in question?

 

I hope this post makes sense and I will keep trying when I get to work tomorrow.

 

 

0 Kudos
Message 20 of 28
(2,716 Views)