LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Packed BCD sent to instrument

am currently trying to communicate with an old instrument that uses packed BCD numbers only (it's a Varian FR41 Controller Gaussmeter if anyone is familiar). I am using Labview to replicate some old C code that output the BCD code. Below is the C script. What it is doing is some simple arithmetic to generate integers that are exported to the instrument through the IEEE port using %c.

(thanks to GerdW for helping turn this into a working VI https://forums.ni.com/t5/LabVIEW/IEEE-write-converted-from-C/td-p/3930058)

#include "ieeeio.h"
#include <math.h>
#include <stdio.h>


main()

{
  long  temp;
  int   z1,z2,z3,z4,b1,b2,b3;
  float b;
  double gauss,hv=5000.,magconst=.069,Mass=87.;

  if (ieeeinit()==-1)
  {
    printf("Cannot initialize IEEE system.\n");
    exit(1);
  }
  gauss=sqrt(Mass*hv/magconst);
  temp=10*gauss;
  b=temp/10.;
  z1=b/1000;
  z2=b/100;
  z3=b/10;
  z4=b;
  printf("\n\r %f %f %d %d %d %d",gauss,b,z1,z2,z3,z4);
  b1=z2+z1*6;
  b2=z4+6*z3-160*z2;
  b3=(b-z4)*160+14;
  printf("\n\r %d %d %d %d",7,b1,b2,b3);
  ieeewt("output 08;");
  ieeeprtf("%c%c%c%c\n",7,b1,b2,b3);
}

I have generated a modified .VI that generates the same numbers b1,b2,b3 and puts them into a string of packed BCD numbers. Using the input variables HV,magconst,mass above, the output should be 2510.8 gauss. and b1,b2,b3 are 142,37,16 respectively.

Now on to what the Varian Gaussmeter wants. This is the text that describes how the instrument receives information (not all of this is useful, but I copy it for the sake of completeness).  I've also attached an image of the pseudo manual that this text comes from. 

 

Data are transmitted to the FR-41 as a sequence of three 8 bit bytes. Each byte is divided into two half bytes, hi and lo, which may contain BCD numbers only. When auxiliary output port is used a fourth byte (any binary number) is added to the beginning of the sequence. The last character sent contains the least significant digit (LSD) of the new Gauss setting in the hi byte location and a load control NON BCD character, (bin 14) in the lo byte which is interpreted to load all registers with the new data. The one bit of the lo byte controls the 10 kGauss overrange when used. no change of setting occurs until the control word is received

So, if I'm understanding this correctly in the C code above, the first byte added (aux output port thing) seems to be 7, which should be 0000 0111 in BCD. The following bytes, to write 2510.8, should be 0010 0101 0001 0000 1000 followed by 1110 (for the bin 14 control word).

Here's what I have done. Using the attached .VI, I can reproduce the 32 bit BCD string that I expect it should be. I'm sending this to the GPIB Send Message VI in Labview (I've also tried using VISA Write, but it does the exact same thing across all tests as far as I can see). However, the instrument doesn't register anything happening.

 

The interesting thing is that when I send the instrument the information as a %f string, of floating points, so, 7.0000142.00037.00016.000, the instrument registers something happening and the tens and hundreds places change. So, if I send 42 as a floating point, the instrument will go to X4X2.X gauss setting. If I put 142 it will do the same thing. If I put 17 it will go to X1X7.X setting. If I send it 17 then 25 it will only take the first one.

 

My thought is that something in the GPIB Send or VISA Write is taking my string of BCD numbers and sending them out as something else, but I can't figure out what I could be doing wrong. Any help or tests would be much appreciated; I've been struggling with this for weeks now to no avail.

Download All
0 Kudos
Message 1 of 3
(2,288 Views)

Which part of your VI are we supposed to be looking at?  I see at the bottom a basic conversion of U8 values to ASCII string characters.  At the top I see a super-complicated set of data manipulation that at the end doesn't even have an output.  Since you are sending data as binary coded decimal, I have no idea why you would want to format anything with a %f format string which implies decimal values with a fractional component, which in the practical non-programming world means "decimal number" as in you have digits showing up after the decimal point.

 

In the LabVIEW programming world, "decimal" means a decimal integer (as opposed to binary, octal, or hexadecimal).

 

 

 

 

0 Kudos
Message 2 of 3
(2,257 Views)

Hi Carlson,

 

a suggestion:

check.png

The loop calculate the 5 digits from your float value.

Then the "14" value is added as 6th digit, then the BCD bytes are created.

(I prefer hexadecimal formatting for BCD data, but you gave decimal values (in wrong order?) with your example data…)

I suggest learning to handle BCD values either by reading 6502 Assembler (including that SED/CLD commands) or by learning about the ABCD/SBCD commands of the 68k CPU family… 🙂

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 3
(2,194 Views)