Rozbudowa Select Case

Pytania, kody i porady dotyczące nie tylko Bascom.
ODPOWIEDZ
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Rozbudowa Select Case

Post autor: Jacek » 29 lip 2022, 13:16

Witam - w ramach wolnego czasu (chorobowe :roll: ) chciałbym rozbudować program do komunikacji po RS485 o identyfikację adresu urządzenia, komendy, wartości
na tą chwilę mam tak
  1. '-------------------------------------------------------------------------------------------
  2. 'ODBIÓR DANYCH UART1
  3.    If Ischarwaiting(#RS485_1) > 0 Then                                          'calls _gotchar and use URXC
  4.       Lcount_1 = Inkey(#RS485_1)                                                'pobierz znak z bufora
  5.       If Lcount_1 = 13 Or Len(uart_command_1) > 20 Then                         '20 Then                        ' jeslii ENTER lub wiecej niz 20 znaków to call uartrx
  6.          Call Uartrx1()                                                         'wywołaj podprogram Uartrx1
  7.          'Debug "czyszczenie bufora po odebranje komendzie"                      'Using a constant will let us change the prompt
  8.          'clear serialin                                                            'nie sprawdzone
  9.          Uart_command_1 = ""                                                    ' koniecznie potrzenbe do czysczenia bufora
  10.       Else                                                                      'inaczej
  11.          Uart_command_1 = Uart_command_1 + Chr(Lcount_1)                        'kluczowe budowanie bufora
  12.       End If                                                                    'koniec warunku
  13.    End If                                                                       'koniec warunku
  14. '-------------------------------------------------------------------------------------------
w Call Uartrx1 mam tak
  1. $nocompile
  2. '  odbiór danych z uart1 RS485_1
  3. Sub Uartrx1
  4.    Debug #Debug_ , "jestem w uartrx1_"
  5.    Lcount_1 = Split(uart_command_1 , Getcommands_1(1) , " ")
  6.    Debug #Debug_ , "lcount= " ; Lcount_1
  7.    Debug #Debug_ , "Uart_command_1= " ; Uart_command_1
  8.    Debug #Debug_ , "debug uart_command_1= " ; Uart_command_1
  9.    Debug #Debug_ , "debug Getcommands_1(1)= " ; Getcommands_1(1)
  10.    Debug #Debug_ , "debug Getcommands_1(2)= " ; Getcommands_1(2)
  11.    Debug #Debug_ , "debug Getcommands_1(3)= " ; Getcommands_1(3)
  12.  
  13.  
  14.    Select Case Getcommands_1
  15.  
  16.    '-----------------------------------------------------------------------------------------
  17.       Case G1_c_1:
  18.          Debug #Debug_ , "jestem w command 1, case 1 "
  19.          Adres_rs485 = Val(Getcommands_1(1))
  20.          Debug #Debug_ , "odebrany adres urzadzenia: " ; Adres_rs485
  21.    '-----------------------------------------------------------------------------------------
  22.       Case G1_c_2:
  23.          Debug #Debug_ , "jestem w command 1, case 2 "
  24.          komenda_1 = Getcommands_1(2)
  25.          Debug #Debug_ , "odebrana komeda_1: " ; komenda_1
  26.          '-------------------------------------------------------------------------------------
  27.       Case G1_c_3:
  28.          Debug #Debug_ , "jestem w command 1, case 3 "                          '
  29.          wartosc_1 = Val(Getcommands_1(3))
  30.          Debug #Debug_ , "odebrana wartosc_1: " ; wartosc_1
  31.          '-------------------------------------------------------------------------------------
  32.  
  33.  
  34.  
  35.       'ponizej NIE USUWAJ TO JEST WAZNE!
  36.       'jak komenda nie rozpoznana zrób to
  37.          Getcommands_1(1) = ""
  38.          Getcommands_1(2) = ""
  39.          Getcommands_1(3) = ""
  40.  
  41.  
  42.    End Select
  43.    'ponizej NIE USUWAJ TO JEST WAZNE!
  44.    'jak komenda nei rozpoznana zrób to
  45.    Getcommands_1(1) = ""
  46.    Getcommands_1(2) = ""
  47.    Getcommands_1(3) = ""
  48.  
  49.  
  50.  '*******************************************************************************
  51. End Sub
do urządzenia o adresie 200 wysyłam na tą chwilę
  1. '-------------------------------------------------------------------------------------------
  2.    If Flaga1s = 1 Then                                                          'jeśli Flaga1s jest równa 1
  3.       Flaga1s = 0                                                               'wyzeruj Flaga1s
  4.       Call Mruganie
  5.       Print #RS485_1 , "200 a"
  6.       'Print #RS485_1 , "200 t"
  7.    End If                                                                       'koniec warunku
  8. '-------------------------------------------------------------------------------------------
terminal odpowiada
Clipboard01.jpg
co mam źle w pliku Uartrx1.inc że odebrane dane nie trafiają do swoich zmiennych.
pozdrawiam Jacek.
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Rozbudowa Select Case

Post autor: Jacek » 31 lip 2022, 10:53

Witam - przerobiłem podprogram Uartrx1
  1. $nocompile
  2. '  odbiór danych z uart1 RS485_1
  3. Sub Uartrx1
  4.    Debug #Debug_ , "jestem w uartrx1_"
  5.    Lcount_1 = Split(uart_command_1 , Getcommands_1 , " ")
  6.    Debug #Debug_ , "lcount=" ; Lcount_1
  7.    Debug #Debug_ , "Uart_command_1= " ; Uart_command_1
  8.    Debug #Debug_ , "debug uart_command_1= " ; Uart_command_1
  9.    Debug #Debug_ , "debug Getcommands_1(1)=" ; Getcommands_1(1)
  10.    Debug #Debug_ , "debug Getcommands_1(2)=" ; Getcommands_1(2)
  11.    Debug #Debug_ , "debug Getcommands_1(3)=" ; Getcommands_1(3)
  12.  
  13.  
  14.  
  15.  
  16.    '-----------------------------------------------------------------------------------------
  17.  
  18.          Debug #Debug_ , "jestem w command 1, case 1 "
  19.          Rs485_adres = Val(Getcommands_1(1))
  20.          Debug #Debug_ , "odebrany adres urzadzenia: " ; Rs485_adres
  21.  
  22.    '-----------------------------------------------------------------------------------------
  23.  
  24.          Debug #Debug_ , "jestem w command 1, case 2 "
  25.          komenda_1 = Getcommands_1(2)
  26.          Debug #Debug_ , "odebrana komeda_1: " ; komenda_1
  27.  
  28.          '-------------------------------------------------------------------------------------
  29.  
  30.          Debug #Debug_ , "jestem w command 1, case 3 "                                '
  31.          wartosc_1 = Val(Getcommands_1(3))
  32.          Debug #Debug_ , "odebrana wartosc_1: " ; wartosc_1
  33.  
  34.          '-------------------------------------------------------------------------------------
  35.  
  36.  
  37.  
  38.       'ponizej NIE USUWAJ TO JEST WAZNE!
  39.       'jak komenda nie rozpoznana zrób to
  40.          Getcommands_1(1) = ""
  41.          Getcommands_1(2) = ""
  42.          Getcommands_1(3) = ""
  43.  
  44.  
  45.    'End Select
  46.    'ponizej NIE USUWAJ TO JEST WAZNE!
  47.    'jak komenda nei rozpoznana zrób to
  48.    'Getcommands_1(1) = ""
  49.   ' Getcommands_1(2) = ""
  50.   ' Getcommands_1(3) = ""
  51.  
  52.  
  53.  '*******************************************************************************
  54. End Sub
w terminalu odbieram to
31072022_1040.jpg
po restarcie mikro kontrolera do zmiennej Rs485_adres trafia prawidłowo adres "200", niestety po wysłaniu kolejnego zapytania do enkodera zamiast adresu "200" otrzymuje "0"
i tak w kółko po zresetowaniu trafia "200" a po następnym i kolejnych zapytaniu jest "0"
czy ktoś może podpowiedzieć dlaczego zmienia się z "200" na "0".
pozdrawiam Jacek.
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.
ODPOWIEDZ