Toggling between NRSE, RSE and Differential Analog inputs in LabWindows CVI - nidaqmx

I'm having some issues reading analog input from a DAQ card in LabWindows CVI; the input configuration seems to be set to "Differential" by default, and I was wondering how I would go about changing that to NRSE.

When you call DAQmxCreateAIVoltageChan(), use DAQmx_Val_NRSE instead of DAQmx_Val_Cfg_Default for the terminalConfig parameter.

Related

How to know which is the type of a physical channel

How do I know which kind of data is currently emitted by a physical channel?
physical_chan.ai_meas_types gives me the possible type of data (ex: CURRENT, TEMPERATURE_THERMOCOUPLE, VOLTAGE). I would like to know which one are currently emitting.
Do I try/except add_ai_current_chan to check if a current is emitted? It seems like an ugly hack. Any suggestions?
import nidaqmx.system
system = nidaqmx.system.System.local()
device = system.devices["PXI1Slot2"]
with nidaqmx.Task() as task:
for physical_chan in device.ai_physical_chans:
# physical_chan.ai_meas_types gives me the possible options.
# task.ai_channels.add_ai_current_chan(physical_chan.name)
task.ai_channels.add_ai_voltage_chan(physical_chan.name)
print(task.read())

how to get list of Auto-IVC component output names

I'm switching over to using the Auto-IVC component as opposed to the IndepVar component. I'd like to be able to get a list of the promoted output names of the Auto-IVC component, so I can then use them to go and pull the appropriate value out of a configuration file and set the values that way. This will get rid of some boilerplate.
p.model._auto_ivc.list_outputs()
returns an empty list. It seems that p.model__dict__ has this information encoded in it, but I don't know exactly what is going on there so I am wondering if there is an easier way to do it.
To avoid confusion from future readers, I assume you meant that you wanted the promoted input names for the variables connected to the auto_ivc outputs.
We don't have a built-in function to do this, but you could do it with a bit of code like this:
seen = set()
for n in p.model._inputs:
src = p.model.get_source(n)
if src.startswith('_auto_ivc.') and src not in seen:
print(src, p.model._var_allprocs_abs2prom['input'][n])
seen.add(src)
assuming 'p' is the name of your Problem instance.
The code above just prints each auto_ivc output name followed by the promoted input it's connected to.
Here's an example of the output when run on one of our simple test cases:
_auto_ivc.v0 par.x

Flexible unknown size in OpenMDAO

I have a Component that generates results on a 2D grid. I would like to be able to change the size of that grid as an input to the component. When I do so, I get errors such as:
ValueError: could not broadcast input array from shape (42025) into shape (40401)
I have params and unknowns like:
self.add_param('plot_res', val=201, pass_by_obj=True, description='Data output resolution')
self.add_output('out_grid', shape=201*201, description='output grid')
When I change plot_res, I get the error I pasted above.
Thanks in advance for your help.
You are not allowed to change the size of a variable after setup() has been called. Instead, I suggest that you make the desired size an argument to your __init__ method.

AT Command to change frame size gives ERROR

I'm using a SIM900A GSM Shield to communicate between an arduino due and an API.
I currently using it's default values in the multiplexer of GSM Shield. But now I'm in need of changing it's frame size to 255. When I check the current frame size, it gives following response which indicates the frame size as 127.
CMUX Read:AT+CMUX?
+CMUX: 0,0,5,127,10,3,30,10,2
OK
Then I used following AT command to change it to 255. But it gives an ERROR.
sim900_send_cmd("AT+CMUX=0[,0[,1[,255[,10[,3[,30[,10[,2]]]]]]]]\r\n");
CMUX Read:AT+CMUX=0[,0[,5[,255[,10[,3[,30[,10[,2]]]]]]]]
ERROR
What am I doing wrong here ? am I missing a step ? Any insight will be much appreciated. Thank you
I'm not an expert in AT commands, but I bet you don't need all the brackets in yours. Brackets are used to indicate parameters which could be omitted. So your command should look like this:
CMUX Read:AT+CMUX=0,0,5,255,10,3,30,10,2
Maybe even a shoter version will work:
CMUX Read:AT+CMUX=0,0,5,255

Unix write() function (libc)

I am making a C application in Unix that uses raw tty input.
I am calling write() to characters on the display, but I want to manipulate the cursor:
ssize_t
write(int d, const void *buf, size_t nbytes);
I've noticed that if buf has the value 8 (I mean char tmp = 8, then passing &tmp), it will move the cursor/pointer backward on the screen.
I was wondering where I could find all the codes, for example, I wish to move the cursor forward but I cannot seem to find it via Google.
Is there a page that lists all the code for the write() function please?
Thank you very much,
Jary
8 is just the ascii code for backspace. You can type man ascii and look at all the values (the man page on my Ubuntu box has friendlier names for the values). If you want to do more complicated things you may want to look at a library like ncurses.
You have just discovered that character code 8 is backspace (control-H).
You would probably be best off using the curses library to manage the screen. However, you can find out what control sequences curses knows about by using infocmp to decompile the terminfo entry for your terminal. The format isn't particularly easy to understand, but it is relatively comprehensive. The alternative is to find a manual for the terminal, which tends to be rather hard.
For instance, I'm using a color Xterm window; infocmp says:
# Reconstructed via infocmp from file: /usr/share/terminfo/78/xterm-color
xterm-color|nxterm|generic color xterm,
am, km, mir, msgr, xenl,
colors#8, cols#80, it#8, lines#24, ncv#, pairs#64,
acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
bel=^G, bold=\E[1m, clear=\E[H\E[2J, cr=^M,
csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, ed=\E[J,
el=\E[K, enacs=\E)0, home=\E[H, ht=^I, hts=\EH, il=\E[%p1%dL,
il1=\E[L, ind=^J,
is2=\E[m\E[?7h\E[4l\E>\E7\E[r\E[?1;3;4;6l\E8, kbs=^H,
kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
kdch1=\E[3~, kf1=\E[11~, kf10=\E[21~, kf11=\E[23~,
kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, kf15=\E[28~,
kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, kf19=\E[33~,
kf2=\E[12~, kf20=\E[34~, kf3=\E[13~, kf4=\E[14~,
kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
kfnd=\E[1~, kich1=\E[2~, kmous=\E[M, knp=\E[6~, kpp=\E[5~,
kslt=\E[4~, meml=\El, memu=\Em, op=\E[m, rc=\E8, rev=\E[7m,
ri=\EM, rmacs=^O, rmcup=\E[2J\E[?47l\E8, rmir=\E[4l,
rmkx=\E[?1l\E>, rmso=\E[m, rmul=\E[m,
rs2=\E[m\E[?7h\E[4l\E>\E7\E[r\E[?1;3;4;6l\E8, sc=\E7,
setab=\E[4%p1%dm, setaf=\E[3%p1%dm, sgr0=\E[m, smacs=^N,
smcup=\E7\E[?47h, smir=\E[4h, smkx=\E[?1h\E=, smso=\E[7m,
smul=\E[4m, tbc=\E[3g, u6=\E[%i%d;%dR, u7=\E[6n,
u8=\E[?1;2c, u9=\E[c,
That contains information about box drawing characters, code sequences generated by function keys, various cursor movement sequences, and so on.
You can find out more about X/Open Curses (v4.2) in HTML. However, that is officially obsolete, superseded by X/Open Curses v7, which you can download for free in PDF.
If you're using write just so you have low-level cursor control, I think you are using the wrong tool for the job. There are command codes for many types of terminal. VT100 codes, for example, are sequences of the form "\x1b[...", but rather than sending raw codes, you'd be much better off using a library like ncurses.

Resources