[comedi] strange Analog out problem NI PCIe 6251/PCI 6229
JK <[email protected]> Mon, 8 May 2023 11:01:56 -0700 (PDT)
| Newsgroups | gmane.linux.comedi |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_8584_608276886.1683568916011
Content-Type: multipart/alternative;
boundary="----=_Part_8585_934894928.1683568916011"
------=_Part_8585_934894928.1683568916011
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Symptoms:
Code runs correctly on PCI 6229 (using a PCI/PCIe adapter). Outputs a 5V=
=20
square wave.
Swap card with PCIe 6251 (no adapter) and the code appears to run fine -=20
i.e. debug printouts as expected - but there=E2=80=99s no analog output and=
no=20
errors etc.
I=E2=80=99ve verified the card(s) with ao_waveform and that works as expect=
ed. We=20
have another system that successfully uses the same code with the PCIe 6251=
=20
so it can=E2=80=99t be the card.
What could be the difference between the 2 cards? Are there changes from=
=20
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=20
nChannels, int devType)
{
comedi_set_global_oor_behavior (COMEDI_OOR_NUMBER);
jobject handle =3D (jobject)newJavaManagedByteBuffer(env, sizeof(struct=20
ComediHandle));
struct ComediHandle * h =3D (struct ComediHandle=20
*)(*env)->GetDirectBufferAddress(env, handle);
h->deviceName =3D GetStringNativeChars(env, devString);
h->dev =3D comedi_open(h->deviceName);
if (h->dev =3D=3D NULL) {
throwFormattedException(env, "org/xper/exception/ComediException",=20
"Error opening comedi device %s: %s", h-> deviceName, getComediError());
}
h->subdev =3D comedi_find_subdevice_by_type(h->dev,devType,0);
if (h->subdev =3D=3D -1) {
throwFormattedException (env, "org/xper/exception/ComediException",=20
"Error finding analog input subdevice for=
=20
%s: %s", h->deviceName, getComediError());
}
h->nChannels =3D nChannels;
h->insnList.n_insns=3DnChannels;
h->insnList.insns=3Dh->insn;
return handle;
}
nCreateChannels()
JNIEXPORT void JNICALL=20
Java_org_xper_acq_comedi_ComediAnalogSWOutDevice_nCreateChannels
(JNIEnv * env, jobject obj, jobject handle, jint i, jshort chan, jdouble=
=20
min, jdouble max, jstring aref)
{
struct ComediHandle * h =3D (struct ComediHandle=20
*)(*env)->GetDirectBufferAddress(env, handle);
configComediChannel (h, env, i, chan, min, max, aref);
h->insn[i].insn=3DINSN_WRITE;
h->insn[i].n =3D 1;
h->insn[i].data=3D&(h->sample[i]);
h->insn[i].subdev =3D h->subdev;
}
void configComediChannel (struct ComediHandle * h, JNIEnv * env, jint i,=20
jshort chan, jdouble min, jdouble max, jstring aref)
{
if (i >=3D COMEDI_MAX_CHAN) {
throwFormattedException (env, "org/xper/exception/ComediException",=20
"Maximum channels supported is %d, requesting=
=20
%d", COMEDI_MAX_CHAN, i);
}
char * refString =3D GetStringNativeChars(env, aref);
int ref =3D AREF_DIFF;
if (strcmp(refString, "ground") =3D=3D 0) {
ref =3D AREF_GROUND;
} else if (strcmp(refString, "diff") =3D=3D 0) {
ref =3D AREF_DIFF;
} else if (strcmp(refString, "common") =3D=3D 0) {
ref =3D AREF_COMMON;
} else if (strcmp(refString, "other") =3D=3D 0) {
ref =3D AREF_OTHER;
}
int range =3D comedi_find_range (h->dev, h->subdev, chan, UNIT_volt, mi=
n,=20
max);
if (range =3D=3D -1) {
throwFormattedException (env, "org/xper/exception/ComediException",=20
"Error finding range (device %s, chanel %i): %s",=20
h->deviceName, chan, getComediError());
}
h->chanlist[i] =3D CR_PACK(chan, range, ref);
memcpy (&((h->rangeInfo)[i]), comedi_get_range (h->dev, h->subdev, chan,=20
range), sizeof (comedi_range));
(h->maxSample)[i] =3D comedi_get_maxdata (h->dev, h->subdev, chan);
}
JNIEXPORT void JNICALL=20
Java_org_xper_acq_comedi_ComediAnalogSWOutDevice_nWrite
(JNIEnv * env, jobject obj, jobject handle, jobject buf)
{
struct ComediHandle * h =3D (struct ComediHandle=20
*)(*env)->GetDirectBufferAddress(env, handle);
double * data =3D (double *)(*env)->GetDirectBufferAddress(env, buf);
int i;
for (i =3D 0; i < h->nChannels; i ++) {
h->sample[i] =3D comedi_from_phys (data[i], &((h->rangeInfo)[i]),=20
h->maxSample[i]);
}
int ret=3Dcomedi_do_insnlist(h->dev,&(h->insnList));
if(ret !=3D h->nChannels){
throwFormattedException (env, "org/xper/exception/ComediException",=20
"Error reading comedi data: %s", getComediError());
}
}
--=20
You received this message because you are subscribed to the Google Groups "=
Comedi: Linux Control and Measurement Device Interface" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
comedi_list/918a5c2e-d580-4d45-9f13-64d059371e2fn%40googlegroups.com.
------=_Part_8585_934894928.1683568916011
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; =
font-weight: normal; letter-spacing: normal; text-align: start; text-indent=
: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-d=
ecoration: none;">Symptoms:</div><div style=3D"caret-color: rgb(0, 0, 0); c=
olor: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: no=
rmal; font-variant-caps: normal; font-weight: normal; letter-spacing: norma=
l; text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; text-decoration: none;">Code runs correctly on P=
CI 6229 (using a PCI/PCIe adapter). =C2=A0Outputs a 5V square wave.</div><d=
iv style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: He=
lvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; fo=
nt-weight: normal; letter-spacing: normal; text-align: start; text-indent: =
0px; text-transform: none; white-space: normal; word-spacing: 0px; text-dec=
oration: none;">Swap card with PCIe 6251 (no adapter) and the code appears =
to run fine - i.e. debug printouts as expected - but there=E2=80=99s no ana=
log output and no errors etc.</div><div style=3D"caret-color: rgb(0, 0, 0);=
color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: =
normal; font-variant-caps: normal; font-weight: normal; letter-spacing: nor=
mal; text-align: start; text-indent: 0px; text-transform: none; white-space=
: normal; word-spacing: 0px; text-decoration: none;"><br /></div><div style=
=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica;=
font-size: 14px; font-style: normal; font-variant-caps: normal; font-weigh=
t: normal; letter-spacing: normal; text-align: start; text-indent: 0px; tex=
t-transform: none; white-space: normal; word-spacing: 0px; text-decoration:=
none;">I=E2=80=99ve verified the card(s) with ao_waveform and that works a=
s expected. =C2=A0We have another system that successfully uses the same co=
de with the PCIe 6251 so it can=E2=80=99t be the card.</div><div style=3D"c=
aret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font=
-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: no=
rmal; letter-spacing: normal; text-align: start; text-indent: 0px; text-tra=
nsform: none; white-space: normal; word-spacing: 0px; text-decoration: none=
;"><br /></div><div style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0)=
; font-family: Helvetica; font-size: 14px; font-style: normal; font-variant=
-caps: normal; font-weight: normal; letter-spacing: normal; text-align: sta=
rt; text-indent: 0px; text-transform: none; white-space: normal; word-spaci=
ng: 0px; text-decoration: none;">What could be the difference between the 2=
cards? =C2=A0Are there changes from libcomedi 10 - 12 that would cause thi=
s behavior?</div><div><br /></div><div>Any suggestions would be greatly app=
reciated!</div><div><br /></div><div>Thanks,</div><div>JK</div><div><br /><=
/div><div><br /></div><div>Here's the comedi methods I'm using.=C2=A0 Pleas=
e excuse the java JNI cruft:</div><div><br /></div><div><br />jobject creat=
eComediInsnTask (JNIEnv * env, jstring devString, jint nChannels, int devTy=
pe)<br />{<br /><span style=3D"white-space: pre;"> </span>comedi_set_global=
_oor_behavior (COMEDI_OOR_NUMBER);<br /><span style=3D"white-space: pre;"> =
</span><br /><span style=3D"white-space: pre;"> </span>jobject handle =3D =
(jobject)newJavaManagedByteBuffer(env, sizeof(struct ComediHandle));<br /><=
span style=3D"white-space: pre;"> </span>struct ComediHandle * h =3D (struc=
t ComediHandle *)(*env)->GetDirectBufferAddress(env, handle);<br /><span=
style=3D"white-space: pre;"> </span><br /><span style=3D"white-space: pre;=
"> </span>h->deviceName =3D GetStringNativeChars(env, devString);<br /><=
span style=3D"white-space: pre;"> </span>h->dev =3D comedi_open(h->de=
viceName);<br /><span style=3D"white-space: pre;"> </span>if (h->dev =3D=
=3D NULL) {<br /><span style=3D"white-space: pre;"> </span>throwFormattedE=
xception(env, "org/xper/exception/ComediException", <br /><span style=3D"wh=
ite-space: pre;"> </span>"Error opening comedi device %s: %s", h-> de=
viceName, getComediError());<br /><span style=3D"white-space: pre;"> </span=
>}<br /><span style=3D"white-space: pre;"> </span>h->subdev =3D comedi_f=
ind_subdevice_by_type(h->dev,devType,0);<br /><span style=3D"white-space=
: pre;"> </span>if (h->subdev =3D=3D -1) {<br /><span style=3D"white-spa=
ce: pre;"> </span>throwFormattedException (env, "org/xper/exception/Comedi=
Exception", <br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "Error finding anal=
og input subdevice for %s: %s", h->deviceName, getComediError());<br /><=
span style=3D"white-space: pre;"> </span>}<br /><span style=3D"white-space:=
pre;"> </span>h->nChannels =3D nChannels;<br /><span style=3D"white-spa=
ce: pre;"> </span><br /><span style=3D"white-space: pre;"> </span>h->ins=
nList.n_insns=3DnChannels;<br /><span style=3D"white-space: pre;"> </span>h=
->insnList.insns=3Dh->insn;<br /><span style=3D"white-space: pre;"> <=
/span><br /><span style=3D"white-space: pre;"> </span>return handle;<br />}=
<br /><br /><br /><br /><br />=C2=A0 =C2=A0 nCreateChannels()<br /><br />JN=
IEXPORT void JNICALL Java_org_xper_acq_comedi_ComediAnalogSWOutDevice_nCrea=
teChannels<br />=C2=A0 (JNIEnv * env, jobject obj, jobject handle, jint i, =
jshort chan, jdouble min, jdouble max, jstring aref)<br />{<br /><span styl=
e=3D"white-space: pre;"> </span>struct ComediHandle * h =3D (struct ComediH=
andle *)(*env)->GetDirectBufferAddress(env, handle);<br /><span style=3D=
"white-space: pre;"> </span><br /><span style=3D"white-space: pre;"> </span=
>configComediChannel (h, env, i, chan, min, max, aref);<br /><span style=3D=
"white-space: pre;"> </span><br /><span style=3D"white-space: pre;"> </span=
>h->insn[i].insn=3DINSN_WRITE;<br />=C2=A0 =C2=A0 h->insn[i].n =3D 1;=
<br />=C2=A0 =C2=A0 h->insn[i].data=3D&(h->sample[i]);<br />=C2=
=A0 =C2=A0 h->insn[i].subdev =3D h->subdev;<br />}<br /><br /><br /><=
br /><br /><br /><br /><br />void configComediChannel (struct ComediHandle =
* h, JNIEnv * env, jint i, jshort chan, jdouble min, jdouble max, jstring a=
ref)<br />{<br /><span style=3D"white-space: pre;"> </span>if (i >=3D CO=
MEDI_MAX_CHAN) {<br /><span style=3D"white-space: pre;"> </span>throwForma=
ttedException (env, "org/xper/exception/ComediException", <br />=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0"Maximum channels supported is %d, requesting %d", COME=
DI_MAX_CHAN, i);<br /><span style=3D"white-space: pre;"> </span>}<br /><spa=
n style=3D"white-space: pre;"> </span><br /><span style=3D"white-space: pre=
;"> </span>char * refString =3D GetStringNativeChars(env, aref);<br /><span=
style=3D"white-space: pre;"> </span><br /><span style=3D"white-space: pre;=
"> </span>int ref =3D AREF_DIFF;<br />=C2=A0 =C2=A0 if (strcmp(refString, "=
ground") =3D=3D 0) {<br />=C2=A0 =C2=A0 <span style=3D"white-space: pre;"> =
</span>ref =3D AREF_GROUND;<br />=C2=A0 =C2=A0 } else if (strcmp(refString,=
"diff") =3D=3D 0) {<br />=C2=A0 =C2=A0 <span style=3D"white-space: pre;"> =
</span>ref =3D AREF_DIFF;<br />=C2=A0 =C2=A0 } else if (strcmp(refString, "=
common") =3D=3D 0) {<br />=C2=A0 =C2=A0 <span style=3D"white-space: pre;"> =
</span>ref =3D AREF_COMMON;<br />=C2=A0 =C2=A0 } else if (strcmp(refString,=
"other") =3D=3D 0) {<br />=C2=A0 =C2=A0 <span style=3D"white-space: pre;">=
</span>ref =3D AREF_OTHER;<br />=C2=A0 =C2=A0 }<br />=C2=A0 =C2=A0 int ran=
ge =3D comedi_find_range (h->dev, h->subdev, chan, UNIT_volt, min, ma=
x);<br />=C2=A0 =C2=A0 if (range =3D=3D -1) {<br />=C2=A0 =C2=A0 <span styl=
e=3D"white-space: pre;"> </span>throwFormattedException (env, "org/xper/exc=
eption/ComediException", <br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 "Error finding range (device %s, chanel %i): %s=
", h->deviceName, chan, getComediError());<br />=C2=A0 =C2=A0 }<br /><br=
/><span style=3D"white-space: pre;"> </span>h->chanlist[i] =3D CR_PACK(=
chan, range, ref);<br /><span style=3D"white-space: pre;"> </span><br /><sp=
an style=3D"white-space: pre;"> </span>memcpy (&((h->rangeInfo)[i]),=
comedi_get_range (h->dev, h->subdev, chan, range), sizeof (comedi_ra=
nge));<br /><span style=3D"white-space: pre;"> </span>(h->maxSample)[i] =
=3D comedi_get_maxdata (h->dev, h->subdev, chan);<br />}<br /><br /><=
br /><br />JNIEXPORT void JNICALL Java_org_xper_acq_comedi_ComediAnalogSWOu=
tDevice_nWrite<br />=C2=A0 (JNIEnv * env, jobject obj, jobject handle, jobj=
ect buf)<br />{<br /><span style=3D"white-space: pre;"> </span>struct Comed=
iHandle * h =3D (struct ComediHandle *)(*env)->GetDirectBufferAddress(en=
v, handle);<br /><span style=3D"white-space: pre;"> </span>double * data =
=3D (double *)(*env)->GetDirectBufferAddress(env, buf);<br /><br /><br /=
><span style=3D"white-space: pre;"> </span>int i;<br /><span style=3D"white=
-space: pre;"> </span>for (i =3D 0; i < h->nChannels; i ++) {<br /><s=
pan style=3D"white-space: pre;"> </span>h->sample[i] =3D comedi_from_ph=
ys (data[i], &((h->rangeInfo)[i]), h->maxSample[i]);<br /><span s=
tyle=3D"white-space: pre;"> </span>}<br /><span style=3D"white-space: pre;"=
> </span><br /><span style=3D"white-space: pre;"> </span>int ret=3Dcomedi_=
do_insnlist(h->dev,&(h->insnList));<br /><span style=3D"white-spa=
ce: pre;"> </span>if(ret !=3D h->nChannels){<br /><span style=3D"white-s=
pace: pre;"> </span>throwFormattedException (env, "org/xper/exception/Come=
diException", <br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
"Error reading comedi data: %s", getComediError());<br /><span style=3D"wh=
ite-space: pre;"> </span>}<br />}</div><div><br /></div><div><br /></div><d=
iv><br /></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Comedi: Linux Control and Measurement Device Interface" group.<br=
/>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">comedi_=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/comedi_list/918a5c2e-d580-4d45-9f13-64d059371e2fn%40googlegroups=
.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/ms=
gid/comedi_list/918a5c2e-d580-4d45-9f13-64d059371e2fn%40googlegroups.com</a=
>.<br />
------=_Part_8585_934894928.1683568916011--
------=_Part_8584_608276886.1683568916011--