Thông báo

Collapse
No announcement yet.

Giao tiêp· GPIB với máy tính

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Giao tiêp· GPIB với máy tính

    Trong quá trình làm việc mình gặp rất nhiều máy điều khiển qua công GPIB, nhưng hầu hết chúng ta đều quen thuộc với cổng RS232. Hôm nay mình sẽ hướng dẫn các bạn giao tiếp cổng GPIB với máy tính bằng phần mền Visial Studio. Để giao tiếp được với máy tính trước hết các bạn cài driver cho cổng GPIB, mỗi hãng sẽ có driver khác nhau: Agilent, NI... Mình dùng cổng GPIB của Agilent điều khiển Multimeter 34401A với máy tính. Driver của Agilent là IOLibSuite.
    Các bạn mở Visual Studio và tạo 1 project mới, sau đó thêm thư viện Visa Com 3.0 bằng cách click chuột vào Project/Add Reference/Com rồi chọn Visa Com 3.0 Type Library.

    Click image for larger version

Name:	Visa Com.jpg
Views:	908
Size:	99.0 KB
ID:	1728124

    Trong phần form design các bạn tạo button và checkbox như hình dưới đây

    Click image for larger version

Name:	Form.jpg
Views:	638
Size:	13.5 KB
ID:	1728125

    Checkbox Address là địa chỉ cổng GPIB, địa chỉ cổng GPIB trên 34401A và trên phần mền phải giống nhau, ví dụ mình để là 1
    Bây giờ đến phần viết code.

    Button Send:
    Dim ioMgr As Ivi.Visa.Interop.ResourceManager
    Dim instrument As Ivi.Visa.Interop.FormattedIO488
    ioMgr = New Ivi.Visa.Interop.ResourceManager
    instrument = New Ivi.Visa.Interop.FormattedIO488
    instrument.IO = ioMgr.Open("GPIB0::22")
    System.Threading.Thread.Sleep(100)
    System.Threading.Thread.Sleep(100)
    instrument.WriteString("*RST" & vbCrLf)
    System.Threading.Thread.Sleep(100)
    instrument.WriteString("*CLS" & vbCrLf)
    System.Threading.Thread.Sleep(100)
    instrument.WriteString(TextBox1.Text & vbCrLf)

    Button Read DMM:
    Dim ioMgr As Ivi.Visa.Interop.ResourceManager
    Dim instrument As Ivi.Visa.Interop.FormattedIO488
    ioMgr = New Ivi.Visa.Interop.ResourceManager
    instrument = New Ivi.Visa.Interop.FormattedIO488
    instrument.IO = ioMgr.Open("GPIB0::22")
    System.Threading.Thread.Sleep(100)
    System.Threading.Thread.Sleep(100)
    instrument.WriteString("*RST" & vbCrLf)
    System.Threading.Thread.Sleep(100)
    instrument.WriteString("*CLS" & vbCrLf)
    System.Threading.Thread.Sleep(100)
    instrument.WriteString(":MEASURE:VOLTAGEC ?" & vbCrLf)
    System.Threading.Thread.Sleep(100)
    idn = instrument.ReadString()
    idn = Mid(idn, 2, 6)
    TextBox1.Text = idn & " V"

    Form load:
    ComboBox1.Items.Add("4")
    ComboBox1.Items.Add("10")
    ComboBox1.Items.Add("22")
    ComboBox1.Items.Add("23")
    ComboBox1.Items.Add("1")
    ComboBox1.Items.Add("2")
    ComboBox1.Items.Add("3")
    ComboBox1.Items.Add("5")
    ComboBox1.SelectedItem = ComboBox1.Items(3)

    Chúc các bạn thành công!

Về tác giả

Collapse

sunset Tìm hiểu thêm về sunset

Bài viết mới nhất

Collapse

Đang tải...
X