![]() 本文以Active Technologies公司(簡(jiǎn)稱(chēng)AT)的PG 1000系列脈沖發(fā)生器為例,講述了在進(jìn)行SCPI控制儀器前,如何使用NI MAX進(jìn)行系統配置。 1. 概要 1 2. 工具/準備 1 2.1 PG-1000系列SDK 1 2.2 NI VISA 2 2.3 NI NAX(Measurement & Automation Explorer) 3 2.4 PG-1000系列軟件 3 3. 配置系統(使用NI MAX) 4 4. 調試系統(使用AT Instrument Communicator) 8 5. 例程/范例 9 5.1 LabVIEW 10 5.2 Microsoft C# 11 5.3 Microsoft C++ 13 1. 概要 可以連接儀器至用戶(hù)的網(wǎng)絡(luò )中,實(shí)現打印、文件共享、互聯(lián)網(wǎng)訪(fǎng)問(wèn)等其他功能。請聯(lián)系貴公司的網(wǎng)絡(luò )管理員,并使用標準Windows在用戶(hù)的網(wǎng)絡(luò )中配置儀器。 儀器是通過(guò)VXI-11 (LAN)協(xié)議進(jìn)行控制的,用戶(hù)可以利用SCPI命令遠程控制儀器,請參考《Pulse Rider PG-1000 programmer manual》了解詳細的SCPI命令語(yǔ)法、語(yǔ)句。 2. 工具/準備 2.1 PG-1000系列SDK 1. 用戶(hù)在www.activetechnologies.it網(wǎng)站注冊賬戶(hù)后,登錄網(wǎng)站并“Register”儀器。 2. 點(diǎn)擊“Support”—“Client Area”,訪(fǎng)問(wèn)“Users Products”界面。 3. 點(diǎn)擊AT-PG1072或AT-PG1074鏈接,訪(fǎng)問(wèn)下載界面。點(diǎn)擊SDK-AT-PULSE-GENERATOR安裝包并下載。 SDK內包括: AT Instrument Communicator安裝程序(用途,參考下節“配置系統”的第9步) C++例程 C#例程 LabVIEW例程 2.2 NI VISA 在Client-PC(即Remote PC)中下載并安裝NI VISA。 VISA為硬件與開(kāi)發(fā)環(huán)境(比如,Visual Studio .NET、LabVIEW、LabWindows/CVI、Measurement Studio for Microsoft Visual Studio、MatLab等)提供編程接口。NI VISA是National Instruments公司提供的VISA I/O標準。NI VISA包括軟件庫、交互式工具(例如, NI I/O Trace與VISA交互式控制)、配置程序等。 2.3 NI NAX(Measurement & Automation Explorer) 在Client-PC(即Remote PC)中下載并安裝NI MAX軟件。 2.4 PG-1000系列軟件 打開(kāi)PG-1000系列儀器中自帶的控制軟件,找到“Remote/Local”界面中的VXI-11(LAN協(xié)議)Server。默認情況下,VXI-11 Server是開(kāi)啟的,意味著(zhù)PG1000系列儀器可以接收來(lái)自Client-PC的SCPI命令。 當PG-1000系列儀器接收SCPI命令時(shí),PG-1000系列軟件界面會(huì )根據SCPI命令做出相應的變化(例如,參數設置等)。 注意:不能在本地PC(即PG-1000系列儀器本身中的PC系統)中通過(guò)SCPI命令控制PG-1000系列儀器。 若VXI-11 Server被關(guān)閉,SCPI命令通信將會(huì )失敗。 3. 配置系統(使用NI MAX) 使用NI MAX進(jìn)行如下配置: 1. 使用LAN線(xiàn)纜連接儀器與Client-PC。 2. 在Client-PC中安裝NI VISA與NI MAX。 3. 打開(kāi)Client-PC中的NI MAX。點(diǎn)擊“Add Network Device ”——“VISA TCP/IP Resource…”。 4. 選擇“Auto-detect of LAN Instrument”,并點(diǎn)擊“Next”。 5. 面板將會(huì )顯示在LAN網(wǎng)絡(luò )中搜索到的儀器,選擇PG-1000系列儀器,并點(diǎn)擊“Next”。 6. 輸入“Alias”(此步非必須,可省略),并點(diǎn)擊“Next”。 7. 點(diǎn)擊“Finish”。 8. PG-1000儀器資源將會(huì )在“Network Devices”列表中顯示。 9. 現在,可以使用NI Visa Test Panel或AT Instrument Communicator(軟件的獲取下載,參考“PG-1000系列 SDK”小節的第3步;軟件的使用,參考下節“使用AT Instrument Communicator調試系統”)發(fā)送SCPI命令至PG-1000。 4. 調試系統(使用AT Instrument Communicator) VXI-11(LAN協(xié)議)Server可以為在同一LAN網(wǎng)絡(luò )下的PG-1000儀器與Client-PC提供軟件接口。 AT Instrument Communicator軟件需安裝在Client-PC中,且Client-PC中需安裝NI VISA。 通過(guò)以下步驟,操控Client-PC中AT Instrument Communicator軟件實(shí)現對PG-1000儀器的控制: 1. 在Client-PC中安裝AT Instrument Communicator軟件。 2. 在“Device”列表中選擇PG-1000系列儀器。 3. 點(diǎn)擊“Connect”按鈕。 4. 若連接成功,“Command”復選框內的“Write”、“Read”等按鈕將會(huì )可選(非灰色) 5. 在“Command”文本框內輸入*IDN?并點(diǎn)擊“Write”按鈕。 6. 點(diǎn)擊“Query”按鈕。 7. 在“Event Logger”列表中,PG-1000系列儀器會(huì )顯示返回值,例如: ACTIVE TECHNOLOGIES, AT-PULSE-RIDER PG1072 00000001,SCPI 99.0, SV 1.0.0 where 00000001 is the serialnumber, SCPI 99.0 is the SCPI command version and SV 1.0.0 is the software version. 8. TXT命令腳本(script)文件包括一系列SCPI命令(每行一條命令),用戶(hù)可以發(fā)送TXT命令腳本文件。點(diǎn)擊“File”—“Open”打開(kāi)加載TXT命令腳本文件對話(huà)框。 9. 參考《Pulse Rider PG-1000 programmer manual》了解詳細的SCPI命令語(yǔ)法、語(yǔ)句。 5. 例程/范例 PG-1000系列SDK中包含由很多種語(yǔ)言編寫(xiě)的例程,例如LabVIEW、Microsoft Visual C++與Microsoft C# .NE語(yǔ)言。 例程可以在安裝了NI VISA并兼容Microsoft Windows®的PC上運行。 NI VISA是National Instruments公司提供的VISA I/O標準。NI VISA包括軟件庫、交互式工具(例如, NI I/O Trace與VISA交互式控制)、配置程序等。 在軟件中使用NI VISA編寫(xiě)的儀器驅動(dòng),可以處理軟件應用程序與硬件儀器之間的通信。 可下載并安裝NI VISA。 例程假設系統已經(jīng)識別PG-1000系列儀器的資源名稱(chēng)(resource name),即IP地址或主機名稱(chēng),可參考前文“配置系統”小節了解資源名稱(chēng)(resource name)。 5.1 LabVIEW LabVIEW例程要求最低使用LabView 2013 64 bit版本,可在…\LabView 2013 Examples\AT-PULSE-RIDER-PG1000 Series文件夾內找到LabVIEW工程。 LabVIEW工程中包含一些VI用于控制儀器的基礎特性,還包含有三個(gè)例程。 雙擊GenerateSinglePulse.vi,本例程可以連續模式生成單脈沖。在運行VI之前,需要選擇“VISA resource name”。 用戶(hù)可以更改脈寬、延時(shí)、高電平、低電平和其他輸出參數。 運行VI開(kāi)始生成輸出脈沖,點(diǎn)擊“Stop”按鈕控件停止PG-1000系列脈沖發(fā)生器。 5.2 Microsoft C# 可以在…\VS2015 Examples\PulseRiderCSharp文件夾內找到C++例程,需要安裝Microsoft Visual Studio 2015打開(kāi)例程。 用戶(hù)需要編譯并運行例程;在Form中需要輸入“Instrument Address”并點(diǎn)擊“Connect”按鈕建立連接。 若成功連接,儀器會(huì )在“Server Answer”文本框內顯示*IDN?命令的返回值。 點(diǎn)擊“Generate Pulse”按鈕發(fā)送SCPI命令至PG-1000系列儀器,儀器將會(huì )以連續模式生成輸出單脈沖。 private void btnGeneratePulse_Click(object sender, EventArgs e) { // Reset to default tbAnswer.Text = vs.SendTo(sInstrumentAddress, "*RST"); // Set the channel parameters tbAnswer.Text = vs.SendTo(sInstrumentAddress, "SOURce1:VOLT:HIGH 1.5"); tbAnswer.Text = vs.SendTo(sInstrumentAddress, "SOURce1:VOLT ![]() tbAnswer.Text = vs.SendTo(sInstrumentAddress, "SOURce2:VOLT:HIGH 2"); tbAnswer.Text = vs.SendTo(sInstrumentAddress, "SOURce2:VOLT ![]() // Set the pulse parameters tbAnswer.Text = vs.SendTo(sInstrumentAddress, "SOURce1 ![]() tbAnswer.Text = vs.SendTo(sInstrumentAddress, "SOURce1 ![]() ![]() tbAnswer.Text = vs.SendTo(sInstrumentAddress, "SOURce2 ![]() tbAnswer.Text = vs.SendTo(sInstrumentAddress, "SOUrce2 ![]() ![]() // Set the pulse mode tbAnswer.Text = vs.SendTo(sInstrumentAddress, "OUTPut1 ![]() tbAnswer.Text = vs.SendTo(sInstrumentAddress, "OUTPut2 ![]() // Turn On the channels tbAnswer.Text = vs.SendTo(sInstrumentAddress, "OUTPut1 ON"); tbAnswer.Text = vs.SendTo(sInstrumentAddress, "OUTPut2 ON"); // Set the trigger mode and arm the instrument tbAnswer.Text = vs.SendTo(sInstrumentAddress, "TRIGger:MODE CONTinuous"); tbAnswer.Text = vs.SendTo(sInstrumentAddress, "PULSEGENControl:START"); // Send the trigger tbAnswer.Text = vs.SendTo(sInstrumentAddress, "*TRG"); } 點(diǎn)擊“ Load Script…”按鈕可加載SCPI命令TXT腳本文件;在工程目錄文件夾內有三個(gè)腳本文件:GenerateSinglePulse.txt、GenerateMultiplePulse.txt、GeneratePulseTriggerIN.txt。 5.3 Microsoft C++ 可以在…\VS2015 Examples\PulseRiderMSVC\TCPIP文件夾內找到C++例程,例程是使用 Microsoft® Visual C++語(yǔ)言編寫(xiě)的。 /*********************************************************************/ /* This example demonstrates opening a simple TCPIP connection and */ /* implements a single pulse generation in Continuous Mode. */ /* */ /* The general flow of the code is */ /* Open Resource Manager */ /* Open a session to the TCP/IP site at NI */ /* Perform write/read, and check properties */ /* Close all VISA Sessions */ /*********************************************************************/ #include "visa.h" #include #include #include static char outputBuffer[VI_FIND_BUFLEN]; static ViSession defaultRM, instr; static ViStatus status; static ViUInt32 count; static char acBuffer[10000000] = ""; static unsigned int u32Timeout = 20000; //timeout value in milliseconds static const char acInstrument[] = "TCPIP::192.168.0.6::INSTR"; // instrument address ViStatus VisaWrite(std::string sInput) { printf("viWrite - %s \n", sInput.c_str()); status = viWrite (instr, (ViBuf)sInput.c_str(), sInput.length(), &count); if (status < VI_SUCCESS) { viStatusDesc(instr, status, outputBuffer); printf("viWrite failed with error code %x - %s\n", status, outputBuffer); viClose(defaultRM); exit (EXIT_FAILURE); } // In case of query command, retrieve the output string memset(outputBuffer, 0, sizeof(outputBuffer)); status = viRead (instr, (ViBuf)outputBuffer, sizeof(outputBuffer), &count); if (status < VI_SUCCESS) { viStatusDesc(instr, status, outputBuffer); printf("viRead failed with error code %x - %s\n",status, outputBuffer); viClose(defaultRM); exit (EXIT_FAILURE); } outputBuffer[strlen(outputBuffer)-1] = 0; if(strlen(outputBuffer) > 0) { printf("The server response is:\n %s\n\n",outputBuffer); } return status; } int main() { int iIndex = 0; FILE* pFile = NULL; ViFindList objFindList; /* First we will need to open the default resource manager. */ status = viOpenDefaultRM (&defaultRM); if (status < VI_SUCCESS) { printf("Could not open a session to the VISA Resource Manager!\n"); exit (EXIT_FAILURE); } status = viFindRsrc (defaultRM, "?*INSTR", &objFindList, &count, outputBuffer); if (status < VI_SUCCESS) { viStatusDesc(instr, status, outputBuffer); printf("viFindRsrc failed with error code %x - %s\n", status, outputBuffer); exit (EXIT_FAILURE); } printf("viFindRsrc - %s\n", outputBuffer); /* Now we will open a session via TCP/IP */ status = viOpen (defaultRM, (ViRsrc) acInstrument, VI_NULL, u32Timeout, &instr); if (status < VI_SUCCESS) { printf ("An error occurred opening the session to %s\n", acInstrument); viClose(defaultRM); exit (EXIT_FAILURE); } // Set the timeout attribute viSetAttribute (instr, VI_ATTR_TMO_VALUE, u32Timeout); //Identify and reset the instrument VisaWrite("*IDN?"); VisaWrite("*RST"); //Set the Channel Parameters VisaWrite("SOURce1 ![]() VisaWrite("SOURce2 ![]() VisaWrite("SOURce1:VOLT:HIGH 1"); VisaWrite("SOURce1:VOLT ![]() VisaWrite("SOURce2:VOLT:HIGH 0.5"); VisaWrite("SOURce2:VOLT ![]() // Set the Pulse Parameters VisaWrite("SOURce1 ![]() VisaWrite("SOURce2 ![]() // Turn On the Outputs VisaWrite("OUTPut1 ON"); VisaWrite("OUTPut2 ON"); // Set the Pulse Mode VisaWrite("SOURce1:PULSe:MODE SINGLE"); // Set the Trigger Mode VisaWrite("TRIGger:MODE CONTinuous"); // Arm the instrument VisaWrite("PULSEGENControl:START"); // Start the generation VisaWrite("*TRG"); status = viClose (instr); status = viClose (defaultRM); printf ("\nHit enter to continue."); fflush(stdin); getchar(); return 0; } |