ActiveX Control For Visual Basic 2005.NET [ 版本 : 1.0] 1 安裝 Windows 驅動程式 請依照下列步驟 : 1. 執行 Windows 驅動程式安裝程式 ( 此範例為 PIO-DIO) 驅動程式位置 : CD:\NAPDOS\PCI\PIO-DIO\dll_ocx\Driver http://ftp.icpdas.com/pub/cd/iocard/pci/napdos/pci/pio-dio/dll_ocx/driver/ Windows 驅動程式只支援 windows 98/NT/2000 及 XP/2003/Vista 32-bit 版本 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 1
2. 按 Next > 按鈕並開始安裝 3. 按 Next > 按鈕並選擇安裝路徑 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 2
4. 按 Install 按鈕繼續安裝程序 5. 選擇 No, I will restart the computer later 並且按 Finish 按鈕 1 2 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 3
2 安裝硬體裝置 請依照下列步驟 : 1. 關掉電腦電源 2. 打開電腦機殼 3. 選擇未使用的 PCI 插槽, 並移除保護裝置 4. 小心插入板卡至 PCI 插槽中, 並以螺絲固定住 5. 裝回電腦機殼 6. 啟動電腦電源 進入 Windows 後, 請依照提示訊息完成 Plug & Play 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 4
3 使用 ActiveX Control (OCX) 在 VB.NET 2005 上使用 ActiveX Control, 請依照下列步驟 : 1. 新增 ActiveX Control (OCX) 到 VB.NET 2005 工具列上 在功能選單上, 選擇 Tools/ Choose Toolbox Items... 1 2 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 5
2. 點選 COM Components 對話框列表裡的 PIODIOX Control 並且按 OK 按鈕 1 2 3 3. 工具列將會顯示 PIODIO (PCI Card OCX) 的元件圖示 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 6
4. 產生一個新的專案 並且新增 PIODIO (PCI Card OCX) 元件到此專案中 1 2 注意 : 請注意, 在.NET 環境上, 所有 OCX 控制元件不能正確處理 Array 型態的參數 因為它們是不同的子系統 在.NET 環境使用 Array 型態的參數時, 你必須直接呼叫 Win32 DLL 函式來代替使用 OCX 控制元件 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 7
4 撰寫 DIO 程式範例 設計 DIO 程式, 在程式中呼叫 OCX 函式 請依照下列步驟 : 1. 設計介面 : etotalboar ComName ListTest btnactive PIODIOX1 btnexit 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 8
2. PIODIOX 函式列表, 如下 : property property property BSTR ErrorString; short ErrorCode; short ActiveBoard; short DriverInit(); long GetConfigAddressSpace(short naddrnum); short GetDllVersion(); short GetDriverVersion(); short InputByte(long IBaseAddr); long InputWord(long IBaseAddr); void OutputByte(long IBaseAddr, short noutputdata); void OutputWord(long IBaseAddr, long IOutputData); short DigitalIn(short nport); void DigitalOut(short nport, short noutputvalue); void SetCounter(short ncounterno, short ncountermode, long ncounterval); long ReadCounter(short ncounterno, short ncountermode); long ResetlrqCount(); void Installlrq(long* hevent, short nlrqsource, short nactivemode); void Removelrq(); void GetlrqCount(); long D48Freq(); void D48Installlrq(long* IHandle, short nlrqmask, short nactivemode); void D48Removelrq(); long D48Getlrqcount(); void SavelrqActiveFlag(); short GetlrqActiveFlag(short FlagNum); void DriverClose(); 更詳細 OCX 函式 資訊 請參考 : ActiveX Control for PCI series boards User's Manual http://ftp.icpdas.com/pub/cd/iocard/pci/napdos/pci/manual/ocx%28activex%29_manual_for_pci _pio_piso_cards.pdf 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 9
3. 函式使用 : Form1_Load Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Integer, wtotalboards As Integer, iboards As Integer Dim wsubaux As Long ' Initialize the driver and get the total boards wtotalboards = PIODIOX1.DriverInit btnactive.text = "Active" etotalboards.text = wtotalboards iboards = 0 For i = 0 To (wtotalboards - 1) PIODIOX1.ActiveBoard = i ' Set the active board wsubaux = PIODIOX1.GetConfigAddressSpace(4) ' Get the AddrBase If 64 = wsubaux Then ComName.Items.Add(Str(i) & ":PIO-D24/56") iboards = iboards + 1 End If Next i If iboards = 0 Then ComName.Items.Add("No Device") btnactive.enabled = False Else btnactive.enabled = True End If ComName.SelectedIndex = 0 End Sub btnexit Private Sub btnexit_click(byval sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.click End Sub PIODIOX1.DriverClose() ' Release the device resource Me.Close() 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 10
btnactive Private Sub btnactive_click(byval sender As System.Object, ByVal e As System.EventArgs) Handles btnactive.click Dim InVal1, InVal2, InVal3 As Integer Dim i As Long PIODIOX1.ActiveBoard = 0 ListTest.Items.Clear() ListTest.Items.Add("Setting Port 0 to Output-Mode and Port 1,2 to Input-mode") ListTest.Items.Add(" ") Thread.Sleep(10) i = 1 While i <= &H80 PIODIOX1.DigitalOut(0, i) '// Port 0 digital output value ListTest.Items.Add("Output Port 0 (Hex)= " + Hex(i)) End Sub Thread.Sleep(100) InVal2 = PIODIOX1.DigitalIn(1) '// Port 1 digital input value InVal3 = PIODIOX1.DigitalIn(2) '// Port 2 digital input value ListTest.Items.Add(" Input Port 2, 1 (Hex)= " _ + Hex(InVal3) + " " _ + Hex(InVal2)) ListTest.Items.Add(" ") Application.DoEvents() Thread.Sleep(100) i = i * 2 End While PIODIOX1.DigitalIn(0) ' Port 0, Back to input mode ListTest.Items.Add( " The End " ) 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 11
AxPIODIOX1_OnError Private Sub AxPIODIOX1_OnError(ByVal sender As System.Object, ByVal e As AxPIODIOXLib._DPIODIOXEvents_OnErrorEvent) Handles PIODIOX1.OnError ' Get the error massage MsgBox("Error Code:" + Str(PIODIOX1.ErrorCode) + Chr(13) + "Error Message:" + PIODIOX1.ErrorString) End Sub Form1_FormClosed Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed PIODIOX1.DriverClose() ' Release the device resource End Sub 5 參考資訊 ActiveX Control for PCI series boards User's Manual http://ftp.icpdas.com/pub/cd/iocard/pci/napdos/pci/manual/ocx%28activex%29_manual_ for_pci_pio_piso_cards.pdf PCI1800X, PCI1602X, PCI1202X ActiveX Control User's Manual http://ftp.icpdas.com/pub/cd/iocard/pci/napdos/pci/manual/ocx%28activex%29_manual_ for_pci_1002_1202_1602_1800_1802.pdf ActiveX Control (OCX) Installation in VB, Delphi and BCB Manual http://ftp.icpdas.com/pub/cd/iocard/pci/napdos/pci/manual/ocx%28activex%29_installati on_in_vb_delphi_bcb.pdf 在 Visual Basic 2005.NET 中使用 ActiveX Control (OCX), Ver.1.0, May/2009, Copyright By ICP DAS ---- 12