Strona 1 z 1

Odczyt urządzeń na magistrali RS485

: 04 paź 2022, 18:53
autor: Jacek
Witam - pomyślałem że dobrze było by abym mógł odczytać w sterowniku rotora jakie są nazwy i adresy urządzeń podpiętych na magistrali rs485.
Clipboard02.png

Napisałem sub'a
  1. $nocompile
  2. '  odbiór danych z uart1 RS485
  3. Sub RS485ping
  4.    Debug #Debug_ , "jestem w RS485ping_"
  5.    ''Adres485 = 254
  6.    ''Print #RS485 , Adres485 ; " ping_adress" ; Chr(13)
  7.    ''Print #Debug_ , "Adres485tx=> " ; Adres485
  8.      'Print #Debug_ , "Adres485rx=> " ; RS485_adres_temp
  9.      'Print #Debug_ , "Name_device=>" ; Name_device
  10.    For Adres485 = 1 To 255 Step 1
  11.       Print #RS485 , Adres485 ; " ping_adress" ; Chr(13)
  12.       Print #Debug_ , "Adres485tx=> " ; RS485
  13.       Print #Debug_ , "Adres485rx=> " ; RS485_adres_temp
  14.       Print #Debug_ , "Name_device=>" ; Name_device
  15.    Next Adres485
  16.    Return
  17. End Sub
i wychodzi kaszanka :oops:
Clipboard03.png
jak ustawię na sztywno jeden adres
  1. $nocompile
  2. '  odbiór danych z uart1 RS485
  3. Sub RS485ping
  4.    Debug #Debug_ , "jestem w RS485ping_"
  5.    Adres485 = 254
  6.    Print #RS485 , Adres485 ; " ping_adress" ; Chr(13)
  7.    'Print #Debug_ , "Adres485tx=> " ; Adres485
  8.    'Print #Debug_ , "Adres485rx=> " ; RS485_adres_temp
  9.    'Print #Debug_ , "Name_device=>" ; Name_device
  10. '   For Adres485 = 1 To 255 Step 1
  11. '      Print #RS485 , Adres485 ; " ping_adress" ; Chr(13)
  12. '      Print #Debug_ , "Adres485tx=> " ; RS485
  13. '      Print #Debug_ , "Adres485rx=> " ; RS485_adres_temp
  14. '      Print #Debug_ , "Name_device=>" ; Name_device
  15. '   Next Adres485
  16.    Return
  17. End Sub
to już coś wychodzi ale nie do końca dobrze
Clipboard04.png
odbiór mam tak
  1. $nocompile
  2. '  odbiór danych z uart1 RS485
  3. Sub Uartrx1
  4.    'Reset Watchdog
  5. '##########################################################
  6.    Print #Debug_ , "jestem w uar_rx1"
  7.    Lcount_1 = Split(uart_command_1 , Getcommands_1(1) , " ")                    'This choping coomand after space
  8.    'Debug Chr(13)
  9.    Print #Debug_ , "lcount_1= " ; Lcount_1
  10.    Print #Debug_ , "uart_command_1= " ; Uart_command_1
  11.    Print #Debug_ , "Getcommands_1(1)= " ; Getcommands_1(1)
  12.    Print #Debug_ , "Getcommands_1(2)= " ; Getcommands_1(2)
  13.    Print #Debug_ , "Getcommands_1(3)= " ; Getcommands_1(3)
  14.    'Debug #Debug_ , " ";                                                         'command>> az 0 0  'printing proper spaces
  15.  
  16.    Rs485_adres_temp = Val(getcommands_1(1))                                     'zamien tekst na numer
  17.    Print #Debug_ , "odebrlem poprawnie adres "
  18.    'Print #Debug_ , "adress " ; RS485_adres_temp
  19.    Print #Debug_ , "Adres485rx=> " ; RS485_adres_temp
  20.    Name_device = Getcommands_1(2)
  21.    Print #Debug_ , "Name_device=>" ; Name_device
  22.    Select Case Rs485_adres_temp
  23.  
  24.       Case Rs485_adres :                                                        'komneda 1 case 1, sprawdzenie adresu
  25.         ' Debug #Debug_ , "odebrlem poprawnie adres "
  26.          'Debug #Debug_ , "adress " ; RS485_adres_temp
  27. '-------------------------------------------------------------------------------------------
  28.          Select Case Getcommands_1(2)
  29.             Case uart1G2_c_1:                                                   'azymut
  30.                Print #Debug_ , "jestem w command 2, case 1 "
  31.                Name_device = Getcommands_1(2)
  32.                'Debug #Debug_ , "Name_device=>" ; Name_device
  33.                Print #Debug_ , "Name_device=>" ; Name_device
  34. '-------------------------------------------------------------------------------------------
  35.             Case uart1G2_c_2:                                                   'temperatura
  36.                Debug #Debug_ , "jestem w command 2, case 2 "
  37. '-------------------------------------------------------------------------------------------
  38.             Case uart1G2_c_3:
  39.                Debug #Debug_ , "jestem w command 2, case 5 "                    ' diag_on
  40.                'Print "200,diag_on"                                              'flagi.2 = 1
  41. '-------------------------------------------------------------------------------------------
  42.             Case uart1G2_c_4:
  43.                Debug #Debug_ , "jestem w command 2, case 6 "                    'diag_off
  44.                'Print "200,diag_off"                                             'flagi.2 = 0
  45. '-------------------------------------------------------------------------------------------
  46.             Case uart1G2_c_5:
  47.                Debug #Debug_ , "jestem w command 2, case 7 "                    'rs_term_on
  48.                'Print "rs_term_on"                                               'Term_enable = 1
  49. '-------------------------------------------------------------------------------------------
  50.             Case uart1G2_c_6:
  51.                Debug #Debug_ , "jestem w command 2, case 8 "                    'rs_term_off
  52.                'Print "rs_term_off"                                              'Term_enable = 0
  53. '-------------------------------------------------------------------------------------------
  54.             Case uart1G2_c_7:
  55.                Debug #Debug_ , "jestem w command 2, case 9 "                    'rs_term_off
  56.                'print "podaj adres nowy adres: "
  57.                'Rs485_adres = Val(getcommands_1(3))
  58.                'Writeeeprom rs485_adres , &H10                                   '_ee , &H10                    'writeeeprom Rs485_adres_ee
  59.                'Start Watchdog
  60. '-------------------------------------------------------------------------------------------
  61.             Case Reboot:
  62.       'zrestartój system
  63.                'Print
  64.                'Print "Device will now reboot"
  65.                'Start Watchdog
  66.                'do
  67.                'loop
  68.  
  69.             Case bootloader:                                                    'load
  70.                'disable interrupts
  71.                'Config Watchdog = 1024
  72.                'Start Watchdog
  73.                'do
  74.                'loop
  75.  
  76.  
  77.             Case Help :                                                         '?
  78.           'wysietl komendy
  79. '               Print chr(10) ; "Ekoder absolutny SP9DR"
  80. '               Print "Version: " ; Version(2)
  81. '               Print "RS_485 Adres= " ; Rs485_adres
  82. '               print "120 Ohm terminacja = " ; Term_enable
  83. '               if Portc.5 = 1 then
  84. '                  print "Wlaczona"
  85. '               else
  86. '                  print "Wylaczona"
  87. '               end if
  88.                'print chr(10) ; " lista komend: "
  89.                'print "a------------Podaj azymut"
  90.                'print "t------------Podaj temperature"
  91.                'print "c------------Wolne"
  92.                'print "s------------Predkosc"
  93.                'print "diag_on------Diagnostyka wlacz"                           'magnitude diagnostic
  94.                'print "diag_off-----Diagnostyka wylacz"
  95.                'print "rs_term_on---Terminacja wlacz"
  96.                'print "rs_term_off--Terminacja wylacz"
  97.                'print "reboot ------Restart systemu"
  98.                'print "load---------Aktualizuj oprogramowanie"
  99.                'print "adrr---------Zmiana adresu RS485"
  100.                'print "?------------Wyswielt liste komend"
  101.  
  102.             Case Else
  103.  
  104.       'ponizej NIE USUWAJ TO JEST WAZNE!
  105.       'jak komenda nie rozpoznana zrób to
  106.                'Print #Debug_ , Prompt ; " " ; Uart_command_1 ; " " ; Notincommands
  107.                'Print #Debug_ , Prompt
  108.                Getcommands_1(1) = ""
  109.                Getcommands_1(2) = ""
  110.                Getcommands_1(3) = ""
  111.  
  112.          End Select
  113.    'ponizej NIE USUWAJ TO JEST WAZNE!
  114.    'jak komenda nei rozpoznana zrób to
  115.          Getcommands_1(1) = ""
  116.          Getcommands_1(2) = ""
  117.          Getcommands_1(3) = ""
  118.  
  119.       Case Broadcast:                                                           '255 broadcast do wszystkich
  120.  
  121.          'Select Case Getcommands(2)
  122. '            Case Reboot:
  123. '      'zrestartój system
  124. '               Print
  125. '               Print "Device will now reboot"
  126. '               Start Watchdog
  127.  
  128. '            Case Help :                                     '?
  129. '               Waitms Rs485_adres
  130. '               Print "Wind speed board ver: " ; Version(2)
  131. '               Print "RS_485 Adres= " ; Rs485_adres
  132.  
  133.  
  134. '            Case Else
  135. '                 'Print Prompt ; " " ; Uart_command ; " " ; Notincommands
  136. '               'Print Prompt
  137. '               Getcommands(1) = ""
  138. '               Getcommands(2) = ""
  139. '               Getcommands(3) = ""
  140. '         End Select
  141. '         Getcommands(1) = ""
  142. '         Getcommands(2) = ""
  143. '         Getcommands(3) = ""
  144.  
  145.  
  146.       Case Else
  147.       'ponizej NIE USUWAJ TO JEST WAZNE!
  148.          Debug #Debug_ , "odebrlem zly adres "
  149.          'Print #Debug_ , Prompt ; " " ; Uart_command_1 ; " " ; Notincommands
  150.          'Print Prompt
  151.          'Jelsi zly adres wyczysc wszytkie komorki z odebranymi danymi
  152.          Getcommands_1(1) = ""
  153.          Getcommands_1(2) = ""
  154.          Getcommands_1(3) = ""
  155.  
  156.    End Select
  157.    'ponizej NIE USUWAJ TO JEST WAZNE!
  158.    'jak komenda nei rozpoznana zrób to
  159.    Getcommands_1(1) = ""
  160.    Getcommands_1(2) = ""
  161.    Getcommands_1(3) = ""
  162. '##########################################################
  163.  
  164. End Sub
jak poprawnie odebrać adresy z nazwami urządzeń aby to działało domyślam się że powinienem użyć tablic ale nie wiem jak to napisać.
pozdrawiam Jacek.

Re: Odczyt urządzeń na magistrali RS485

: 04 paź 2022, 19:22
autor: niveasoft
Jak napiszesz "For Address 1 To 255" to ciągle nadajesz i nie dajesz szansy nikomu odpowiedzieć.
To musisz zrobić sprytniej. Wysłać zapytanie i poczekać na odpowiedź w programie glównym bo w tym Sub przecież niczego nie odbierzesz.
  1. Dim Skanuj_siec As Byte
  2.  
  3. Do
  4.  If 100ms = 1 Then           'na przykład
  5.   If Skanuj_siec < 255 Then
  6.    Incr Skanuj_siec
  7.     Print #rs485 , "Ping " ; Skanuj_siec
  8.   End If
  9.  End if
  10.  
  11.  If Ischarwaiting(rs485) > 0 Then
  12.   'Jeśli ktoś odpowie to sobie parsujesz
  13.  'Jesli nie to pytasz o kolejny adres za 100ms
  14.  End if
  15. Loop

Re: Odczyt urządzeń na magistrali RS485

: 04 paź 2022, 20:09
autor: Jacek
Dziękuję Bartek za szybka odpowiedź - myślałem że w "subie" będzie bardziej poprawnie politycznie ;)
pozdrawiam Jacek.