strange Analog out problem NI PCIe 6251/PCI 6229

10 views
Skip to first unread message

JK

unread,
May 8, 2023, 2:01:56 PM5/8/23
to Comedi: Linux Control and Measurement Device Interface
Symptoms:
Code runs correctly on PCI 6229 (using a PCI/PCIe adapter).  Outputs a 5V square wave.
Swap card with PCIe 6251 (no adapter) and the code appears to run fine - i.e. debug printouts as expected - but there’s no analog output and no errors etc.

I’ve verified the card(s) with ao_waveform and that works as expected.  We have another system that successfully uses the same code with the PCIe 6251 so it can’t be the card.

What could be the difference between the 2 cards?  Are there changes from libcomedi 10 - 12 that would cause this behavior?

Any suggestions would be greatly appreciated!

Thanks,
JK


Here's the comedi methods I'm using.  Please excuse the java JNI cruft:


jobject createComediInsnTask (JNIEnv * env, jstring devString, jint nChannels, int devType)
{
comedi_set_global_oor_behavior (COMEDI_OOR_NUMBER);

jobject handle = (jobject)newJavaManagedByteBuffer(env, sizeof(struct ComediHandle));
struct ComediHandle * h = (struct ComediHandle *)(*env)->GetDirectBufferAddress(env, handle);

h->deviceName = GetStringNativeChars(env, devString);
h->dev = comedi_open(h->deviceName);
if (h->dev == NULL) {
throwFormattedException(env, "org/xper/exception/ComediException",
"Error opening comedi device %s: %s", h-> deviceName, getComediError());
}
h->subdev = comedi_find_subdevice_by_type(h->dev,devType,0);
if (h->subdev == -1) {
throwFormattedException (env, "org/xper/exception/ComediException",
                                "Error finding analog input subdevice for %s: %s", h->deviceName, getComediError());
}
h->nChannels = nChannels;

h->insnList.n_insns=nChannels;
h->insnList.insns=h->insn;

return handle;
}




    nCreateChannels()

JNIEXPORT void JNICALL Java_org_xper_acq_comedi_ComediAnalogSWOutDevice_nCreateChannels
  (JNIEnv * env, jobject obj, jobject handle, jint i, jshort chan, jdouble min, jdouble max, jstring aref)
{
struct ComediHandle * h = (struct ComediHandle *)(*env)->GetDirectBufferAddress(env, handle);

configComediChannel (h, env, i, chan, min, max, aref);

h->insn[i].insn=INSN_WRITE;
    h->insn[i].n = 1;
    h->insn[i].data=&(h->sample[i]);
    h->insn[i].subdev = h->subdev;
}







void configComediChannel (struct ComediHandle * h, JNIEnv * env, jint i, jshort chan, jdouble min, jdouble max, jstring aref)
{
if (i >= COMEDI_MAX_CHAN) {
throwFormattedException (env, "org/xper/exception/ComediException",
                             "Maximum channels supported is %d, requesting %d", COMEDI_MAX_CHAN, i);
}

char * refString = GetStringNativeChars(env, aref);

int ref = AREF_DIFF;
    if (strcmp(refString, "ground") == 0) {
    ref = AREF_GROUND;
    } else if (strcmp(refString, "diff") == 0) {
    ref = AREF_DIFF;
    } else if (strcmp(refString, "common") == 0) {
    ref = AREF_COMMON;
    } else if (strcmp(refString, "other") == 0) {
    ref = AREF_OTHER;
    }
    int range = comedi_find_range (h->dev, h->subdev, chan, UNIT_volt, min, max);
    if (range == -1) {
    throwFormattedException (env, "org/xper/exception/ComediException",
                    "Error finding range (device %s, chanel %i): %s", h->deviceName, chan, getComediError());
    }

h->chanlist[i] = CR_PACK(chan, range, ref);

memcpy (&((h->rangeInfo)[i]), comedi_get_range (h->dev, h->subdev, chan, range), sizeof (comedi_range));
(h->maxSample)[i] = comedi_get_maxdata (h->dev, h->subdev, chan);
}



JNIEXPORT void JNICALL Java_org_xper_acq_comedi_ComediAnalogSWOutDevice_nWrite
  (JNIEnv * env, jobject obj, jobject handle, jobject buf)
{
struct ComediHandle * h = (struct ComediHandle *)(*env)->GetDirectBufferAddress(env, handle);
double * data = (double *)(*env)->GetDirectBufferAddress(env, buf);


int i;
for (i = 0; i < h->nChannels; i ++) {
h->sample[i] = comedi_from_phys (data[i], &((h->rangeInfo)[i]), h->maxSample[i]);
}

int ret=comedi_do_insnlist(h->dev,&(h->insnList));
if(ret != h->nChannels){
throwFormattedException (env, "org/xper/exception/ComediException",
                "Error reading comedi data: %s", getComediError());
}
}



Reply all
Reply to author
Forward
0 new messages