VTI Instruments
46
EMX-75XX Index
/*Now let's pick another port and set it to an output, and output some data on
it. Changing the direction to Output allows us to write data as well as read it back.
Note that we also have to set a voltage on the port before we can write data.*/
Dio->Normal->Ports->Item["PORT2"]->Direction = VTEXDioDirectionOutput;
Dio->Normal->Ports->Item["PORT2"]->VoltageRange = 3.3;
Dio->Normal->Ports->Item["PORT2"]->Data = 128;
/* Changing the Polarity of an output changes both the output and readback
polarity. This means the user will always read back what they wrote, but the opposite
signal will be placed on the line. */
Dio->Normal->Ports->Item["PORT2"]->Polarity = VTEXDioPolarityInverse;
Dio->Normal->Ports->Item["PORT2"]->Data = 128; //Looks the same as above,
really outputting 127
data = Dio->Normal->Ports->Item["PORT2"]->Data; //Will return 128.
/* The Configure call lets us set all the values for a particular port quickly.
Here we will configure the port with a direction of Output, a Polarity of Normal, a
VoltageSource of User, and a voltage of 5V TTL Emulation (which has no effect, since
the voltage source is set to User. */
Dio->Normal->Ports->Item["PORT3"]->Configure(VTEXDioDirectionOutput,
VTEXDioPolarityNormal, VTEXDioVoltageSourceUser, -1.0);
/* We can also work with multiple ports at once. The ReadPorts and WritePorts
functions allow us to set or get data from several ports at a time. Setting data on
ports with an Input direction is ignored. */
Dio->Normal->WritePorts(VTEXDioDataWidth16, 2, 255); //Writes a data of 255 on
port 2, and 0 on port 3.
Dio->Close();
::CoUninitialize(); //Turn off the COM layer.
}
catch(...)
{
//Exception handling here
}
return 0;
}
C#
using System;
using System.Runtime.InteropServices;
using VTI.VTEXDio.Interop;
namespace PortConfiguration
{
class PortConfiguration
{
static void Main(string[] args)
{
try
{
VTEXDio Dio = new VTEXDio();
try
{
Dio.Initialize("TCPIP::10.20.1.6::INSTR", true, true, "");
Dio.Normal.Ports.get_Item("PORT1").VoltageRange = 5.0;