Specifications

RIGOL Chapter 4 Programming Demos
4-26 M300 Programming Guide
C# Programming Demo
The program used in this Demo: Microsoft Visual Studio 2008
The functions realized in this Demo: search for the instrument address, connect the instrument, send
command and read the return value, configure the scan list etc.
1. Run Microsoft Visual Studio 2008, create a C# project based on Windows Form Application and name
it as M300_Demo_CSharp.
2. Add a visa library by adding the statement as follows to Form1.cs.
using System.Runtime.InteropServices;
/*Function:Queries a VISA system to locate the resources associated with a specified interface*/
[DllImport("visa32.dll")]
public static extern Int32 viFindRsrc(Int32 sesn, string expr, ref Int32 vi, ref Int32 retCount, byte[]
Desc);
/*Function:Returns the next resource from the list of resources found during a previous call to
viFindRsrc().*/
[DllImport("visa32.dll")]
public static extern Int32 viFindNext(Int32 vi, byte[] Desc);
/*Function:This function returns a session to the Default Resource Manager resource.*/
[DllImport("visa32.dll")]
public static extern Int32 viOpenDefaultRM(ref Int32 sesn);
/*Function:Opens a session to the specified resource.*/
[DllImport("visa32.dll")]
private static extern Int32 viOpen(Int32 sesn, string viDexc, Int32 mode, Int32 timeout, ref Int32
vi);
/*Function:Closes the specified session, event, or find list.*/
[DllImport("visa32.dll")]
private static extern Int32 viClose(Int32 vi);
/*Function:Converts, formats, and sends the parameters designated by params to the device or
interface as specified by the format string.*/
[DllImport("visa32.dll")]
private static extern Int32 viVPrintf(Int32 vi, string writeFmt, Int32 para);
/*Function:Reads, converts, and formats data using the format specifier. Stores the formatted
data in the parameters (designated by ...).*/
[DllImport("visa32.dll")]
private static extern Int32 viScanf(Int32 vi, string readFmt, byte[] para);
Note:
Please add the visa32.dll” file to the current project directory.