IP, Submaske, Gateway und Port in Memory schreiben und lesen

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • Hi Six1,

      ich habe mein code auf Basis von deinem veränder.
      Mit einem Taster am AVR, schreibe ich alle Daten in den EEPROM
      wie folgt:

      BASCOM-Quellcode

      1. Dim Setip_e As Eram String * 16
      2. Dim Setsubmaske_e As Eram String * 16
      3. Dim Setgateway_e As Eram String * 16
      4. Dim Setport_e As Eram String * 4
      5. Dim Setip(4) As String * 3
      6. Dim Setsubmaske(4) As String * 3
      7. Dim Setgateway(4) As String * 3
      8. Dim Setip_p As Long
      9. Dim Setsubmaske_p As Long
      10. Dim Setgateway_p As Long
      11. Dim Ipa As Byte
      12. Ipa = Split(setip_e , Setip(1) , ".")
      13. Setip_p = Maketcp(setip(1) , Setip(2) , Setip(3) , Setip(4))
      14. Ipa = Split(setsubmaske_e , Setip(1) , ".")
      15. Setsubmaske_p = Maketcp(setip(1) , Setip(2) , Setip(3) , Setip(4))
      16. Ipa = Split(setgateway_e , Setip(1) , ".")
      17. Setgateway_p = Maketcp(setip(1) , Setip(2) , Setip(3) , Setip(4))
      18. Print Setip(1) ; Setip(2) ; Setip(3) ; Setip(4)
      19. Setport = Setport_e
      20. Config Tcpip = Int0 , Mac = 0.8.220.77.05.11 , Ip = 192.168.178.29 , Submask = 255.255.255.0 , Gateway = 192.168.178.1 , Localport = 2005 , Chip = W5500 , Spi = 1 , Cs = Portb.4
      21. Local_port = Val(setport)
      22. Settcp 0.8.220.77.05.11 , Setip_p , Setsubmaske_p , Setgateway_p
      23. 'Nach dem betätigen der Taster am AVR
      24. Ippreset:
      25. Setip_e = "192.168.178.29"
      26. Setsubmaske_e = "255.255.255.0"
      27. Setgateway_e = "192.168.178.1"
      28. Setport_e = "2005"
      29. Goto _reset
      Alles anzeigen
      Leider liefert mit der Print jetzt unlesbare Zeichen.
      Warum eigentlich?

      VG
      Katip
    • six1 schrieb:

      Bald geht es...
      So jetzt habe ich mal deine Variablen verwendet.


      BASCOM-Quellcode

      1. '######################### VARIABLEN FÜR DIE ETHERNET VERBINDUNG ###############
      2. Dim Ee_ip(4) As Eram Byte 'At 4
      3. Dim Ee_mask(4) As Eram Byte 'At 6
      4. Dim Ee_gateway(4) As Eram Byte 'At 14
      5. Dim Ee_port As Eram Long 'At 18
      6. Dim Eth_ip(4) As Byte
      7. Dim Eth_mask(4) As Byte
      8. Dim Eth_gateway(4) As Byte
      9. Dim Eth_port As Long
      10. Dim Ip_ As Long
      11. Dim Subnetmask_ As Long
      12. Dim Gateway_ As Long
      13. Dim Port_ As Long
      14. Gosub Set_eth_values
      15. Config Tcpip = Int0 , Mac = 0.8.220.77.05.11 , Ip = Ip_ , Submask = Subnetmask_ , Gateway = Gateway_ , Localport = 2005 , Chip = W5500 , Spi = 1 , Cs = Portb.4
      16. Local_port = Port_
      17. Settcp 0.8.220.77.05.11 , Ip_ , Subnetmask_ , Gateway_
      18. '######################## ENDE DER ETHERNET VARIABLEN ##########################
      19. Set_ip_reset: 'Wird durch eine Taste getriggert
      20. Do
      21. Eth_ip(1) = 192 : Eth_ip(2) = 168 : Eth_ip(3) = 178 : Eth_ip(4) = 29
      22. Eth_mask(1) = 255 : Eth_mask(2) = 255 : Eth_mask(3) = 255 : Eth_mask(4) = 0
      23. Eth_gateway(1) = 192 : Eth_gateway(2) = 168 : Eth_gateway(3) = 178 : Eth_gateway(4) = 1
      24. Eth_port = 2005
      25. Ee_ip(1) = Eth_ip(1) : Ee_ip(2) = Eth_ip(2) : Ee_ip(3) = Eth_ip(3) : Ee_ip(4) = Eth_ip(4)
      26. Ee_mask(1) = Eth_mask(1) : Ee_mask(2) = Eth_mask(2) : Ee_mask(3) = Eth_mask(3) : Ee_mask(4) = Eth_mask(4)
      27. Ee_gateway(1) = Eth_gateway(1) : Ee_gateway(2) = Eth_gateway(2) : Ee_gateway(3) = Eth_gateway(3) : Ee_gateway(4) = Eth_gateway(4)
      28. Ee_port = Eth_port
      29. Exit Do
      30. Loop
      31. Goto _reset
      32. '-------------------------------------------------------------------------------
      33. Set_eth_values:
      34. Eth_ip(1) = Ee_ip(1) : Eth_ip(2) = Ee_ip(2) : Eth_ip(3) = Ee_ip(3) : Eth_ip(4) = Ee_ip(4)
      35. Eth_mask(1) = Ee_mask(1) : Eth_mask(2) = Ee_mask(2) : Eth_mask(3) = Ee_mask(3) : Eth_mask(4) = Ee_mask(4)
      36. Eth_gateway(1) = Ee_gateway(1) : Eth_gateway(2) = Ee_gateway(2) : Eth_gateway(3) = Ee_gateway(3) : Eth_gateway(4) = Ee_gateway(4)
      37. Eth_port = Ee_port
      38. Ip_ = Maketcp(eth_ip(1) , Eth_ip(2) , Eth_ip(3) , Eth_ip(4))
      39. Subnetmask_ = Maketcp(eth_mask(1) , Eth_mask(2) , Eth_mask(3) , Eth_mask(4) )
      40. Gateway_ = Maketcp(eth_gateway(1) , Eth_gateway(2) , Eth_gateway(3) , Eth_gateway(4))
      41. Port_ = Eth_port
      42. Print Ip_ ; Subnetmask_ ; Gateway_ ; Port_
      43. Return
      44. '-------------------------------------------------------------------------------
      Alles anzeigen
      geliefert bekomme ich im HyperTerminal folgende Zeile:
      -1071775745-256-10626862072005

      Was mache ich jetzt falsch?
    • BASCOM-Quellcode

      1. Ee_ip(1) = Eth_ip(1) : Ee_ip(2) = Eth_ip(2) : Ee_ip(3) = Eth_ip(3) : Ee_ip(4) = Eth_ip(4)
      2. Ee_mask(1) = Eth_mask(1) : Ee_mask(2) = Eth_mask(2) : Ee_mask(3) = Eth_mask(3) : Ee_mask(4) = Eth_mask(4)
      3. Ee_gateway(1) = Eth_gateway(1) : Ee_gateway(2) = Eth_gateway(2) : Ee_gateway(3) = Eth_gateway(3) : Ee_gateway(4) = Eth_gateway(4)
      4. Ee_port = Eth_port
      Oh Oh, mach das bitte nie in der Hauptschleife, da dein EEProm wesentlich weniger Schreibzyklen hat als der Flash.
      Das EEProm am besten immer in einer separaten Sub lesen und schreiben und danach immer nur mit den normalen Variablen arbeiten.
      Eine Lösung habe ich nicht, aber mir gefällt Ihr Problem.
    • Nix, dein print printet eben die long-Variable. Da sind keine Punkte zwischen den einzelnen bytes. Setzte doch mal über die long ein overlay mit 4 bytes und printe die. Oder printe einfach mal die Eth-Variablen.
      Raum für Notizen

      -----------------------------------------------------------------------------------------------------

      -----------------------------------------------------------------------------------------------------
    • Hall Zusammen,

      jetzt funktioniert es a_14_3ef964b0 a_14_3ef964b0 a_14_3ef964b0

      BASCOM-Quellcode

      1. '######################### VARIABLEN FÜR DIE ETHERNET VERBINDUNG ###############
      2. Dim Ee_ip(4) As Eram Byte 'At 4
      3. Dim Ee_mask(4) As Eram Byte 'At 6
      4. Dim Ee_gateway(4) As Eram Byte 'At 14
      5. Dim Ee_port As Eram String * 4 'At 18
      6. Dim Eth_ip(4) As Byte
      7. Dim Eth_mask(4) As Byte
      8. Dim Eth_gateway(4) As Byte
      9. Dim Eth_port As String * 4
      10. Dim Ip_ As Long
      11. Dim Subnetmask_ As Long
      12. Dim Gateway_ As Long
      13. Dim Port_ As Long
      14. Gosub Set_eth_values
      15. Config Tcpip = Int0 , Mac = 0.8.220.77.05.11 , Ip = Ip_ , Submask = Subnetmask_ , Gateway = Gateway_ , Localport = 2005 , Chip = W5500 , Spi = 1 , Cs = Portb.4
      16. Local_port = Port_
      17. Settcp 0.8.220.77.05.11 , Ip_ , Subnetmask_ , Gateway_
      18. '######################## ENDE DER ETHERNET VARIABLEN ##########################
      19. Set_ip_reset:
      20. Do
      21. Eth_ip(1) = 192 : Eth_ip(2) = 168 : Eth_ip(3) = 178 : Eth_ip(4) = 29
      22. Eth_mask(1) = 255 : Eth_mask(2) = 255 : Eth_mask(3) = 255 : Eth_mask(4) = 0
      23. Eth_gateway(1) = 192 : Eth_gateway(2) = 168 : Eth_gateway(3) = 178 : Eth_gateway(4) = 1
      24. Eth_port = "2005"
      25. Ee_ip(1) = Eth_ip(1) : Ee_ip(2) = Eth_ip(2) : Ee_ip(3) = Eth_ip(3) : Ee_ip(4) = Eth_ip(4)
      26. Ee_mask(1) = Eth_mask(1) : Ee_mask(2) = Eth_mask(2) : Ee_mask(3) = Eth_mask(3) : Ee_mask(4) = Eth_mask(4)
      27. Ee_gateway(1) = Eth_gateway(1) : Ee_gateway(2) = Eth_gateway(2) : Ee_gateway(3) = Eth_gateway(3) : Ee_gateway(4) = Eth_gateway(4)
      28. Ee_port = Eth_port
      29. Exit Do
      30. Loop
      31. Goto _reset
      32. '-------------------------------------------------------------------------------
      33. Set_eth_values:
      34. Eth_ip(1) = Ee_ip(1) : Eth_ip(2) = Ee_ip(2) : Eth_ip(3) = Ee_ip(3) : Eth_ip(4) = Ee_ip(4)
      35. Eth_mask(1) = Ee_mask(1) : Eth_mask(2) = Ee_mask(2) : Eth_mask(3) = Ee_mask(3) : Eth_mask(4) = Ee_mask(4)
      36. Eth_gateway(1) = Ee_gateway(1) : Eth_gateway(2) = Ee_gateway(2) : Eth_gateway(3) = Ee_gateway(3) : Eth_gateway(4) = Ee_gateway(4)
      37. Eth_port = Ee_port
      38. Ip_ = Maketcp(eth_ip(1) , Eth_ip(2) , Eth_ip(3) , Eth_ip(4))
      39. Subnetmask_ = Maketcp(eth_mask(1) , Eth_mask(2) , Eth_mask(3) , Eth_mask(4) )
      40. Gateway_ = Maketcp(eth_gateway(1) , Eth_gateway(2) , Eth_gateway(3) , Eth_gateway(4))
      41. Port_ = Val(eth_port)
      42. Return
      43. '-------------------------------------------------------------------------------
      44. Setnewip:
      45. Dim Ip_trenn(4) As String * 3 , Mask_trenn(4) As String * 3 , Gateway_trenn(4) As String * 3
      46. Dim Temp_a As Byte , Temp_b As Byte , Temp_c As Byte
      47. Dim Ip_val(4) As Byte , Mask_val(4) As Byte , Gateway_val(4) As Byte
      48. Temp_a = Split(command_array(2) , Ip_trenn(1) , ".")
      49. Temp_b = Split(command_array(3) , Mask_trenn(1) , ".")
      50. Temp_c = Split(command_array(4) , Gateway_trenn(1) , ".")
      51. Ip_val(1) = Val(ip_trenn(1)) : Ip_val(2) = Val(ip_trenn(2)) : Ip_val(3) = Val(ip_trenn(3)) : Ip_val(4) = Val(ip_trenn(4))
      52. Mask_val(1) = Val(mask_trenn(1)) : Mask_val(2) = Val(mask_trenn(2)) : Mask_val(3) = Val(mask_trenn(3)) : Mask_val(4) = Val(mask_trenn(4))
      53. Gateway_val(1) = Val(gateway_trenn(1)) : Gateway_val(2) = Val(gateway_trenn(2)) : Gateway_val(3) = Val(gateway_trenn(3)) : Gateway_val(4) = Val(gateway_trenn(4))
      54. Do
      55. 'Die Daten erst in eine Variable schreiben
      56. Eth_ip(1) = Ip_val(1) : Eth_ip(2) = Ip_val(2) : Eth_ip(3) = Ip_val(3) : Eth_ip(4) = Ip_val(4)
      57. Eth_mask(1) = Mask_val(1) : Eth_mask(2) = Mask_val(2) : Eth_mask(3) = Mask_val(3) : Eth_mask(4) = Mask_val(4)
      58. Eth_gateway(1) = Gateway_val(1) : Eth_gateway(2) = Gateway_val(2) : Eth_gateway(3) = Gateway_val(3) : Eth_gateway(4) = Gateway_val(4)
      59. Eth_port = Command_array(5)
      60. 'Jetzt die Daten vom Variablen in den EEPROM schreiben
      61. Ee_ip(1) = Eth_ip(1) : Ee_ip(2) = Eth_ip(2) : Ee_ip(3) = Eth_ip(3) : Ee_ip(4) = Eth_ip(4)
      62. Ee_mask(1) = Eth_mask(1) : Ee_mask(2) = Eth_mask(2) : Ee_mask(3) = Eth_mask(3) : Ee_mask(4) = Eth_mask(4)
      63. Ee_gateway(1) = Eth_gateway(1) : Ee_gateway(2) = Eth_gateway(2) : Ee_gateway(3) = Eth_gateway(3) : Ee_gateway(4) = Eth_gateway(4)
      64. Ee_port = Eth_port
      65. Result1 = Tcpwrite(idx , "NewIP")
      66. Exit Do
      67. Loop
      68. Return
      69. Getnewip:
      70. Do
      71. B = "GetIPConfig|" + Str(eth_ip(1)) + "." + Str(eth_ip(2)) + "." + Str(eth_ip(3)) + "." + Str(eth_ip(4)) + "|" + _
      72. Str(eth_mask(1)) + "." + Str(eth_mask(2)) + "." + Str(eth_mask(3)) + "." + Str(eth_mask(4)) + "|" + _
      73. Str(eth_gateway(1)) + "." + Str(eth_gateway(2)) + "." + Str(eth_gateway(3)) + "." + Str(eth_gateway(4)) + "|" + _
      74. Eth_port + "|"
      75. Result1 = Tcpwritestr(idx , B , 255 )
      76. Exit Do
      77. Loop
      78. Return
      Alles anzeigen
    • DHCP ist Ein Protokoll... kannst ja mal die RFC2131 nachschauen, ob du es kleiner hin bekommst

      ietf.org/rfc/rfc2131.txt

      das ist das Schma in ASCII aus der RFC

      Quellcode

      1. RFC 2131 Dynamic Host Configuration Protocol March 1997
      2. -------- -------
      3. | | +-------------------------->| |<-------------------+
      4. | INIT- | | +-------------------->| INIT | |
      5. | REBOOT |DHCPNAK/ +---------->| |<---+ |
      6. | |Restart| | ------- | |
      7. -------- | DHCPNAK/ | | |
      8. | Discard offer | -/Send DHCPDISCOVER |
      9. -/Send DHCPREQUEST | | |
      10. | | | DHCPACK v | |
      11. ----------- | (not accept.)/ ----------- | |
      12. | | | Send DHCPDECLINE | | |
      13. | REBOOTING | | | | SELECTING |<----+ |
      14. | | | / | | |DHCPOFFER/ |
      15. ----------- | / ----------- | |Collect |
      16. | | / | | | replies |
      17. DHCPACK/ | / +----------------+ +-------+ |
      18. Record lease, set| | v Select offer/ |
      19. timers T1, T2 ------------ send DHCPREQUEST | |
      20. | +----->| | DHCPNAK, Lease expired/ |
      21. | | | REQUESTING | Halt network |
      22. DHCPOFFER/ | | | |
      23. Discard ------------ | |
      24. | | | | ----------- |
      25. | +--------+ DHCPACK/ | | |
      26. | Record lease, set -----| REBINDING | |
      27. | timers T1, T2 / | | |
      28. | | DHCPACK/ ----------- |
      29. | v Record lease, set ^ |
      30. +----------------> ------- /timers T1,T2 | |
      31. +----->| |<---+ | |
      32. | | BOUND |<---+ | |
      33. DHCPOFFER, DHCPACK, | | | T2 expires/ DHCPNAK/
      34. DHCPNAK/Discard ------- | Broadcast Halt network
      35. | | | | DHCPREQUEST |
      36. +-------+ | DHCPACK/ | |
      37. T1 expires/ Record lease, set | |
      38. Send DHCPREQUEST timers T1, T2 | |
      39. to leasing server | | |
      40. | ---------- | |
      41. | | |------------+ |
      42. +->| RENEWING | |
      43. | |----------------------------+
      44. ----------
      45. Figure 5: State-transition diagram for DHCP clients
      Alles anzeigen
      Code first, think later - Natural programmer :D
    • :D
      ich habe schon darauf gewartet...

      Diese DHCP Routine funktioniert nicht mit den WIZ Befehlen aus Bascom.
      Das habe ich programmiert, bevor Mark die WIZ Befehle in Bascom eingebaut hat.
      Es sind also eigene Routinen. Dafür müsstest du meine WIZ Routinen einbinden, wovon ich allerdings abraten würde, da dann dein restlichen Programm wahrscheinlich nicht mehr funktioniert.
      Im Prinzip ist es aber relativ einfach, meinen Code in die neueren Bascom Befehle umzusetzen! Macht nur ein bisschen Arbeit.
      Code first, think later - Natural programmer :D