Pomoc w komunikacji nextion inteligent-xmega256A3U

Rodzina procesorów bogatszych w wiele nowych rozwiązań i dlatego warto po nie sięgnąć.
Awatar użytkownika
Karlos128@nos
Posty: 64
Rejestracja: 18 sie 2015, 13:32

Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: Karlos128@nos » 15 gru 2024, 21:53

Witam. Panowie mam bardzo duży problem z komunikacją pomiędzy nextion inteligent a atxmega256A3U.
Chodzi mi o to jak odbiera się dane z nextiona do cpu.
np. klikam w button i powinno wysłać : print "AT=SAFEvcc" i to powinen rozpoznać cpu.
Zawsze do tej pory korzystałem z takiej skladni we wszystkich moich projektach i było dobrze, a teraz nici z tego.
Ustawienia moich uartów: dodam tylko że zamiast baudrate=57600 dałem 50000 bo procek chodzi na 48Mhz
  1. Rem ***************************** Komunikacja UART *********************************
  2. 'Rem *** CONFIG COM1 Połączenie bluetootch JDY-34
  3. Config Com3 = 50000 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
  4. Open "COM3:" For Binary As #3
  5. Config Serialin2 = Buffered , Size = 124
  6. Enable Usartd0_rxc , Lo
  7. Config Input3 = Cr , Echo = Crlf
  8.  
  9. Rem *** CONFIG COM5     E220-900T30D       >><< NEXTION HMI   34200
  10. Config Com2 = 50000 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
  11.  
  12. Open "COM2:" For Binary As #2
  13. Config Serialin1 = Buffered , Size = 200
  14. 'Config Serialout1 = Buffered , Size = 200
  15. Enable Usartc1_rxc , Lo
  16. Config Input1 = Cr , Echo = Crlf
A tak odbieram:
  1. Rem ************ RX - TX >< NEXTION ********
  2. Rxtx_zasilacz_jdy24:
  3.    Input #3 , Odbieram_dane
  4.    Bufor = Odbieram_dane
  5.    Clear Serialin2
  6.    Lcd_text "RX=" + Bufor + "    " , 8 , 273 , 2 , Yellow , Black , 1
  7.  
  8.    If Bufor = "AT=CLOCK" Then
  9.       Waitms 30
  10.       Clear Serialin2
  11.       Print #3 , "Zegar-" ; Godz_txt ; ":" ; Min_txt ; ":" ; Sek_txt
  12.    Elseif Bufor = "AT=DATA" Then
  13.       Waitms 30
  14.       Clear Serialin2
  15.       Pokaz_date = 1
  16.       Call Zegarek
  17.       Print #3 , "DATA: " ; Data_sd
  18.    Elseif Bufor = "AT=SETCLOCK" Then
  19.       Input #3 , Odbieram_dane                              'Noecho
  20.       Waitms 20
  21.       Bcount = Split(odbieram_dane , Tablica_rx(1) , ":")
  22.       G = Val(tablica_rx(1))
  23.       M = Val(tablica_rx(2))
  24.       S = Val(tablica_rx(3))
  25.       Call Settime
  26.       Waitms 20
  27.       Call Zegarek
  28.       Print #3 , Czas
  29.       Clear Serialin2
  30.    Elseif Bufor = "AT=SETDATA" Then
  31.  
  32.       Input #3 , Odbieram_dane
  33.       Waitms 20
  34.       Bcount = Split(odbieram_dane , Tablica_rx(1) , "-")
  35.       Rok = Val(tablica_rx(1))                              ' rok
  36.       Miesiac = Val(tablica_rx(2))                          ' miesiac
  37.       Dzien = Val(tablica_rx(3))                            ' dzien
  38.       Dzien_tygodnia = Val(tablica_rx(4))                   ' dzien_tygodnia
  39.       Call Setdata
  40.       Clear Serialin2
  41.       Print #3 , Data_sd
  42.    Elseif Bufor = "AT=LCDPWM" Then
  43.       Waitms 20
  44.       Print #3 , "PWM=0 - 65535"
  45.       Print #3 , "PWM=" ; Lcd_pwm
  46.  
  47.    Elseif Bufor = "AT=SETLCD" Then
  48.       Waitms 20
  49.       Input #3 , Lcd_pwm
  50.       Waitms 10
  51.       Rx_pwm = Lcd_pwm
  52.       Tcf0_ccb = Lcd_pwm
  53.       Clear Serialin2
  54.    Elseif Bufor = "AT=ALLVCC" Then
  55.       Waitms 20
  56.       Print
  57.  
  58.    Elseif Bufor = "AT=TEMP" Then
  59.  '  Appendtofile( "log1.txt" , Text)
  60.  
  61.    Elseif Bufor = "AT=SAFEON" Then
  62.  
  63.  
  64.    Elseif Bufor = "AT=SAFEOFF" Then
  65.  
  66.  
  67.    Elseif Bufor = "AT=SETI" Then
  68.       Waitms 20
  69.       Input #3 , Rx_vi
  70.       Waitms 10
  71.       Prad = Rx_vi
  72.       If Prad > 0 And Prad < 4095 Then
  73.          I_dac = Prad * Idac
  74.          Txt = Fusing(i_dac , "#.##")
  75.          Lcd_text Txt , 162 , 45 , 3 , Yellow , Black , 1
  76.          Call Set_prad
  77.       End If
  78.       Clear Serialin2
  79.    Elseif Bufor = "AT=SETV" Then
  80.       Waitms 20
  81.       Input #3 , Rx_vi
  82.       Waitms 10
  83.       Napiecie = Rx_vi
  84.       If Napiecie > 0 And Napiecie < 4095 Then
  85.          V_dac = Napiecie * Vdac
  86.          Txt = Fusing(v_dac , "##.##")
  87.          Lcd_text Txt + " " , 12 , 45 , 3 , Yellow , Black , 1
  88.          Call Set_napiecie
  89.       End If
  90.       Clear Serialin2
  91.    Elseif Bufor = "AT=ZAPISZVI" Then
  92.  
  93.    Elseif Bufor = "AT=TIMERON" Then
  94.  
  95.    Elseif Bufor = "AT=TIMEROFF" Then
  96.  
  97.    Elseif Bufor = "AT=SETTIMER" Then
  98.  
  99.    Elseif Bufor = "AT=SAVE-LOG" Then
  100.       Waitms 20
  101.       Call Logi_systemowe
  102.       Clear Serialin2
  103.       Call Buzerek
  104.    Elseif Bufor = "AT=DANEPC" Then
  105.       Waitms 20
  106.       Call Dane_komputer
  107.       Clear Serialin2
  108.       Call Buzerek
  109.    Else
  110.       Lcd_text "RX=err " , 8 , 273 , 2 , Yellow , Black , 1
  111.       Print #3 , "Comand Err"
  112.       Clear Serialin2
  113.    End If
  114.   ' Lcd_text "RX=              " , 8 , 273 , 2 , Yellow , Black , 1
  115.    Clear Serialin2
  116.    Call Buzerek
  117.    Close #3
  118. Return
Nigdy nie miałem doczynienia z czymś takim jak: Receiveddata = Inkey(#2) .
Bardzo bym prosił o choćby jakiś sprawdzony przykład komunikacji dwustronnej nextion<>cpu.
Dodam że skorzystałem nawet ze sztucznej mądrości to tylko namieszła mi w głowie, aczkolwiek pomogła napisać procedury do środowiska VB.NET, ale w bascomie to już nie za bardzo.
Awatar użytkownika
niveasoft
Posty: 1313
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: niveasoft » 16 gru 2024, 7:27

Dawno się nextionem nie bawiłem, ale pamietam, że tam się każde dane rozpoczynają od &HFF i potem jest jeszcze informacja jakie to sa dane. Na przykład string czy moze jakieś dane liczbowe/wartości.
Na formum MCS umieściłem taki przykład to i tu powtórzę. czegoś moze zabraknąc bo wycinam go na bieżąco z działającego kodu.
Po latach kilka rzeczy bym tu już poprawił i napisał inaczej :D
  1. '*****************************************************************
  2. '*                    NEXTION DISPLAY                            *
  3. '*****************************************************************
  4.  
  5. 'NEXTION RETURN DATA                                        LENGTH
  6. Const Invalid_instruction = &H00                            '4
  7. Const Instruction_okay = &H01                               '4
  8. Const Invalid_component_id = &H02                           '4
  9. Const Invalid_page_id = &H03                                '4
  10. Const Invalid_picture_id = &H04                             '4
  11. Const Invalid_font_id = &H05                                '4
  12. Const Invalid_file_operation = &H06                         '4
  13. Const Invalid_crc = &H09                                    '4
  14. Const Invalid_baud_rate = &H11                              '4
  15. Const Invalid_vaweform_id = &H12                            '4
  16. Const Invalid_variable_name = &H1A                          '4
  17. Const Invalid_variable_operation = &H1B                     '4
  18. Const Assignement_failed = &H1C                             '4
  19. Const Eeprom_operation_failed = &H1D                        '4
  20. Const Invalid_parameters_quantity = &H1E                    '4
  21. Const Io_operation_failed = &H1F                            '4
  22. Const Escape_char_invalid = &H20                            '4
  23. Const Variable_name_to_long = &H23                          '4
  24. 'return codes valid  in all cases
  25. '00 00 00 FF FF FF =>Nextion starup                          '6
  26. Const Serial_buff_overflow = &H24                           '4
  27. Const Touch_event = &H65                                    '7
  28. ' 65 00 01 01 FF FF FF
  29. ' |   |  |  |
  30. ' |   |  |  event 01=press, 00=release
  31. ' |   |  component ID
  32. ' |   page number
  33. ' touch event
  34. Const Curr_page_num = &H66                                  '5 second byte is page num
  35. Const Touch_awake_coordinate = &H67                         '9
  36. Const Touch_sleep_coordinate = &H68
  37.  'first two bytes is X
  38.  'next two bytes is Y
  39.  'last byte is event 01=press, 00=release
  40.  'eg. 67 00 7A 00 1E 01 FF FF FF
  41. Const String_data = &H70                                    'varied len eg.70 xx xx xx xx xx xx FF FF FF
  42. Const Numeric_data = &H71                                   '8 eg.71 xx xx xx xx FF FF FF  <-4bytes 32bit value, little endian
  43. Const Auto_sleep = &H86                                     '4
  44. Const Auto_awake = &H87                                     '4
  45. Const Nextion_ready = &H88                                  '4
  46. Const Micro_sd_upgrade = &H89                               '4
  47. Const Transp_data_finished = &HFD                           '4
  48. Const Transp_data_ready = &HFE                              '4
Tu przykład odbioru danych.
  1.  '--[ USART1 COM2 NEXTION ]---------------------
  2.   If 0 < Ischarwaiting(#nex) Then
  3.  
  4.     Incr Nex_idx : If Nex_idx > Max_nex_command_len Then Nex_idx = 1       'zabezpieczenie
  5.      Nex_buff(nex_idx) = Waitkey(#nex)
  6.  
  7.     If Nex_idx = 1 Then                                     'check what type of msg we receiving
  8.      Select Case Nex_buff(1)
  9.  
  10.       Case 0
  11.        'it can be 4bytes Invalid_instruction
  12.        'or 6 bytes Nextion_startup (may be after reset)
  13.         Min_len = 1
  14.  
  15.       Case Touch_event
  16.         Min_len = 4
  17.       Case Touch_awake_coordinate                           '9 bytes
  18.         Min_len = 6
  19.       Case Touch_sleep_coordinate                           '9 bytes
  20.         Min_len = 6
  21.  
  22.       Case String_data                                      'it will be string with variable len
  23.         Min_len = 2
  24.       Case Numeric_data                                     'there can be FF`s so we must wait for 8 bytes
  25.         Min_len = 5
  26.  
  27.       Case Else
  28.         Min_len = 1                                         'rest of return`s have one byte followed three FF`s
  29.  
  30.      End Select
  31.  
  32.     Else
  33.                                                         'msg continue
  34.      If Nex_buff(nex_idx) = &HFF Then
  35.       If Nex_idx > Min_len Then
  36.  
  37.        If End_cnt < 2 Then
  38.         Incr End_cnt
  39.  
  40.        Else                                                 'we received third FF
  41.  
  42. '         '-----------------------------[ DEBUG ]----------
  43. '          Debug #usb , "Debug=> ";
  44. '          For N = 1 To Nex_idx
  45. '           Debug #usb , Hex(nex_buff(n)) ; " ";
  46. '          Next
  47. '          Debug #usb , ""
  48. '         '------------------------------------------------
  49.  
  50.          'parse
  51.           Select Case Nex_buff(1)
  52.  
  53.            Case Invalid_instruction
  54.  
  55.             If Nex_idx = 4 Then
  56.              Debug #usb , "Invalid instruction!"
  57.             Elseif Nex_idx = 6 Then
  58.              Debug #usb , "Nextion rebooted OK"
  59.             End If
  60.  
  61.            Case Instruction_okay
  62.              Debug #usb , "Command accepted"
  63.            Case Invalid_variable_name
  64.              Debug #usb , "Variable or component NAME not recognized!"
  65.  
  66.            Case Touch_event
  67.              If Touch_state = 0 Then
  68.               Debug #usb , "Relased object " ; Touch_id ; " on page " ; Touch_page
  69.              Else
  70.               Debug #usb , "Pressed object " ; Touch_id ; " on page " ; Touch_page
  71.              End If
  72.  
  73.            Case Touch_awake_coordinate To Touch_sleep_coordinate
  74.  
  75.               Swap New_x                                    'big endian order received
  76.               Swap New_y
  77.               Debug #usb , "Coordinates are: X=" ; New_x ; " Y=" ; New_y
  78.  
  79.            Case String_data
  80.              Helpb = Nex_idx - 2
  81.              Nex_buff(helpb) = 0                            'add string terminator
  82.              'Debug #usb , "New string=> " ; New_string
  83.              Debug #usb , New_string
  84.  
  85.              'you can parse new commands here
  86.  
  87.              If 0 < Instr(new_string , "AT+POMSTART") Then
  88.  
  89.  
  90.              Elseif 0 < Instr(new_string , "AT+POMSTOP") Then
  91.  
  92.              Elseif 0 < Instr(new_string , "AT+POMIAR") Then
  93.  
  94.              Elseif 0 < Instr(new_string , "AT+GETSET") Then
  95.  
  96.              Elseif 0 < Instr(new_string , "AT+SETBACK") Then
  97.  
  98.              Elseif 0 < Instr(new_string , "AT+NEXSTART") Then
  99.  
  100.              Elseif 0 < Instr(new_string , "AT+CALIB1") Then       'skalibruj przewodnosc na 12uS
  101.  
  102.              Elseif 0 < Instr(new_string , "AT+DATE=") Then
  103.               'na page2
  104.               Helpstr = Mid(new_string , 9)
  105.                Date$ = Helpstr
  106.                Helpstr = Date$
  107.                Call Set_text( "page2.data" , Helpstr)
  108.  
  109.              Elseif 0 < Instr(new_string , "AT+TIME=") Then
  110.               'na page2
  111.               Helpstr = Mid(new_string , 9) + ":00"
  112.                Time$ = Helpstr
  113.                Time_str = Time$
  114.                Helpstr = Left(time_str , 5)
  115.                  Call Set_text( "page2.czas" , Helpstr)
  116.              End If
  117.  
  118.            Case Numeric_data
  119.              Debug #usb , "New value=> " ; New_long
  120.  
  121.              'you can parse new values here
  122.  
  123.  
  124.           End Select
  125.  
  126.  
  127.  
  128.  
  129.           Nex_idx = 0
  130.           End_cnt = 0
  131.        End If
  132.  
  133.       End If
  134.      End If
  135.  
  136.     End If
  137.  
  138.  
  139.   End If
Każda paczka kończy się chyba trzema &HFF. Tak więc raczej nigdy nie będziesz miał tak że "Bufor = AT+COSTAM". Nalezy użyc INSTR(mojstring , "AT+COSTAM") i to pokazuje czy to się w stringu znajduje.
Nie umieszczam tu na razie subów do tworzenia stringów żeby nie zaciemniać tematu.
Awatar użytkownika
Karlos128@nos
Posty: 64
Rejestracja: 18 sie 2015, 13:32

Re: Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: Karlos128@nos » 16 gru 2024, 15:01

Witaj bartku, nie sprawdzałem twego kodu, ale jeszcze się pomęczyłem z tym nieszczęsnym odbiorem i wyszło tak.
wypiełem te nieszczęsne E220-900T30D moduły i zastąpiłem je modułami HC-12 i śmiga aż miło.
Może te E220-900T30D sprawdzają się i dobrze, ale w tym przypadku nie.
W nextion jeśli nacisnę np. button1 to wysyłam dane tak:
  1. va1.txt="SAFE=ON"
  2. print va1.txt
  3. print 0x0D
  4. print 0x0A
Poprostu dodałem na końcu znaki CRLF aby odbiornik nie wieszał się i rozumiał co do niego wysyłam.
W takiej konfiguracji odbiornik działa wyśmienicie:
  1. Rem ************ RX - TX >< NEXTION ********
  2. Rxtx_zasilacz:
  3.    Input #2 , Odbieram_dane
  4.    Waitms 20
  5.    Bufor = Odbieram_dane
  6.    Clear Serialin1
  7.    Lcd_text "RX=" + Bufor + "    " , 8 , 273 , 2 , Yellow , Black , 1
  8.  
  9.    If Bufor = "AT=CLOCK" Then
  10.       Waitms 30
  11.       Clear Serialin1
  12.       Print #3 , "Zegar-" ; Godz_txt ; ":" ; Min_txt ; ":" ; Sek_txt
  13.    Elseif Bufor = "AT=DATA" Then
  14.       Waitms 30
  15.       Clear Serialin2
  16.       Pokaz_date = 1
  17.       Call Zegarek
  18.       Print #3 , "DATA: " ; Data_sd
  19.    Elseif Bufor = "AT=SETCLOCK" Then
  20.  
  21.    Elseif Bufor = "AT=SAFEON" Then
  22.  
  23.    Elseif Bufor = "AT=SAFEOFF" Then
  24.  
  25.    Elseif Bufor = "AT=SETI" Then
  26.  
  27.    Else
  28.       Lcd_text "RX=err " , 8 , 273 , 2 , Yellow , Black , 1
  29.       Print #3 , "Comand Err"
  30.       Clear Serialin1
  31.    End If
  32.    Clear Serialin1
  33.    Call Buzerek
  34.    Close #2
  35. Return
Ile czasu i pomysłów trzeba wykożystać aby takie dziadostwo ogarnąć :)
Awatar użytkownika
niveasoft
Posty: 1313
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: niveasoft » 16 gru 2024, 15:34

Dokładnie nie wiem dlaczego to działa. Może Bascom jak widzi że Input jest użyty do wprowadzenia stringa to ignoruje wszystko co jest poza standard ASCII czyli powyżej 127 i dlatego nie dodaje tych FF. Nextion pewnie to nadaje na końcu i to widać w terminalu, ale Input czeka na CR LF a potem Ty robisz Clear Serialin.

Nie wiem jak łyka te pierwsze FF i komendy. Może tam był system uproszczonej komunikacji bo przy komendzie "print" pisze że jest juz zdeprecjonowana.
U siebie chciałem mieć mozliwość odczytu dotyku więc juz nie szedłem na łatwiznę.

Nie pamietam, a nie za bardzo jest czas to teraz rozgryzać. Grunt że działa.

Modułami E220-900T30D się nie bawiłem, ale LoRa to raczej powolna jest. Mam jakieś inne moduły (AS-32 Ashining) to raczej wolniej po nich gadam a HC-12 to nawet w domyśle miał 9600bps.
Awatar użytkownika
Karlos128@nos
Posty: 64
Rejestracja: 18 sie 2015, 13:32

Re: Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: Karlos128@nos » 16 gru 2024, 15:47

A może tak na zakończenie byś podpowiedział, jakiej formułki użyć aby wysłać cosik takiego do nextiona.
Deklaracja końca-
  1. Const Nextionend = Chr(255) + Chr(255) + Chr(255)  
i wysyłka -
  1. Print #2 , "Vload.val=13850" ; Nextionend  
czy to dobrze? bo coś nie odbiera.
Awatar użytkownika
niveasoft
Posty: 1313
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: niveasoft » 16 gru 2024, 15:50

Moze zadziała.
  1. Dim Nextionend(3) As byte
  2. Nextionend(1) = &HFF
  3. Nextionend(2) = &HFF
  4. Nextionend(3) = &HFF
  5. Print #2 , "Vload.val=13850" ; 'wyslij bez entera
  6. Printbin #2 , Nextionend(1)  'wysle 3xFF
Jak nie to trzeba pewnie podać ID tej zmiennej.
Nie wiem który to Nextion.
Do tego Bascom dodaje zero na końcu stringów a Nextion nie.
Awatar użytkownika
Karlos128@nos
Posty: 64
Rejestracja: 18 sie 2015, 13:32

Re: Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: Karlos128@nos » 19 gru 2024, 18:53

Niestety, ale powyższy kod u mnie nie działa, ale za to działa taka forma wysyłki do nextion po naciśnięciu przycisku s1:
  1.       If S3 = 0 Then
  2.          Waitms 20
  3.          If S3 = 0 Then
  4.             Waitms 10
  5.             Call Buzerek
  6.             Print #2 , "x2.val=00120" ; : Printbin #2 , 255 ; 255 ; 255
  7.             Waitms 10
  8.             Tekst = "Polecenie NR.2"
  9.             Print #2 , "rx1.txt=" ; Chr(34) ; Tekst ; Chr(34) ; : Printbin #2 , 255 ; 255 ; 255
  10.             Clear Serialin1
  11.          End If
  12.       End If
i wysyła bardzo dobrze i to szybko, aje jak zrobię to samo tylko automatycznie to już nie wysyła.
I tak przy pierwszej metodzie z przyciskiem to okno terminala: 78 31 2E 76 61 6C 3D 31 33 38 32 30 FF FF FF 72 78 31 2E 74 78 74 3D 22 33 22 FF FF FF
jak widać na końcu są 3 x FF, a jak będzie wysyłka z automatu to będzie końcówka taka: 41 54 3D 43 4D 44 0D 0A 72 78 31 2E 74 78 74 3D 22 2D 2D 2D 20 4F 4B 20 2D 2D 2D 22 FF FF FF 1A FF FF FF
i jak widać nie wiem co, ale coś dodaje jeszcze oprucz tych 3xFF jeszcze 1A FF FF FF.
Kod wysyłający
  1. Odbior_nextion:
  2.    Sekundnik = 0
  3.  
  4.    Rx2 = Ischarwaiting(#2)
  5.   ' Tekst = "OK Polecenie TEMP."
  6.    'Print #2 , "rx1.txt=" ; Chr(34) ; Tekst ; Chr(34) ; : Printbin #2 , Ende ; Ende ; Ende
  7.    If Rx2 = 1 Then
  8.       Input #2 , Dane_nextion
  9.       Waitms 10
  10.       Bufor_nextion = Dane_nextion
  11.       Dane_nextion = ""
  12.       Rx2 = 0
  13.       Sekundnik = 0
  14.       Clear Serialin1
  15.       Lcd_text "RX=" + Bufor_nextion + "    " , 8 , 273 , 2 , Yellow , Black , 1
  16.    'Bitwait Aux , Reset
  17.       If Bufor_nextion = "AT=CMD" Then
  18.          Tekst = "--- OK ---"
  19.          Call Buzerek
  20.          Print #2 , "rx1.txt=" ; Chr(34) ; Tekst ; Chr(34) ; : Printbin #2 , 255 ; 255 ; 255
  21.          Clear Serialin1
  22.          'Call Sendtonextion
  23.       Elseif Bufor_nextion = "AT=002" Then
  24.          Call Buzerek
  25.  
  26.          Clear Serialin1
  27.       Elseif Bufor_nextion = "AT=002" Then
  28.          Call Buzerek
  29.  
  30.          Clear Serialin1
  31.       Elseif Bufor_nextion = "AT=002" Then
  32.          Call Buzerek
  33.  
  34.          Clear Serialin1
  35.       Elseif Bufor_nextion = "AT=002" Then
  36.          Call Buzerek
  37.  
  38.          Clear Serialin1
  39.       Elseif Bufor_nextion = "AT=002" Then
  40.  
  41.       Else
  42.         ' Clear Serialin1
  43.         ' Rx2 = 0
  44.          Call Buzerek
  45.          Waitms 10
  46.          Tekst = "Polecenie error"
  47.          Call Sendtonextion
  48.       End If
  49.    'Close #2
  50.          'Clear Serialin1
  51.         ' Rx2 = 0
  52.   ' Rx3 = 0
  53.    End If
  54.  
  55. Return
  56. Sub Sendtonextion
  57.  
  58.    Print #2 , "rx1.txt=" ; Chr(34) ; Tekst ; Chr(34) ; : Printbin #2 , 255 ; 255 ; 255
  59.    Waitms 30
  60.    Clear Serialin1
  61.    Rx2 = 0
  62.    Dane_nextion = ""
  63.    'Close #2
  64.  
  65. End Sub
Co może być przyczyną takiego zjawiska nadprzyrodzonego?
Awatar użytkownika
Pikczu
Posty: 399
Rejestracja: 17 sie 2015, 13:46
Lokalizacja: Dublin, Ireland
Kontakt:

Re: Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: Pikczu » 21 gru 2024, 20:15

Zacznij od usunięcia clear serialin1 i 2 itd
Na 100% nie rozumiesz konsekwencji jakie to niesie ze sobą.
Rozpisz sobie wszystkie komendy odbioru na select case.
Awatar użytkownika
Karlos128@nos
Posty: 64
Rejestracja: 18 sie 2015, 13:32

Re: Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: Karlos128@nos » 22 gru 2024, 18:53

A więc zrobiłem test tego co kolega zalecił, a kodzik malusi to testów przebiegł pomyślnie.
Czy chodziło o coś takiego w odbieraniu komend ?
  1.    Select Case Bufor_nextion
  2.  
  3.       Case "AT=RST"
  4.          Call Buzerek
  5.          Lcd_text "RX=POPRAWNIE" , 8 , 273 , 2 , Yellow , Black , 1
  6.       Case "AT=xxx"
  7.          Call Bezerek
  8.      ' itd...
  9.    End Select
Taka różnica ma na celu ?
Awatar użytkownika
Pikczu
Posty: 399
Rejestracja: 17 sie 2015, 13:46
Lokalizacja: Dublin, Ireland
Kontakt:

Re: Pomoc w komunikacji nextion inteligent-xmega256A3U

Post autor: Pikczu » 22 gru 2024, 21:42

Zagnieżdżając select case możesz sobie w łatwy sposób porcjować komendy.
Stosując stałe dla każdego poziomu select case masz idealny szablon na przyszłość.
Na przykład w kodzie głównym masz listę stałych.
W razie potrzeby zmieniasz tylko stałe taki kod jest bardzo uniwersalny można w szybki sposób użyć go w innym projekcje.
  1. Const G2_c_1 = "o1"                                        
  2. Const G2_c_2 = "o2"                                        
  3. Const G3_c1 = "on"                                          
  4. Const G3_c2 = "off"                                        
G2 i G3 to oznaczenie poziomu select case.
Później c_1 lub c_2 to case 1 i case 2
To daje przejrzysty kod łatwy do użytku na przyszłość i pozwala odnaleźć który to select case.

Zobacz ja to wygląda ja odbieram ramkę danych po RS485 i porcjuje.
Moja ramka to: adres, komenda ,wartość
Czyli kod najpierw sprawdza adres.
Jeśli ten warunek jest spełniony wchodzi w kolejny select case czyli getcommand(2)
w zależności od komendy wchodzi dalej w kolejny select case getcommand(3) itd.
Łatwe w rozbudowie i mega przejrzyste.

Dodanie informacji debug idealnie pozwala na sprawdzenie w którym select case jesteś.
  1.  
  2. $nocompile
  3. Sub Uart_rx():
  4.    Debug off' teraz mam na niestandardowym porcje wiec wyłczone
  5.    Reset Watchdog
  6.    Print #2 , "jestem w uart_rx"' debug mam na nie standardowym porcje
  7.    Lcount = Split(uart_command , Getcommands(1) , " ")      "Porcjowanie
  8.   Debug Chr(13)
  9.   Debug "lcount= " ; Lcount
  10.   Debug "uart_command= " ; Uart_command
  11.   Debug "Getcommands(1)= " ; Getcommands(1)
  12.   Debug "Getcommands(2)= " ; Getcommands(2)
  13.   Debug "Getcommands(3)= " ; Getcommands(3)
  14.   Debug " ";                                              
  15.  
  16.   Rs485_adres_temp = Val(getcommands(1))                   'zamien tekst na numer
  17.  
  18.   Select Case Rs485_adres_temp                             ' tymczasowy adres do porównania
  19.  
  20.      Case Rs485_adres:                                     'komenda 1 case 1, sprawdzenie adresu
  21.         Print #2 , "odebrlem poprawnie adres "
  22.        'Tu kod jakis
  23.         Select Case Getcommands(2)
  24.  
  25.            Case G2_c_1:                                    '  jesli odebralem komende druga czyli getcommand(2)
  26.  
  27.               Print #2 , "jestem w command 2, case 1"
  28.               Select Case Getcommands(3)
  29.                  Case G3_c1:                               'On
  30.                     Porta.4 = 1
  31.                  Case G3_c2:                               'Off
  32.                     Porta.4 = 0
  33.                  Case Else:                                'anything else
  34.                     Getcommands(1) = ""
  35.                     Getcommands(2) = ""
  36.                     Getcommands(3) = ""
  37.               End Select
  38.  
  39.            Case G2_c_2:                                    '
  40.               Print #2 , "jestem w command 2, case 2 "     '
  41.               Select Case Getcommands(3)
  42.                  Case G3_c1:                               'On
  43.                     Porta.5 = 1
  44.                  Case G3_c2:                               'Off
  45.                     Porta.5 = 0
  46.                  Case Else:                                'anything else
  47.                     Getcommands(1) = ""
  48.                     Getcommands(2) = ""
  49.                     Getcommands(3) = ""
  50.               End Select
  51.  
  52.            Case G2_c_3:                                    '
  53.               Print #2 , "jestem w command 2, case 3 "     '
  54.               Select Case Getcommands(3)
  55.                  Case G3_c1:                               'On
  56.                     Porta.6 = 1
  57.                  Case G3_c2:                               'Off
  58.                     Porta.6 = 0
  59.                  Case Else:                                'anything else
  60.                     Getcommands(1) = ""
  61.                     Getcommands(2) = ""
  62.                     Getcommands(3) = ""
  63.               End Select
  64.            Case G2_c_4:                                    'High Current output 4
  65.               Print #2 , "jestem w command 2, case 4 "     '
  66.               Select Case Getcommands(3)
  67.                  Case G3_c1:                               'On
  68.                     Porta.7 = 1
  69.                  Case G3_c2:                               'Off
  70.                     Porta.7 = 0
  71.                  Case Else:                                'anything else
  72.                     Getcommands(1) = ""
  73.                     Getcommands(2) = ""
  74.                     Getcommands(3) = ""
  75.               End Select
  76.  
  77.            Case G2_c_5:                                    'o5 RS485 BUS power
  78.               Print #2 , "jestem w command 2, case 5 "     '
  79.               Select Case Getcommands(3)
  80.                  Case G3_c1:
  81.                     Portb.0 = 0                            'On
  82.                  Case G3_c2:                               'Off
  83.                     Portb.0 = 1
  84.                     Getcommands(1) = ""
  85.                     Getcommands(2) = ""
  86.                     Getcommands(3) = ""
  87.                  Case Else:                                'anything else
  88.  
  89.               End Select
  90.            Case G2_c_6:                                    ' low current output 6
  91.               Print #2 , "jestem w command 2, case 6 "     '
  92.               Select Case Getcommands(3)
  93.                  Case G3_c1:                               'On
  94.                     Portb.1 = 0
  95.                  Case G3_c2:                               'Off
  96.                     Portb.1 = 1
  97.                  Case Else:                                'anything else
  98.                     Getcommands(1) = ""
  99.                     Getcommands(2) = ""
  100.                     Getcommands(3) = ""
  101.               End Select
  102.  
  103.            Case G2_c_7:                                    'output 7
  104.               Print #2 , "jestem w command 2, case 7 "     '
  105.               Select Case Getcommands(3)
  106.                  Case G3_c1:                               'On
  107.                     Portb.2 = 0
  108.                  Case G3_c2:                               'Off
  109.                     Portb.2 = 1
  110.                  Case Else:                                'anything else
  111.                     Getcommands(1) = ""
  112.                     Getcommands(2) = ""
  113.                     Getcommands(3) = ""
  114.               End Select
  115.            Case G2_c_8:                                    'output 8
  116.               Print #2 , "jestem w command 2, case 8 "     '
  117.               Select Case Getcommands(3)
  118.                  Case G3_c1:                               'On
  119.                     Portb.3 = 0
  120.                  Case G3_c2:                               'Off
  121.                     Portb.3 = 1
  122.                  Case Else:                                'anything else
  123.                     Getcommands(1) = ""
  124.                     Getcommands(2) = ""
  125.                     Getcommands(3) = ""
  126.               End Select
  127.  
  128.            Case G2_c_9:                                    'ooutput 9
  129.               Print #2 , "jestem w command 2, case 9 "     '
  130.               Select Case Getcommands(3)
  131.                  Case G3_c1:                               'On
  132.                     Portb.4 = 0
  133.                  Case G3_c2:                               'Off
  134.                     Portb.4 = 1
  135.                  Case Else:                                'anything else
  136.                     Getcommands(1) = ""
  137.                     Getcommands(2) = ""
  138.                     Getcommands(3) = ""
  139.               End Select
  140.            Case G2_c_10:                                   'all outputs off
  141.               Print #2 , "jestem w command 2, case 10 "    '
  142.               Select Case Getcommands(3)
  143.                  Case G3_c1:                               'On
  144.                     Porta.3 = 1
  145.                     Porta.4 = 1
  146.                     Porta.5 = 1
  147.                     Porta.6 = 1
  148.                     Portb.0 = 0                            'RS485
  149.                     Portb.1 = 0                            'low current output
  150.                     Portb.2 = 0                            'low current output
  151.                     Portb.3 = 0                            'low current output
  152.                     Portb.4 = 0                            'low current output
  153.                  Case G3_c2:                               'Off
  154.                     Porta.3 = 0
  155.                     Porta.4 = 0
  156.                     Porta.5 = 0
  157.                     Porta.6 = 0
  158.                     Portb.0 = 1                            'RS485
  159.                     Portb.1 = 1                            'low current output
  160.                     Portb.2 = 1                            'low current output
  161.                     Portb.3 = 1                            'low current output
  162.                     Portb.4 = 1                            'low current output
  163.  
  164.                  Case Else:                                'anything else
  165.                     Getcommands(1) = ""
  166.                     Getcommands(2) = ""
  167.                     Getcommands(3) = ""
  168.               End Select
  169.  
  170.            Case Rs485_term_off:
  171.               Print #2 , "jestem w command 2, case RS_term off "       '
  172.               Portc.5 = 0                                  'terminacja wylaczona
  173.               Rs485_term = 0
  174.               Rs485_term_ee = Rs485_term
  175.               Print Chr(6);                                'send ACK
  176.  
  177.            Case Rs485_term_on:
  178.               Print #2 , "jestem w command 2, case RS_term_on "       '
  179.               Portc.5 = 1                                  'terminacja wlaczona
  180.               Rs485_term = 1
  181.               Rs485_term_ee = Rs485_term
  182.               Print Chr(6);                                'send ACK
  183.  
  184.            Case G2_c_10:                                   ' address    space number
  185.               Print #2 , "jestem w command 2, case 10 "    'ustaw adres
  186.               'Print "Input new address(1-254): "
  187.               Rs485_adres = Val(getcommands(3))
  188.               Rs485_adres_ee = Rs485_adres
  189.               Print Chr(6);                                'send ACK
  190.  
  191.            Case G2_c_11:                                   'da?
  192.               Print #2 , "jestem w command 2, case 11 "    'ustaw defaultowa antenne
  193.               Def_out = Def_out_ee                         ' read from EEPROM default antenna
  194.  
  195.               Print "default antenna:" ; Def_out
  196.  
  197.            Case G2_c_12:
  198.               Print #2 , "jestem w command 2, case 11 "    'ustaw defaultowa antenne
  199.               'Print "Input new default antenna (0-4): "
  200.               Def_out = Val(getcommands(3))
  201.               Def_out_ee = Def_out                         ' write to EEPROM default antenna
  202.               Print #2 , Chr(6);                           ' send ACK
  203.            Case Reboot:
  204.                 'zrestartój system
  205.               Print #2 , "Switch:" ; Rs485_adres
  206.               Print #2 , "Device will now reboot"
  207.               'Start Watchdog
  208.               Do
  209.               Loop
  210.  
  211.            Case Firmware_version:
  212.               Print #2 , "Switch:" ; Rs485_adres
  213.               Print #2 , "Version:" ; Version(2)
  214.  
  215.            Case Bootloader:                                'load
  216.               Debug "jestem w command 1, reboot "
  217.               Disable Interrupts
  218.               'Config Watchdog = 16
  219.               'Start Watchdog
  220.               'Stop Timer1
  221.               'Informacja dla mnie bo zapomne :)
  222.               ' Ustaw fusy booltlaoder na 1024 adres &H3C00
  223.               ' w oknie bootloadera dodaj adres i komende:
  224.               ' 1 load {13}
  225.               Do
  226.  
  227.               Loop
  228.  
  229.  
  230.            Case Help :                                     '?
  231.               Print #2 , "Power distributor EI9HEB/SP9DR"
  232.               Print #2 , "EI9SP Sierra Papa DX Group"
  233.               Print #2 , "Version:" ; Version(2)
  234.               Print #2 , "RS_485 Adres:" ; Rs485_adres
  235.               Print #2 , "RS485, 120 Ohm, BUS Termination:";
  236.               If Portc.5 = 1 Then
  237.                  Print #2 , "Enabled"
  238.               Else
  239.                  Print #2 , "Disabled"
  240.               End If
  241.               Print #2 , "Command example:"
  242.               Print #2 , "(address)_(o)(number)_(on/off)"
  243.               Print #2 , "Default output:" ; Def_out
  244.               Print #2 , "o?------------Get active output"
  245.               Print #2 , "o1------------Output 1"
  246.               Print #2 , "o2------------Output 2"
  247.               Print #2 , "o3------------Output 3"
  248.               Print #2 , "o4------------Output 4"
  249.               Print #2 , "o5------------BUS Power"
  250.               Print #2 , "o6------------Output 6"
  251.               Print #2 , "o7------------Output 7"
  252.               Print #2 , "o8------------Output 8"
  253.               Print #2 , "o9------------Output 9"
  254.               Print #2 , "all-----------All outputs"
  255.               Print #2 , "address-(0-254)------Set new rs485 address"
  256.               Print #2 , "do?-----------Get default output"
  257.               Print #2 , "do (number)---Set default output"
  258.               Print #2 , "rs_term_on----BUS Termination Enabled"
  259.               Print #2 , "rs_term_off---BUS Termination Disabled"
  260.               Print #2 , "reboot -------System Restart"
  261.               Print #2 , "fw?-----------Get firmware version"
  262.               'Print "sn?-----------Get serial number"
  263.               'Print #2 , "load----------Firmware update"
  264.               Print #2 , "?-------------Get command list"
  265.  
  266.            Case Else:
  267.  
  268.                 'ponizej NIE USUWAJ TO JEST WAZNE!
  269.                 'jak komenda nie rozpoznana zrób to
  270.                 'Print Prompt ; " " ; Uart_command ; " " ; Notincommands
  271.                 'Print Prompt
  272.  
  273.               Getcommands(1) = ""
  274.               Getcommands(2) = ""
  275.               Getcommands(3) = ""
  276.  
  277.         End Select
  278.         'ponizej NIE USUWAJ TO JEST WAZNE!
  279.         'jak komenda nei rozpoznana zrób to
  280.         Getcommands(1) = ""
  281.         Getcommands(2) = ""
  282.         Getcommands(3) = ""
  283.  
  284.      Case Broadcast:                                       '255 broadcast do wszystkich
  285.         Debug "odebrlem poprawnie adres "
  286.         'stop timer1  ' stop timer used to blink the green led
  287.         Flag1.0 = 1
  288.         'Portd.4 = 0 ' turn off green led
  289.         Porta.3 = 1                                        ' ready to print
  290.         'Portd.4 = 1  ' turn on the green led
  291.         Select Case Getcommands(2)
  292.  
  293.            Case Reboot:
  294.  
  295.               Print #2 , "Device address:" ; Rs485_adres ; " will now reboot"
  296.               'Start Watchdog
  297.  
  298.            Case Help :                                     '?
  299.  
  300.  
  301.               Print #2 , "Power Distributor by EI9HEB/SP9DR"
  302.               Print #2 , "Version:" ; Version(2)
  303.               Print #2 , "RS_485 Address:" ; Rs485_adres
  304.               Print #2 , "RS485, 120 Ohm, BUS Termination:";
  305.               If Porta.3 = 1 Then
  306.                  Print #2 , "Enabled"
  307.               Else
  308.                  Print #2 , "Disabled"
  309.               End If
  310.               Print #2 , "RS_485 Addres:" ; Rs485_adres
  311.               Print #2 , "Default output port:" ; Def_out
  312.               Print #2 , Chr(10) ; "----Command list:---"
  313.               Print #2 , "o?------------Get active output number"
  314.               Print #2 , "o0------------All off"
  315.               Print #2 , "o1------------Output 1"
  316.               Print #2 , "o2------------Output 2"
  317.               Print #2 , "o3------------Output 3"
  318.               Print #2 , "o4------------Output 4"
  319.               Print #2 , "o5------------BUS Power"
  320.               Print #2 , "o6------------Output 6"
  321.               Print #2 , "o7------------Output 7"
  322.               Print #2 , "o8------------Output 8"
  323.               Print #2 , "o9------------Output 9"
  324.               Print #2 , "all-----------All ON!"
  325.               Print #2 , "address-(0-254)------Set new rs485 address"
  326.               Print #2 , "do?-----------Get Default antenna port"
  327.               Print #2 , "do (number)---Set Default antenna port"
  328.               Print #2 , "rs_term_on----BUS Termination Enabled"
  329.               Print #2 , "rs_term_off---BUS Termination Disabled"
  330.               Print #2 , "reboot -------System Restart"
  331.               Print #2 , "load----------Firmware update"
  332.               Print #2 , "?-------------Get command list"
  333.  
  334.  
  335.            Case G2_c_5:                                    'all off
  336.               Debug "jestem w command 2, case 5"           '
  337.  
  338.               Ant_flag = 0
  339.  
  340.            'Case Bootloader:                                      'load
  341.               'Debug "jestem w command 1, reboot "
  342.               'Disable Interrupts
  343.               'Config Watchdog = 16
  344.               'Start Watchdog
  345.               'Stop Timer1
  346.               'Informacja dla mnie bo zapomne :)
  347.               ' Ustaw fusy bootlaoder na 1024 adres &H3C00
  348.               ' w oknie bootloadera dodaj adres i komende:
  349.               ' 1 load {13}
  350.               'Do
  351.               'Loop
  352.  
  353.            Case Else:
  354.  
  355.                 'Print Prompt ; " " ; Uart_command ; " " ; Notincommands
  356.               'Print Prompt
  357.               Getcommands(1) = ""
  358.               Getcommands(2) = ""
  359.               Getcommands(3) = ""
  360.         End Select
  361.  
  362.         Getcommands(1) = ""
  363.         Getcommands(2) = ""
  364.         Getcommands(3) = ""
  365.  
  366.      Case Else:
  367.         Print #2 , "Routing to port 1"
  368.         Print #1 , Getcommands(1) ; Chr(20) ; Getcommands(2) ; Chr(20) ; Getcommands(3) ; Chr(13);
  369.  
  370.  
  371.      'Case Else
  372.      'ponizej NIE USUWAJ TO JEST WAZNE!
  373.         'Debug "odebrlem zly adres "
  374.         'Print Prompt ; " " ; Uart_command ; " " ; Notincommands
  375.         'Print Prompt
  376.         'Jelsi zly adres wyczysc wszytkie komorki z odebranymi danymi
  377.  
  378.         Getcommands(1) = ""
  379.         Getcommands(2) = ""
  380.         Getcommands(3) = ""
  381.   End Select
  382.   'ponizej NIE USUWAJ TO JEST WAZNE!
  383.   'jak komenda nie rozpoznana zrób to
  384.  
  385.   Getcommands(1) = ""
  386.   Getcommands(2) = ""
  387.   Getcommands(3) = ""
  388.  
  389. End Sub
ODPOWIEDZ