各位好,小弟最近想把之前Labview寫的控制程式移到CVI上,Labview上他的COM Port就本身內建偵測可用的PORT
但此功能CVI上小弟目前尚寫不出來,請問有什麼辦法能夠讀取可用的COM PORT?
小弟嘗試"GetComConnectionState"不過都無法讀出回應值,會直接跳Runtime Error然後自動停止,
在"CetComConnectionState" 之後加 "ReturnRS232Err" 嘗試讀出這行Error也是同樣無法運行,依然會跳出NON FATAL RUNTIME ERROR
照理說"ReturnRS232Err"應該就能夠讀出錯誤並且防止跳出了,請問有什麼可以參考的文件或是網頁嗎? 謝謝各位
在 01-21-2013 03:38 AM
CVI裡面好像真的沒有辦法寫出這種功能,我找到最接近的是用Windows API去檢查輸入的COM Port是否正確。
http://digital.ni.com/public.nsf/allkb/37EC9685EC1C87B4862579D1004095C7
如果不正確會要求重新輸入。
但是這種做法跟原本CVI隨附的範例serial.cws好像是一樣的,沒有辦法直接enumerate COM Port出來。
就算用了Find VISA Resource的範例好像也是不行,範例裡面有如下的解釋。
/*********************************************************************/
/* This example demonstrates how you might query your system for */
/* a particular instrument. This example queries for all */
/* GPIB, serial or VXI instruments. Notice that VISA is able to */
/* find GPIB and VXI instruments because the instruments have a */
/* predefined protocol. But serial instruments do not. Hence, */
/* VISA merely indicates that a serial port is available. */
/* */
/* The general flow of the code is */
/* Open Resource Manager */
/* Use viFindRsrc() to query for the first available instrument */
/* Open a session to this device */
/* Find the next instrument using viFindNext() */
/* Open a session to this device. */
/* Loop on finding the next instrument until all have been found*/
/* Close all VISA Sessions */
/*********************************************************************/
所以我想在CVI裡面應該是目前還沒有辦法做到自動列舉COM Port的功能
原來如此,哪可以順便請問一下,GetComConnectionState跟ReturnRS232Err個別是什麼功能嗎?
因為小弟依照著Guide上的說明使用此指令都無法在Runtime下順利執行,所以有點好奇這是做什麼用的,謝謝你