pcbway

VB6.0 usb "sub or function not defined" hatası ?

Başlatan ibrahim626, 25 Şubat 2012, 21:29:25

ibrahim626

25 Şubat 2012, 21:29:25 Son düzenlenme: 25 Şubat 2012, 22:04:14 gevv
PIC 18f4550 ile usb bağlantısı kurmaya calısıyorm fakat visual basicde sürekli hata alıyorum nedeni nedir ?



gevv

fonksiyon tanımlanmamış olabilir  ya da fonksiyon kodlarını kapatmadınız

bu editör  hatalı  alanı göstermiyor mu ?

ibrahim626

Hata olarak connectToHID yazan kısmı gösteriyor , visual basic kullanmayı bilmiyorum denenmiş örneklere göre birebir yapıyorum ama bu hatayı veriyor .

gevv

ne yazıkki  bende bilmiyorum :)   ama bu genel bir hata 

kodları  ekleyin en azından bilen kişiler daha kolay yardımcı  olabilir 

yazici67

Resimden çıkartabildiğim kadarıyla çağırdığınız connectToHID metodu tanımlı değil.Büyük ihtimalle kodları aldığınız yerde içeren kütüphanenin eklenmesi unutulmuş.Kodları ve varsa projenin tamamını gönderebilirseniz yardımcı olabilirim.

ibrahim626

Programın Visual basic ve proton kısımlarını ekliyorum , yardımlarınız için şimdiden çok teşekkürler.

\' vendor and product IDs
Private Const VendorID = 6066
Private Const ProductID = 2006

\' read and write buffers
Private Const BufferInSize = 8
Private Const BufferOutSize = 8
Dim BufferIn(0 To BufferInSize) As Byte
Dim BufferOut(0 To BufferOutSize) As Byte

Private Sub Command1_Click()

BufferOut(4) = Val(Text1.Text)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub

Private Sub Form_Load()
\' do not remove!
ConnectToHID (Me.hWnd)
End Sub


Private Sub Form_Unload(Cancel As Integer)
DisconnectFromHID
End Sub

Public Sub OnPlugged(ByVal pHandle As Long)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
\' ** YOUR CODE HERE **
End If
End Sub

Public Sub OnUnplugged(ByVal pHandle As Long)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
\' ** YOUR CODE HERE **
End If
End Sub

Public Sub OnChanged()
Dim DeviceHandle As Long

DeviceHandle = hidGetHandle(VendorID, ProductID)
hidSetReadNotify DeviceHandle, True
End Sub

Public Sub OnRead(ByVal pHandle As Long)

\' read the data (don\'t forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then

End If
End Sub


Public Sub WriteSomeData()
BufferOut(0) = 0 \' first by is always the report ID
BufferOut(1) = 10 \' first data item, etc etc

\' write the data (don\'t forget, pass the whole array)...
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub

Private Sub Text1_Change()
If Val(Text1.Text) > 255 Then Text1.Text = \"\"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
If IsNumeric(Chr(KeyAscii)) = False Then KeyAscii = 0
End Sub

proton basic kısımı

\'****************************************************************
\'*  Name    : USBPROJECT.BAS                                    *
\'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
\'*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *
\'*          : All Rights Reserved                               *
\'*  Date    : 25.02.2012                                        *
\'*  Version : 1.0                                               *
\'*  Notes   :                                                   *
\'*          :                                                   *
\'****************************************************************

\' select MCU and clock speed                                                                                                                                                                                                                                   
Device = 18F4550
XTAL = 48

\' descriptor file, located in \\inc\\usb_18 - a copy
\' is located in the same folder as this file
USB_DESCRIPTOR = \"USBProjectDESC.inc\"

\' USB Buffer...
Symbol USBBufferSizeMax = 8
Symbol USBBufferSizeTX  = 8
Symbol USBBufferSizeRX  = 8
Dim    USBBuffer[USBBufferSizeMax] As Byte
 \' Buffer[1] = PORTA , Buffer[2] = PORTB
\' some useful flags...
Dim PP0 As Byte SYSTEM        \' USBPOLL status return
Symbol CARRY_FLAG = STATUS.0  \' high if microcontroller does not have control over the buffer
Symbol ATTACHED_STATE = 6     \' is USB attached
     
\' ************************************************************
\' * main program loop - remember, you must keep the USB      *
\' * connection alive with a call to USBPoll, USBIn or USBOut *
\' * every couple of milliseconds or so                       *
\' ************************************************************

TRISB = %00000000
GoSub AttachToUSB
ProgramLoop:
   GoSub DoUSBIn
   GoSub DoUSBOut
   GoTo ProgramLoop
   USBBuffer[1] = PORTA \'portA bilgilerini gönderecek
USBOut 1, USBBuffer, USBBufferSizeTX

USBIn 1, USBBuffer, USBBufferSizeRX, ProgramLoop
PORTB = USBBuffer[2] \'buffer2 yi port b de yansıtacak
 
\' ************************************************************
\' * receive data from the USB bus                            *
\' ************************************************************
DoUSBIn:
   USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn
   Return
   
\' ************************************************************
\' * transmit data                                            *
\' ************************************************************
DoUSBOut:   
   USBOut 1, USBBuffer, USBBufferSizeTX, DoUSBOut
   Return

\' ************************************************************
\' * wait for USB interface to attach                         *
\' ************************************************************
AttachToUSB:
   Repeat
      USBPoll
   Until PP0 = ATTACHED_STATE
   Return

davut naci kaya

mcHIDInterface.bas modülünü projenize eklerseniz derleme yapılabilir. Bu modül için mcHID.dll dosyasıda sisteminizde olmalı.

ibrahim626

26 Şubat 2012, 18:07:00 #7 Son düzenlenme: 26 Şubat 2012, 18:11:06 ibrahim626
mcHIDInterface.bas modülü

Attribute VB_Name = \"HIDDLLInterface\"
\' this is the interface to the HID controller DLL - you should not
\' normally need to change anything in this file.
\'
\' WinProc() calls your main form \'event\' procedures - these are currently
\' set to..
\'
\' MainForm.OnPlugged(ByVal pHandle as long)
\' MainForm.OnUnplugged(ByVal pHandle as long)
\' MainForm.OnChanged()
\' MainForm.OnRead(ByVal pHandle as long)

Option Explicit

\' HID interface API declarations...
Declare Function hidConnect Lib \"mcHID.dll\" Alias \"Connect\" (ByVal pHostWin As Long) As Boolean
Declare Function hidDisconnect Lib \"mcHID.dll\" Alias \"Disconnect\" () As Boolean
Declare Function hidGetItem Lib \"mcHID.dll\" Alias \"GetItem\" (ByVal pIndex As Long) As Long
Declare Function hidGetItemCount Lib \"mcHID.dll\" Alias \"GetItemCount\" () As Long
Declare Function hidRead Lib \"mcHID.dll\" Alias \"Read\" (ByVal pHandle As Long, ByRef pData As Byte) As Boolean
Declare Function hidWrite Lib \"mcHID.dll\" Alias \"Write\" (ByVal pHandle As Long, ByRef pData As Byte) As Boolean
Declare Function hidReadEx Lib \"mcHID.dll\" Alias \"ReadEx\" (ByVal pVendorID As Long, ByVal pProductID As Long, ByRef pData As Byte) As Boolean
Declare Function hidWriteEx Lib \"mcHID.dll\" Alias \"WriteEx\" (ByVal pVendorID As Long, ByVal pProductID As Long, ByRef pData As Byte) As Boolean
Declare Function hidGetHandle Lib \"mcHID.dll\" Alias \"GetHandle\" (ByVal pVendoID As Long, ByVal pProductID As Long) As Long
Declare Function hidGetVendorID Lib \"mcHID.dll\" Alias \"GetVendorID\" (ByVal pHandle As Long) As Long
Declare Function hidGetProductID Lib \"mcHID.dll\" Alias \"GetProductID\" (ByVal pHandle As Long) As Long
Declare Function hidGetVersion Lib \"mcHID.dll\" Alias \"GetVersion\" (ByVal pHandle As Long) As Long
Declare Function hidGetVendorName Lib \"mcHID.dll\" Alias \"GetVendorName\" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long
Declare Function hidGetProductName Lib \"mcHID.dll\" Alias \"GetProductName\" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long
Declare Function hidGetSerialNumber Lib \"mcHID.dll\" Alias \"GetSerialNumber\" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long
Declare Function hidGetInputReportLength Lib \"mcHID.dll\" Alias \"GetInputReportLength\" (ByVal pHandle As Long) As Long
Declare Function hidGetOutputReportLength Lib \"mcHID.dll\" Alias \"GetOutputReportLength\" (ByVal pHandle As Long) As Long
Declare Sub hidSetReadNotify Lib \"mcHID.dll\" Alias \"SetReadNotify\" (ByVal pHandle As Long, ByVal pValue As Boolean)
Declare Function hidIsReadNotifyEnabled Lib \"mcHID.dll\" Alias \"IsReadNotifyEnabled\" (ByVal pHandle As Long) As Boolean
Declare Function hidIsAvailable Lib \"mcHID.dll\" Alias \"IsAvailable\" (ByVal pVendorID As Long, ByVal pProductID As Long) As Boolean

\' windows API declarations - used to set up messaging...
Private Declare Function CallWindowProc Lib \"user32\" Alias \"CallWindowProcA\" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib \"user32\" Alias \"SetWindowLongA\" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

\' windows API Constants
Private Const WM_APP = 32768
Private Const GWL_WNDPROC = -4

\' HID message constants
Private Const WM_HID_EVENT = WM_APP + 200
Private Const NOTIFY_PLUGGED = 1
Private Const NOTIFY_UNPLUGGED = 2
Private Const NOTIFY_CHANGED = 3
Private Const NOTIFY_READ = 4

\' local variables
Private FPrevWinProc As Long    \' Handle to previous window procedure
Private FWinHandle As Long      \' Handle to message window

\' Set up a windows hook to receive notification
\' messages from the HID controller DLL - then connect
\' to the controller
Public Function ConnectToHID(ByVal pHostWin As Long) As Boolean
   FWinHandle = pHostWin
   ConnectToHID = hidConnect(FWinHandle)
   FPrevWinProc = SetWindowLong(FWinHandle, GWL_WNDPROC, AddressOf WinProc)
End Function

\' Unhook from the HID controller and disconnect...
Public Function DisconnectFromHID() As Boolean
   DisconnectFromHID = hidDisconnect
   SetWindowLong FWinHandle, GWL_WNDPROC, FPrevWinProc
End Function

\' This is the procedure that intercepts the HID controller messages...
Private Function WinProc(ByVal pHWnd As Long, ByVal pMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   If pMsg = WM_HID_EVENT Then
       Select Case wParam
       
        \' HID device has been plugged message...
        Case Is = NOTIFY_PLUGGED
           MainForm.OnPlugged (lParam)

        \' HID device has been unplugged
        Case Is = NOTIFY_UNPLUGGED
           MainForm.OnUnplugged (lParam)
       
        \' controller has changed...
        Case Is = NOTIFY_CHANGED
           MainForm.OnChanged

        \' read event...
        Case Is = NOTIFY_READ
           MainForm.OnRead (lParam)
        End Select
   
   End If
   
   \' next...
   WinProc = CallWindowProc(FPrevWinProc, pHWnd, pMsg, wParam, lParam)
   
End Function

yazici67

VB6.0 IDE sini kullanmadım ama proje  dosyaları bölümünden mcHIDInterface.bas dosyasını eklerseniz proje sorunsuzca derlenir.

yazici67


ibrahim626

yazıcı67 cok tesekkur ederım yardımın için sayende sorun cozuldu.

yazici67