SNMP Connection With VB

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
HI,
I buy a SNMP board DAEnetIP2 for my Final Year 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?
<pre class="prettyprint linenums <ol>
Code:
<span class="pln     <span class="kwd Private<span class="pln  <span class="kwd Sub<span class="pln  snmpSet<span class="pun (<span class="kwd ByVal<span class="pln  IPaddress <span class="kwd As<span class="pln  <span class="kwd String<span class="pun ,<span class="pln  <span class="kwd ByVal<span class="pln  Port <span class="kwd As<span class="pln  <span class="kwd Integer<span class="pun ,<span class="pln  <span class="kwd ByVal<span class="pln  OID <span class="kwd As<span class="pln  <span class="kwd String<span class="pun ,<span class="pln  <span class="kwd ByVal<span class="pln  dataType <span class="kwd As<span class="pln  SByte<span class="pun ,<span class="pln  <span class="kwd ByVal<span class="pln  SetValue <span class="kwd As<span class="pln  <span class="kwd String<span class="pun ,<span class="pln  <span class="kwd ByVal<span class="pln  Community <span class="kwd As<span class="pln  <span class="kwd String<span class="pun )
Code:
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objAPI <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpAPI <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpAPI
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objSession <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpSession <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpSession<span class="pun (<span class="pln objAPI<span class="pun )
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objPDU <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpPDU <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpPDU
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objResultPDU <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpPDU <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpPDU
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objOID <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpOID <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpOID<span class="pun (<span class="pln OID<span class="pun )
Code:
<span class="pln         <span class="kwd Dim<span class="pln  ipIPAddress <span class="kwd As<span class="pln  System<span class="pun .<span class="pln Net<span class="pun .<span class="pln IPAddress <span class="pun =<span class="pln  System<span class="pun .<span class="pln Net<span class="pun .<span class="pln IPAddress<span class="pun .<span class="pln Parse<span class="pun (<span class="pln IPaddress<span class="pun )
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objUDPOpt <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln UDPProtocolOptions <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln UDPProtocolOptions<span class="pun (<span class="pln ipIPAddress<span class="pun ,<span class="pln  Port<span class="pun )
Code:
<span class="pln         objSession<span class="pun .<span class="pln Version <span class="pun =<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpAPI<span class="pun .<span class="pln SNMP_VERSION_1
Code:
<span class="pln         objSession<span class="pun .<span class="pln Open<span class="pun ()
Code:
<span class="pln         objPDU<span class="pun .<span class="pln DNSLookup <span class="pun =<span class="pln  <span class="lit False
Code:
<span class="pln         objPDU<span class="pun .<span class="pln ProtocolOptions <span class="pun =<span class="pln  objUDPOpt
Code:
<span class="pln         objPDU<span class="pun .<span class="pln Command <span class="pun =<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpAPI<span class="pun .<span class="pln SET_REQ_MSG
Code:
<span class="pln         objPDU<span class="pun .<span class="pln Community <span class="pun =<span class="pln  Community
Code:
<span class="pln         <span class="kwd Dim<span class="pln  myvar <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpVar <span class="pun =<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpVar<span class="pun .<span class="pln CreateVariable<span class="pun (<span class="pln SetValue<span class="pun ,<span class="pln  dataType<span class="pun )
Code:
<span class="pln         <span class="kwd Dim<span class="pln  varbind <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpVarBind <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpVarBind<span class="pun (<span class="pln objOID<span class="pun ,<span class="pln  myvar<span class="pun )
Code:
<span class="pln         objPDU<span class="pun .<span class="pln AddVariableBinding<span class="pun (<span class="pln varbind<span class="pun )
Code:
<span class="pln         objResultPDU <span class="pun =<span class="pln  objSession<span class="pun .<span class="pln SyncSend<span class="pun (<span class="pln objPDU<span class="pun )
Code:
<span class="pln         objSession<span class="pun .<span class="pln Close<span class="pun ()
Code:
<span class="pln         objAPI<span class="pun .<span class="pln Close<span class="pun ()
Code:
<span class="pln     <span class="kwd End<span class="pln  <span class="kwd Sub
Code:
Code:
Code:
<span class="pln     <span class="kwd Private<span class="pln  <span class="kwd Function<span class="pln  snmpGet<span class="pun (<span class="kwd ByVal<span class="pln  IPaddress <span class="kwd As<span class="pln  <span class="kwd String<span class="pun ,<span class="pln  <span class="kwd ByVal<span class="pln  Port <span class="kwd As<span class="pln  <span class="kwd Integer<span class="pun ,<span class="pln  <span class="kwd ByVal<span class="pln  OID <span class="kwd As<span class="pln  <span class="kwd String<span class="pun ,<span class="pln  <span class="kwd ByVal<span class="pln  Community <span class="kwd As<span class="pln  <span class="kwd String<span class="pun )<span class="pln  <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpPDU
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objSession <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpSession <span class="pun =<span class="pln  <span class="lit Nothing
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objAPI <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpAPI <span class="pun =<span class="pln  <span class="lit Nothing
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objPDU <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpPDU <span class="pun =<span class="pln  <span class="lit Nothing
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objResultPDU <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpPDU <span class="pun =<span class="pln  <span class="lit Nothing
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objOID <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpOID <span class="pun =<span class="pln  <span class="lit Nothing
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objVar <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpVar <span class="pun =<span class="pln  <span class="lit Nothing
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objVarBind <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpVarBind <span class="pun =<span class="pln  <span class="lit Nothing
Code:
<span class="pln         <span class="kwd Dim<span class="pln  objUDPOpt <span class="kwd As<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln UDPProtocolOptions <span class="pun =<span class="pln  <span class="lit Nothing
Code:
<span class="pln         <span class="kwd Dim<span class="pln  ipIPAddress <span class="kwd As<span class="pln  System<span class="pun .<span class="pln Net<span class="pun .<span class="pln IPAddress <span class="pun =<span class="pln  <span class="lit Nothing
Code:
<span class="pln         <span class="kwd Dim<span class="pln  strDebug <span class="kwd As<span class="pln  <span class="kwd String<span class="pln  <span class="pun =<span class="pln  <span class="str &quot;&quot;
Code:
<span class="pln         <span class="kwd Dim<span class="pln  strInfo <span class="kwd As<span class="pln  <span class="kwd String<span class="pln  <span class="pun =<span class="pln  <span class="str &quot;&quot;
Code:
<span class="pln         ipIPAddress <span class="pun =<span class="pln  System<span class="pun .<span class="pln Net<span class="pun .<span class="pln IPAddress<span class="pun .<span class="pln Parse<span class="pun (<span class="pln IPaddress<span class="pun )
Code:
<span class="pln         objAPI <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpAPI
Code:
<span class="pln         objSession <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpSession<span class="pun (<span class="pln objAPI<span class="pun )
Code:
<span class="pln         objPDU <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpPDU
Code:
<span class="pln         objResultPDU <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpPDU
Code:
<span class="pln         objUDPOpt <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln UDPProtocolOptions<span class="pun (<span class="pln ipIPAddress<span class="pun ,<span class="pln  Port<span class="pun )
Code:
<span class="pln         objOID <span class="pun =<span class="pln  <span class="kwd New<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpOID<span class="pun (<span class="pln OID<span class="pun )
Code:
<span class="pln         objSession<span class="pun .<span class="pln Version <span class="pun =<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpAPI<span class="pun .<span class="pln SNMP_VERSION_1
Code:
<span class="pln         objSession<span class="pun .<span class="pln Open<span class="pun ()
Code:
<span class="pln         objPDU<span class="pun .<span class="pln DNSLookup <span class="pun =<span class="pln  <span class="lit False
Code:
<span class="pln         objPDU<span class="pun .<span class="pln ProtocolOptions <span class="pun =<span class="pln  objUDPOpt
Code:
<span class="pln         objPDU<span class="pun .<span class="pln Command <span class="pun =<span class="pln  adventnet<span class="pun .<span class="pln snmp<span class="pun .<span class="pln snmp2<span class="pun .<span class="pln SnmpAPI<span class="pun .<span class="pln GET_REQ_MSG
Code:
<span class="pln         objPDU<span class="pun .<span class="pln Community <span class="pun =<span class="pln  Community
Code:
<span class="pln         objPDU<span class="pun .<span class="pln AddNull<span class="pun (<span class="pln objOID<span class="pun )
Code:
<span class="pln         objResultPDU <span class="pun =<span class="pln  objSession<span class="pun .<span class="pln SyncSend<span class="pun (<span class="pln objPDU<span class="pun )
Code:
<span class="pln         objSession<span class="pun .<span class="pln Close<span class="pun ()
Code:
<span class="pln         objAPI<span class="pun .<span class="pln Close<span class="pun ()
Code:
<span class="pln         <span class="kwd Return<span class="pln  objResultPDU
Code:
<span class="pln     <span class="kwd End<span class="pln  <span class="kwd Function
</ol>[/code]
in solution explorer, i see a folder name Service References but the folder is empty.
please help me, im still new about this....

<br/>

View the full article
 
Back
Top