Editing Instrument control package

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 78: Line 78:
# Prerequisits are that during install of the NI drivers, the C/C++ support  
# Prerequisits are that during install of the NI drivers, the C/C++ support  
# and the NI Measurement & Automation explorer has been enabled.
# and the NI Measurement & Automation explorer has been enabled.
# set the base for includes and libraries on your system
# it is usually /usr, but on newer windows installs of octave, it will be
# /mingw64
INSTALL_BASE=/usr


# this define should find the NI header file, if properly installled
# this define should find the NI header file, if properly installled
Line 91: Line 86:


# symlink NI header file
# symlink NI header file
mkdir -p ${INSTALL_BASE}/include/gpib/
mkdir -p /usr/include/gpib/
ln -sf "${NI_H_FILE}" ${INSTALL_BASE}/include/gpib/ib.h
ln -sf "${NI_H_FILE}" /usr/include/gpib/ib.h


# generate .def for all functions in the NI header file with a NI488CC prefix
# generate .def for all functions in the NI header file with a NI488CC prefix
echo LIBRARY ${NI_DLL_FILE} > ${NI_DEF_FILE}
echo LIBRARY ${NI_DLL_FILE} > ${NI_DEF_FILE}
echo EXPORTS >> ${NI_DEF_FILE}
echo EXPORTS >> ${NI_DEF_FILE}
grep "NI488CC  *[A-Za-z]" ${INSTALL_BASE}/include/gpib/ib.h \
grep "NI488CC  *[A-Za-z]" /usr/include/gpib/ib.h \
   | sed "s/^.*NI488CC  *//" \
   | sed "s/^.*NI488CC  *//" \
   | sed "s/(.*$//" >> ${NI_DEF_FILE}
   | sed "s/(.*$//" >> ${NI_DEF_FILE}


# generate the wrapper library simulating gpib-linux
# generate the wrapper library simulating gpib-linux
dlltool -d ${NI_DEF_FILE} -l ${INSTALL_BASE}/lib/libgpib.a
dlltool -d ${NI_DEF_FILE} -l /usr/lib/libgpib.a


#cleanup  
#cleanup  
Line 113: Line 108:


If rpcgen cannot be build from source, the following error might be obtained:
If rpcgen cannot be build from source, the following error might be obtained:
<syntaxhighlight lang="text"  style="font-size:13px">
<syntaxhighlight style="font-size:13px">
pkg: error running `make' for the instrument-control package.
pkg: error running `make' for the instrument-control package.
error: called from
error: called from
Line 367: Line 362:


== i2c ==
== i2c ==
Example with a Si7021 i2c breakout board (https://www.sparkfun.com/products/1376) connected to a i2c master interface.
i2c
 
To work out the devices available (assuming i2ctools are installed) run the i2cdetect command from a terminal window.
 
<syntaxhighlight lang="bash" style="font-size:13px">
$ i2cdetect -l
i2c-1  i2c            i2c-ch341-usb at bus 002 device 008    I2C adapter
i2c-0  unknown        SMBus I801 adapter at 4000              N/
</syntaxhighlight>
 
In the example case the temperature sensor is connected to the i2c-ch341-usb device, and it is assumed the user has sufficient permissions to access the device.
 
According to the datasheet, the temperature device uses address 0x40, so create a i2c device using the linux device and address:
 
<syntaxhighlight lang="octave" style="font-size:13px">
i2cdev = i2c("/dev/i2c-1", 0x40)
</syntaxhighlight>
 
To read  the temperature, register 0xF3 must be addressed and read (2 bytes of data):
 
<syntaxhighlight lang="octave" style="font-size:13px">
TEMP_MEASURE_NOHOLD = hex2dec("F3");
fwrite (i2cdev, uint8([TEMP_MEASURE_NOHOLD]));
pause (0.02);
data = fread (i2cdev, 3);
</syntaxhighlight>
 
The data must be converted to a deg K value by making  16 bit number of the value and masking out unused bits.
 
<syntaxhighlight lang="octave" style="font-size:13px">
value = uint16(data(1))*256 + uint16(data(2));
value = bitand (value, hex2dec("FFFC"));
temp_Code = double(value);
</syntaxhighlight>
 
Now convert the temperature to degrees C and display:
 
<syntaxhighlight lang="octave" style="font-size:13px">
C = (175.72*temp_Code/65536)-46.85;
printf ("temperature read %f C\n", C);
</syntaxhighlight>


== TCP ==
== TCP ==
Please note that all contributions to Octave may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Octave:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Template used on this page: