LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

1's complement with Hex string conversion

I have a problem with converting my decimal number to 1's complement. Please have a look into the program that i have attached . I value coming out of the loop is 489 and its 1's complement is

22 (i found it by converting to binary and then inversing it bitwise). But in the program i cant get that value, its giving -490 . I searched about this in the ni support and found that " Note that the integer representation of both the source value and the result value have to be a Signed Integer (I8. I16, I32 or I64) in order to use the NOT operator." hence i included integer conversion also .
Still problem is not solved .

 

Please look into the code..(i am using LabVIEW 7.1)

 

cheers

Bala

0 Kudos
Message 1 of 16
(10,427 Views)

Try the code below. 

 

 

Is that what you are looking for?

 

 

0 Kudos
Message 2 of 16
(10,408 Views)

You still seem to be having a problem in understanding the format of the message you are trying to send to your device.

 

As was pointed out before, if you do not understand how to construct the message and send it manually, you will not have much success in creating a program (in any software language) to send the characters programatically.

 

Original post:

 

syringe pump feedback control

 

 


 

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 3 of 16
(10,405 Views)

Ah... perspective change when you read the rest of the story..

 

0 Kudos
Message 4 of 16
(10,395 Views)

Thank you for the response ...I checked every thing and now i am able to control the pump using LabVIEW (i used the hyperterminal and a serial monitor for checking the serial port communications). All the inputs are given in ASCII format only.

In that to automate the check sum calculation i am trying to use this logic.

The logic which you sent me is not working ...please have a look..

 

Bala

0 Kudos
Message 5 of 16
(10,390 Views)

Representing a signed number with 1's complement is done by changing all the bits that are 1 to 0 and all the bits that are 0 to 1. Reversing the digits in this way is also called complementing a number.

 

So I'm trying to understand what you trying to get the 1's complement of.

 

For instance, you have a control called num, but in fact it is a string.  It is then concatenated with PR; and Flowrate (hex).  What does that give you?

Then you convert to U8 (okay).  But you then put it through a For Loop which only gives you the last element of the array which you convert to a boolean array to do a sum (that's my RG code that I'll fix below 😉 ) and then you complement that number.

 

Maybe if you gave us what you want complemented and the expected (complemented) value, we'd understand.

 

Can you describe what you want complemented?

 

 

 

For amusement.  In my previous post, I wrote a Rube Goldberg code, meaning an unnecessarily complex code.  Although useless, I shall post the improvement just to show the difference.  At that time, I thought that you wanted the complement of the sum of the bytes, as some sort of checksum.  So here is the appropriate example (not useful):

 

 

 

Here is an example of getting the complement of a string.  Obtain the Hex value for each of the characters in the string, then inverse the bits to get 1's complement.  I didn't know if you were looking for a numeric representation so I added it in, although it may be meaningless.  OOps... I noticed that I copied your string control and kept the same name.  I should have called it string instead of num 2.

 

 

Download All
Message 6 of 16
(10,367 Views)

@bala1234 wrote:

"value coming out of the loop is 489 and its 1's complement is 22 (i found it by converting to binary and then inversing it bitwise). "


 

This is only true if you are processing only the 9 least significant bits.  LabVIEW operates on 8 bit boundaries so it is inverting the "extra" MSB that are zero.  Use an AND gate to truncate the extra bits...

 

 

 

Message 7 of 16
(10,326 Views)

Thank you very much for the response...As explained by Paul i think the problem is there with 8 bit boundaries. When i put a AND gate with 1F connected if gives correct results only for a few inputs .

My infusion rate is going to change over time (the pumps flow rate will be connected to a PID controller).

Please have a look into the program attached.

 

Let me give some examples

 

1. When the infusion is 1 it should give a checksum of 20 but it gives a wrong value 00

 

2. But when infusion is 20 it gives the correct value 16 . I think the problem is again in the 1's complement ...

 

Cheers

 

Bala

 

0 Kudos
Message 8 of 16
(10,300 Views)

Hi bala,

 

what about using an AND gate of 0x1FF to catch the 9 LSBs? Instead of the current 0x1F, which only gets 5 LSBs...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 16
(10,288 Views)

bala1234,

 

Can you please post the make and model of the instrument you are trying to control?

0 Kudos
Message 10 of 16
(10,280 Views)