HI,

I buy a SNMP board for my project and i got some problem to understand SNMP code with VB, Can somenone help me?, i got this code under another project, and i want to use it in my project but, when i copy and paste it in my project, this code got many error, can someone help me to explain it why?

    Private Sub snmpSet(ByVal IPaddress As String, ByVal Port As Integer, ByVal OID As String, ByVal dataType As SByte, ByVal SetValue As String, ByVal Community As String)

        Dim objAPI As adventnet.snmp.snmp2.SnmpAPI = New adventnet.snmp.snmp2.SnmpAPI
        Dim objSession As adventnet.snmp.snmp2.SnmpSession = New adventnet.snmp.snmp2.SnmpSession(objAPI)
        Dim objPDU As adventnet.snmp.snmp2.SnmpPDU = New adventnet.snmp.snmp2.SnmpPDU
        Dim objResultPDU As adventnet.snmp.snmp2.SnmpPDU = New adventnet.snmp.snmp2.SnmpPDU
        Dim objOID As adventnet.snmp.snmp2.SnmpOID = New adventnet.snmp.snmp2.SnmpOID(OID)
        Dim ipIPAddress As System.Net.IPAddress = System.Net.IPAddress.Parse(IPaddress)
        Dim objUDPOpt As adventnet.snmp.snmp2.UDPProtocolOptions = New adventnet.snmp.snmp2.UDPProtocolOptions(ipIPAddress, Port)
        objSession.Version = adventnet.snmp.snmp2.SnmpAPI.SNMP_VERSION_1
        objSession.Open()
        objPDU.DNSLookup = False
        objPDU.ProtocolOptions = objUDPOpt
        objPDU.Command = adventnet.snmp.snmp2.SnmpAPI.SET_REQ_MSG
        objPDU.Community = Community
        Dim myvar As adventnet.snmp.snmp2.SnmpVar = adventnet.snmp.snmp2.SnmpVar.CreateVariable(SetValue, dataType)
        Dim varbind As adventnet.snmp.snmp2.SnmpVarBind = New adventnet.snmp.snmp2.SnmpVarBind(objOID, myvar)
        objPDU.AddVariableBinding(varbind)
        objResultPDU = objSession.SyncSend(objPDU)
        objSession.Close()
        objAPI.Close()
    End Sub


    Private Function snmpGet(ByVal IPaddress As String, ByVal Port As Integer, ByVal OID As String, ByVal Community As String) As adventnet.snmp.snmp2.SnmpPDU
        Dim objSession As adventnet.snmp.snmp2.SnmpSession = Nothing
        Dim objAPI As adventnet.snmp.snmp2.SnmpAPI = Nothing
        Dim objPDU As adventnet.snmp.snmp2.SnmpPDU = Nothing
        Dim objResultPDU As adventnet.snmp.snmp2.SnmpPDU = Nothing
        Dim objOID As adventnet.snmp.snmp2.SnmpOID = Nothing
        Dim objVar As adventnet.snmp.snmp2.SnmpVar = Nothing
        Dim objVarBind As adventnet.snmp.snmp2.SnmpVarBind = Nothing
        Dim objUDPOpt As adventnet.snmp.snmp2.UDPProtocolOptions = Nothing
        Dim ipIPAddress As System.Net.IPAddress = Nothing
        Dim strDebug As String = ""
        Dim strInfo As String = ""
        ipIPAddress = System.Net.IPAddress.Parse(IPaddress)
        objAPI = New adventnet.snmp.snmp2.SnmpAPI
        objSession = New adventnet.snmp.snmp2.SnmpSession(objAPI)
        objPDU = New adventnet.snmp.snmp2.SnmpPDU
        objResultPDU = New adventnet.snmp.snmp2.SnmpPDU
        objUDPOpt = New adventnet.snmp.snmp2.UDPProtocolOptions(ipIPAddress, Port)
        objOID = New adventnet.snmp.snmp2.SnmpOID(OID)
        objSession.Version = adventnet.snmp.snmp2.SnmpAPI.SNMP_VERSION_1
        objSession.Open()
        objPDU.DNSLookup = False
        objPDU.ProtocolOptions = objUDPOpt
        objPDU.Command = adventnet.snmp.snmp2.SnmpAPI.GET_REQ_MSG
        objPDU.Community = Community
        objPDU.AddNull(objOID)
        objResultPDU = objSession.SyncSend(objPDU)
        objSession.Close()
        objAPI.Close()
        Return objResultPDU
    End Function

in solution explorer, i see a folder name Service References but the folder is empty.

Recommended Answers

All 6 Replies

Hi,
What errors do you get and where did you get them?

You need to add a reference in your project to adventnet which I assume is the software that communicates wih your card. - there should be a .dll file somewhere on your machine called aventnet if that is the software that came with your card.

To add a reference you can either open the project properties page and then the References tab Add Reference and browse for the .dll file

OR

In solution explorer ensure the show all files option is on and open the References folder, Right click on it and Add Reference then again browse for the dll file.

Thanks G Waddell,
i think i understand about the reference, but now i cant understand the code under SNMPGet and SNMPSet, for example code line :

Dim objSession As adventnet.snmp.snmp2.SnmpSession = Nothing
objAPI
objPDU and other else

i cant understand function for code like this, i need to understand about this code because i will present this project and explain about code in my project

Hi, Sorry I've never actually done any work with SNMP so I would n't be much help in that regard - is there any documents that came with the hardware? Did you try google?

document about this hardware just explain about how to use it, like volt, pin number, port and other else, but the document didnt explain about code, i try to send email to the hardware company but they said cant explain about the code because its just a sample code.

thanks for your help, my project is done!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.