Podgląd co wysyła Nextion w HEX

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

Podgląd co wysyła Nextion w HEX

Post autor: Jacek » 23 sty 2022, 21:33

Witam na podstawie programu Pawła z tego tematu viewtopic.php?p=3206#p3206
napisałem program który ma wyświetlać w terminalu to co wyświetlacz Nextion wysyła
  1. 'program testowy Bascom  Nextion
  2.  
  3. $regfile = "m2560def.dat"                                                       'deklaracja mikrokontrolera
  4. $crystal = 16000000                                                             'deklaracja zewnętrzego kwarcu taktującego mikrokontroler
  5. $hwstack = 256
  6. $swstack = 128
  7. $framesize = 256
  8. $projecttime = 74
  9. $version 0 , 0 , 48
  10. '$baud = 9600
  11. '$baud1 = 9600
  12.  
  13. Debug On
  14.  
  15. Config Submode = New
  16. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  17. '                                       Konfiguracja UART'ów
  18. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  19. Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8
  20. Config Serialin0 = Buffered , Size = 100                                        'buforowoanie  pierwszy uart
  21. Config Serialout0 = Buffered , Size = 100                                       'buforowoanie  pierwszy uart
  22. Open "Com1:" For Binary As #1
  23. Const Usb = 1
  24. Config Com2 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8
  25. Config Serialin1 = Buffered , Size = 100                                        'buforowoanie  drugi uart
  26. Config Serialout1 = Buffered , Size = 100                                       'buforowoanie  drugi uart
  27. Open "Com2:"For Binary As #2
  28. Const Nex = 2
  29. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  30. '                                           Deklaracje Zmiennych
  31. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  32. Dim Tablica_tx_nex(10) As byte
  33. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  34. Enable Interrupts
  35. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  36.  
  37. Wait 1
  38.  
  39. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  40.  
  41. Do
  42.    While Ischarwaiting(#nex) <> 0                                               'gdy znak czeka w buforze
  43.       Inputbin , Tablica_tx_nex(1) , 10                                         'obierz 10 bajtów zapisz  zaczynajac od komórki 1
  44.    Wend
  45.  
  46.    Print #usb , "D1 " ; Tablica_tx_nex(1)
  47.    Print #usb , "D2 " ; Tablica_tx_nex(2)
  48.    Print #usb , "D3 " ; Tablica_tx_nex(3)
  49.    Print #usb , "D4 " ; Tablica_tx_nex(4)
  50.    Print #usb , "D5 " ; Tablica_tx_nex(5)
  51.    Print #usb , "D6 " ; Tablica_tx_nex(6)
  52.    Print #usb , "D7 " ; Tablica_tx_nex(7)
  53.    Print #usb , "D8 " ; Tablica_tx_nex(8)
  54.    Print #usb , "D9 " ; Tablica_tx_nex(9)
  55.    Print #usb , "D10 " ; Tablica_tx_nex(10)
  56.  
  57.  
  58. Loop
  59. End
  60.  
ale coś chyba źle napisałem go atmega odpowiada tyko jeden raz zaraz po nawiązaniu połączenia z terminalem
terminal1.jpg
czy trzeba czyścić bufor za każdym razem po odebraniu wszystkich 10 bajtów.
proszę o podpowiedź.
pozdrawiam Jacek.
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.
Awatar użytkownika
niveasoft
Posty: 1213
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Podgląd co wysyła Nextion w HEX

Post autor: niveasoft » 24 sty 2022, 10:30

Tego się raczej tak nie robiło. Nextion chyba w pierwszych bajtach pisze ile będzie nadawał dalej bajtów.
Ty zawsze czekasz na dziesięć bajtów a tam może być coś innego.
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Podgląd co wysyła Nextion w HEX

Post autor: Jacek » 24 sty 2022, 21:11

Dziękuję za odpowiedź, czy na podstawie Twojego programu na forum MCS https://www.mcselec.com/index2.php?opti ... ht=nextion o parsowaniu danych można za pomocą
pobierać i wysyłać dane do i z wyświetlacza?
pozdrawiam Jacek.
Awatar użytkownika
niveasoft
Posty: 1213
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Podgląd co wysyła Nextion w HEX

Post autor: niveasoft » 24 sty 2022, 21:14

No całkiem tego nie pamiętam. Na pewno ten kod potem rozwinąłem.
W pierwszym bajcie Nextion gada jakiego typu jest wiadomość. Na tej podstawie można przewidzieć ile będzie bajtów potem.
Jakoś "tak to leciało" :D

W tym kodzie jest też odbieranie danych z PC USB więc trochę zaciemniony. To na potrzeby podsłuchu i resetu do wymiany softu.
Jak z terminala wyślesz AT+ON i oczywiście CrLf to włączy podsłuch dotyku. AT+OFF wyłącza.
Gdzieś był drugi kod z funkcjami wysyłania do Nextiona.


  1. $regfile = "m2560def.dat"                                   '8K SRAM | 4K EEPROM
  2. $crystal = 16000000
  3. $hwstack = 256
  4. $swstack = 128
  5. $framesize = 256
  6. $baud = 115200
  7. $baud1 = 9600
  8.  
  9. Debug On
  10.  
  11. Config Submode = New
  12.  
  13. Const Max_usb_in_command_len = 50
  14. Const Max_nex_command_len = 50
  15. '*****************************************************************
  16. '*         CONFIG BUFFERED USART FOR DEBUG via USB               *
  17. '*****************************************************************
  18.  
  19. Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
  20.  Echo Off
  21.  
  22.  Config Serialin0 = Buffered , Size = Max_usb_in_command_len       'RX from Terminal
  23.   Dim Char As Byte , Cmd_timeout1 As Byte , Got_str1 As Byte
  24.   Dim Command1 As String * Max_usb_in_command_len
  25.  
  26.  'Config Serialout0 = Buffered , Size = Max_usb_out_command_len       'TX to the Terminal
  27.   Open "COM1:" For Binary As #1
  28.     Const Usb = 1
  29. '*****************************************************************
  30. '*           CONFIG BUFFERED USART FOR NEXTION                   *
  31. '*****************************************************************
  32.  
  33. Config Com2 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
  34.  
  35.  Config Serialin1 = Buffered , Size = Max_nex_command_len   'RX
  36.   Dim Cmd_timeout As Byte , Got_str As Byte
  37. 'unnecessary
  38.   Dim Command As String * Max_nex_command_len
  39.  
  40.  'Config Serialout1 = Buffered , Size = Max_nex_command_len         'TX
  41.   Open "COM2:" For Binary As #2
  42.    Const Nex = 2
  43.  
  44. '*****************************************************************
  45. '*                TIMER2 FOR TIME BASE                           *
  46. '*****************************************************************
  47. Config Timer2 = Timer , Prescale = 1024 , Compare_a = Disconnect , Compare_b = Disconnect , Clear_timer = 1
  48.  Compare2a = 155                                            '10ms @16MHz/1024
  49.  
  50.  
  51.  
  52. 'BARTek multipurpose
  53. Dim Helpb As Byte , Helpstr As String * 30 , N As Byte , Tempb As Byte , Helpl As Long
  54.  
  55. Enable Interrupts                                           'buffered USART
  56.  
  57. Print #usb , "Program restarted"
  58.  
  59. 'NEXTION RETURN DATA                                        LENGTH
  60. Const Invalid_instruction = &H00                            '4
  61. Const Instruction_okay = &H01                               '4
  62. Const Invalid_component_id = &H02                           '4
  63. Const Invalid_page_id = &H03                                '4
  64. Const Invalid_picture_id = &H04                             '4
  65. Const Invalid_font_id = &H05                                '4
  66. Const Invalid_file_operation = &H06                         '4
  67. Const Invalid_crc = &H09                                    '4
  68. Const Invalid_baud_rate = &H11                              '4
  69. Const Invalid_vaweform_id = &H12                            '4
  70. Const Invalid_variable_name = &H1A                          '4
  71. Const Invalid_variable_operation = &H1B                     '4
  72. Const Assignement_failed = &H1C                             '4
  73. Const Eeprom_operation_failed = &H1D                        '4
  74. Const Invalid_parameters_quantity = &H1E                    '4
  75. Const Io_operation_failed = &H1F                            '4
  76. Const Escape_char_invalid = &H20                            '4
  77. Const Variable_name_to_long = &H23                          '4
  78. 'return codes valid  in all cases
  79. '00 00 00 FF FF FF =>Nextion starup                          '6
  80. Const Serial_buff_overflow = &H24                           '4
  81. Const Touch_event = &H65                                    '7
  82. ' 65 00 01 01 FF FF FF
  83. ' |   |  |  |
  84. ' |   |  |  event 01=press, 00=release
  85. ' |   |  component ID
  86. ' |   page number
  87. ' touch event
  88. Const Curr_page_num = &H66                                  '5 second byte is page num
  89. Const Touch_awake_coordinate = &H67                         '9
  90. Const Touch_sleep_coordinate = &H68
  91.  'first two bytes is X
  92.  'next two bytes is Y
  93.  'last byte is event 01=press, 00=release
  94.  'eg. 67 00 7A 00 1E 01 FF FF FF
  95. Const String_data = &H70                                    'varied len eg.70 xx xx xx xx xx xx FF FF FF
  96. Const Numeric_data = &H71                                   '8 eg.71 xx xx xx xx FF FF FF  <-4bytes 32bit value, little endian
  97. Const Auto_sleep = &H86                                     '4
  98. Const Auto_awake = &H87                                     '4
  99. Const Nextion_ready = &H88                                  '4
  100. Const Micro_sd_upgrade = &H89                               '4
  101. Const Transp_data_finished = &HFD                           '4
  102. Const Transp_data_ready = &HFE                              '4
  103.  
  104. Macro Nexend                                                'to end a tx sequence--------------------------
  105.      Printbin #nex , &HFF ; &HFF ; &HFF
  106. End Macro
  107.  
  108. Macro Nexq                                                  ' to send quote before or after a sentence---------
  109.      Printbin &H22
  110. End Macro
  111.  
  112. Sub Set_return_level()
  113.   'how much return will be sent over serial
  114.   'LEVEL (2 is default)
  115.   '0=no return command will be sent
  116.   '1=only confirm succes commands
  117.   '2=only if command failed
  118.   '3=all return command from &H00 to &H23 will be sent
  119.    Print #nex , "bkcmd=1";
  120.    Nexend
  121. End Sub
  122.  
  123. Dim Nex_buff(30) As Byte , Nex_idx As Byte , End_cnt As Byte , Min_len As Byte
  124. Dim New_long As Long At Nex_buff(2) Overlay
  125. Dim New_string As String * 29 At Nex_buff(2) Overlay
  126. 'for touch event
  127. Dim Touch_page As Byte At Nex_buff(2) Overlay
  128. Dim Touch_id As Byte At Nex_buff(3) Overlay
  129. Dim Touch_state As Byte At Nex_buff(4) Overlay              '1=press , 0=release
  130. 'for coordinates
  131. Dim New_x As Word At Nex_buff(2) Overlay
  132. Dim New_y As Word At Nex_buff(4) Overlay
  133.  
  134. Call Set_return_level
  135.  
  136.  
  137. Do
  138.  
  139.  
  140.  
  141.   '--[ USART0 COM1 USB ]------------------------
  142.   If 0 < Ischarwaiting(#usb) Then
  143.  
  144.    Char = Inkey(#usb)
  145.     Cmd_timeout1 = 10                                       '
  146.  
  147.    Select Case Char
  148.     Case 10 : Got_str1 = 1
  149.     Case 13
  150.     Case Else
  151.      Command1 = Command1 + Chr(char)
  152.  
  153.    End Select
  154.  
  155.    If Len(command1) > 49 Then Got_str1 = 1
  156.  
  157.    If Got_str1 = 0 Then Cmd_timeout1 = 50                   '50x10ms
  158.  
  159.    'end if Ischarwaiting
  160.   End If
  161.  
  162.   '--[ PARSE COM1 USB ]-------------------------
  163.   If Got_str1 = 1 Then
  164.  
  165.  
  166.         If 0 < Instr(command1 , "AT+RST") Then
  167.  
  168.           Print #usb , "Reseting in progress..."
  169.                  
  170.           Config Watchdog = 16
  171.           Start Watchdog
  172.           Do : Loop
  173.  
  174.         Elseif 0 < Instr(command1 , "AT+ON") Then
  175.  
  176.            Print #nex , "sendxy=1";
  177.            Nexend
  178.  
  179.         Elseif 0 < Instr(command1 , "AT+OFF") Then
  180.  
  181.            Print #nex , "sendxy=0";
  182.            Nexend
  183.  
  184.         End If
  185.  
  186.       Got_str1 = 0
  187.     Command1 = ""
  188.    Cmd_timeout1 = 0
  189.  
  190.  
  191.   End If
  192.  
  193.  '--[ USART1 COM2 nex ]---------------------
  194.   If 0 < Ischarwaiting(#nex) Then
  195.  
  196.     Incr Nex_idx
  197.      Nex_buff(nex_idx) = Waitkey(#nex)
  198.      Cmd_timeout = 10                                       'unnecessary
  199.  
  200.     If Nex_idx = 1 Then                                     'check what type of msg we receiving
  201.      Select Case Nex_buff(1)
  202.  
  203.       Case 0
  204.        'it can be 4bytes Invalid_instruction
  205.        'or 6 bytes Nextion_startup (may be after reset)
  206.         Min_len = 1
  207.  
  208.       Case Touch_event
  209.         Min_len = 4
  210.       Case Touch_awake_coordinate                           '9 bytes
  211.         Min_len = 6
  212.       Case Touch_sleep_coordinate                           '9 bytes
  213.         Min_len = 6
  214.  
  215.       Case String_data                                      'it will be string with variable len
  216.         Min_len = 2
  217.       Case Numeric_data                                     'there can be FF`s so we must wait for 8 bytes
  218.         Min_len = 5
  219.  
  220.       Case Else
  221.         Min_len = 1                                         'rest of return`s have one byte followed three FF`s
  222.  
  223.      End Select
  224.  
  225.     Else
  226.                                                         'msg continue
  227.      If Nex_buff(nex_idx) = &HFF Then
  228.       If Nex_idx > Min_len Then
  229.  
  230.        If End_cnt < 2 Then
  231.         Incr End_cnt
  232.  
  233.        Else                                                 'we received third FF
  234.  
  235. '         '-----------------------------[ DEBUG ]----------
  236. '          Debug #usb , "Debug=> ";
  237. '          For N = 1 To Nex_idx
  238. '           Debug #usb , Hex(nex_buff(n)) ; " ";
  239. '          Next
  240. '          Debug #usb , ""
  241. '         '------------------------------------------------
  242.  
  243.          'parse
  244.           Select Case Nex_buff(1)
  245.  
  246.            Case Invalid_instruction
  247.  
  248.             If Nex_idx = 4 Then
  249.              Debug #usb , "Invalid instruction!"
  250.             Elseif Nex_idx = 6 Then
  251.              Debug #usb , "Nextion rebooted OK"
  252.             End If
  253.  
  254.            Case Instruction_okay
  255.              Debug #usb , "Command accepted"
  256.            Case Invalid_variable_name
  257.              Debug #usb , "Variable or component NAME not recognized!"
  258.  
  259.            Case Touch_event
  260.              If Touch_state = 0 Then
  261.               Debug #usb , "Relased object " ; Touch_id ; " on page " ; Touch_page
  262.              Else
  263.               Debug #usb , "Pressed object " ; Touch_id ; " on page " ; Touch_page
  264.              End If
  265.  
  266.            Case Touch_awake_coordinate To Touch_sleep_coordinate
  267.  
  268.               Swap New_x                                    'big endian order received
  269.               Swap New_y
  270.               Debug #usb , "Coordinates are: X=" ; New_x ; " Y=" ; New_y
  271.  
  272.            Case String_data
  273.              Helpb = Nex_idx - 2
  274.              Nex_buff(helpb) = 0                            'add string terminator
  275.              Debug #usb , "New string=> " ; New_string
  276.  
  277.  
  278.               'You can parse commands/data here
  279.  
  280.  
  281.            Case Numeric_data
  282.              Debug #usb , "New value=> " ; New_long
  283.  
  284.              'If you expect numeric data from Nextion then it will be here
  285.  
  286.           End Select
  287.  
  288.  
  289.  
  290.  
  291.           Nex_idx = 0
  292.           End_cnt = 0
  293.        End If
  294.  
  295.       End If
  296.      End If
  297.  
  298.     End If
  299.  
  300.  
  301.   End If
  302.  
  303.  
  304.  '--[ TIMER2 10ms ]----------------------------
  305.  If Tifr2.ocf2a = 1 Then
  306.   Tifr2.ocf2a = 1
  307.  
  308.   If Cmd_timeout1 > 0 Then
  309.    Decr Cmd_timeout1
  310.    If Cmd_timeout1 = 0 Then
  311.      Command1 = ""
  312.    End If
  313.   End If
  314.  
  315.   If Cmd_timeout > 0 Then
  316.    Decr Cmd_timeout
  317.    If Cmd_timeout = 0 Then
  318.     Nex_idx = 0
  319.     End_cnt = 0
  320.    End If
  321.   End If
  322.  
  323.  
  324.  
  325.   '10ms
  326.  End If
  327.  
  328.  
  329. Loop
  330. End
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Podgląd co wysyła Nextion w HEX

Post autor: Jacek » 24 sty 2022, 21:31

Czy te komendy można wysłać z terminala? wpisując w linii poleceń bo coś mi nie idzie.
pozdrawiam Jacek.
P.S. jeszcze jedno mam zmienna w wyświetlaczu wprowadzanie danych jest zrobione przez wyskakująca klawiaturę numeryczną.
O ile jak nacisnę pole to nextion wysyła wartość tej zmiennej o tyle jak wprowadzę nową wartość i nacisnę OK na klawiaturze to już jej nie wysyła jak zamknie się okno klawiatury.
Szukałem po necie i na youtube jak to zrobić ale nic nie znalazłem czy może wiesz jak to zrobić?
Ostatnio zmieniony 24 sty 2022, 21:36 przez Jacek, łącznie zmieniany 1 raz.
Awatar użytkownika
niveasoft
Posty: 1213
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Podgląd co wysyła Nextion w HEX

Post autor: niveasoft » 24 sty 2022, 21:33

Każdy terminal ma inaczej. W Herculesie trzeba napisać AT+ON<CR><LF>
W innym trzeba zaznaczyć by dodawał znaki CR i LF ... no nie przyglądałem się Twojemu ;)
Kod reaguje na 10 czyli LF więc pewnie w Br@y++ trzeba zaznaczyć CR= CR+LF
No próbuj...tam są różne prędkości. USB chodzi chyba na 115200.
Awatar użytkownika
niveasoft
Posty: 1213
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Podgląd co wysyła Nextion w HEX

Post autor: niveasoft » 24 sty 2022, 21:41

Odkomentuj ten fragment to pokaże wszystko co Nextion wypluwa.
Z ta klawiaturą to nie pamiętam. Pamiętam za to że było trochę studiowania noty żeby to wszystko ogarnąć...Trzeba trochę posiedzieć.
  1. '         '-----------------------------[ DEBUG ]----------
  2. '          Debug #usb , "Debug=> ";
  3. '          For N = 1 To Nex_idx
  4. '           Debug #usb , Hex(nex_buff(n)) ; " ";
  5. '          Next
  6. '          Debug #usb , ""
  7. '         '------------------------------------------------
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Podgląd co wysyła Nextion w HEX

Post autor: Jacek » 24 sty 2022, 22:01

OK widzę co przychodzi, dzięki.
pozdrawiam Jacek.
P.S.
Wysyłając AT+ON można włączyć, a wysyłając AT+OFF wyłączyć odczyt ko ordynatów wciśniętego elementu na wyświetlaczu, fajne :D .
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Podgląd co wysyła Nextion w HEX

Post autor: Jacek » 30 sty 2022, 20:25

Witam - odblokowałem numeric keyboard w nextion i do przycisku OK dopisałem jedną linijkę nie wiem czy to czysty C
  1. //Assign loadpageid.val  and loadcmpid.val before call this page.
  2. //loadpageid.val is the caller page id, loadcmpid.val is the caller component id.
  3. if(p[loadpageid.val].b[loadcmpid.val].type==54)
  4. {
  5.   covx input.txt,p[loadpageid.val].b[loadcmpid.val].val,0,0
  6. }else if(p[loadpageid.val].b[loadcmpid.val].type==59)
  7. {
  8.   covx input.txt,temp.val,0,0
  9.   if(temp.val<0)
  10.   {
  11.     temp.val*=-1
  12.   }
  13.   for(temp2.val=0;temp2.val<p[loadpageid.val].b[loadcmpid.val].vvs1;temp2.val++)
  14.   {
  15.     temp.val*=10
  16.   }
  17.   p[loadpageid.val].b[loadcmpid.val].val=temp.val
  18.   strlen input.txt,temp.val
  19.   temp.val--
  20.   while(temp.val>=0)
  21.   {
  22.     substr input.txt,tempstr.txt,temp.val,1
  23.     if(tempstr.txt==".")
  24.     {
  25.       substr input.txt,tempstr.txt,temp.val+1,p[loadpageid.val].b[loadcmpid.val].vvs1
  26.       covx tempstr.txt,temp2.val,0,0
  27.       strlen tempstr.txt,temp.val
  28.       while(temp.val<p[loadpageid.val].b[loadcmpid.val].vvs1)
  29.       {
  30.         temp2.val*=10
  31.         temp.val++
  32.       }
  33.       p[loadpageid.val].b[loadcmpid.val].val+=temp2.val
  34.       temp.val=-1
  35.     }
  36.     temp.val--
  37.   }
  38.   substr input.txt,tempstr.txt,0,1
  39.   if(tempstr.txt=="-")
  40.   {
  41.     p[loadpageid.val].b[loadcmpid.val].val*=-1
  42.   }
  43. }else
  44. {
  45.   p[loadpageid.val].b[loadcmpid.val].txt=input.txt
  46. }
  47. get show.txt//dopisane 28-01-2022 sq2eer
  48. page loadpageid.val
i teraz po wprowadzeniu danych numerycznych i naciśnięciu OK wysyła przez com'a nową wartość.
terminal_30012022_1.jpg
Czy przez
można by było rozróżnić do której zmiennej ma trafić?
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: Podgląd co wysyła Nextion w HEX

Post autor: Jacek » 12 lut 2022, 23:09

Witam - ponownie.
W Bartka programie do komunikacji z wyświetlaczem Nextion dopisałem elementy do pobierania zmiennych z wyświetlacza i podmiany elementów graficznych użytych w projekcie.

  1. $regfile = "m2560def.dat"                                                       '8K SRAM | 4K EEPROM
  2. $crystal = 16000000
  3. $hwstack = 256
  4. $swstack = 128
  5. $framesize = 256
  6. $baud = 115200
  7. $baud1 = 9600
  8.  
  9. Debug On
  10.  
  11. Config Submode = New
  12.  
  13. Const Max_usb_in_command_len = 50
  14. Const Max_nex_command_len = 50
  15.     '*****************************************************************
  16.     '*         CONFIG BUFFERED USART FOR DEBUG via USB               *
  17.     '*****************************************************************
  18.  
  19. Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
  20. Echo Off
  21.  
  22. Config Serialin0 = Buffered , Size = Max_usb_in_command_len                     'RX from Terminal
  23. Dim Char As Byte , Cmd_timeout1 As Byte , Got_str1 As Byte
  24. Dim Command1 As String * Max_usb_in_command_len
  25.  
  26.      'Config Serialout0 = Buffered , Size = Max_usb_out_command_len       'TX to the Terminal
  27. Open "COM1:" For Binary As #1
  28. Const Usb = 1
  29.     '*****************************************************************
  30.     '*           CONFIG BUFFERED USART FOR NEXTION                   *
  31.     '*****************************************************************
  32.  
  33. Config Com2 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
  34.  
  35. Config Serialin1 = Buffered , Size = Max_nex_command_len                        'RX
  36. Dim Cmd_timeout As Byte , Got_str As Byte
  37.     'unnecessary
  38. Dim Command As String * Max_nex_command_len
  39.  
  40.      'Config Serialout1 = Buffered , Size = Max_nex_command_len         'TX
  41. Open "COM2:" For Binary As #2
  42. Const Nex = 2
  43.  
  44.     '*****************************************************************
  45.     '*                TIMER2 FOR TIME BASE                           *
  46.     '*****************************************************************
  47. Config Timer2 = Timer , Prescale = 1024 , Compare_a = Disconnect , Compare_b = Disconnect , Clear_timer = 1
  48. Compare2a = 155                                                                 '10ms @16MHz/1024
  49.  
  50. '****************************************************************
  51. Config portf.0 = Input : Pinf.0 = 1
  52. Config portf.1 = Input : Pinf.1 = 1
  53. Config portf.2 = Input : Pinf.2 = 1
  54. Config Portb.7 = Output : Portb.7 = 0
  55. '****************************************************************
  56. Z_error alias Pinf.0
  57. X_error alias Pinf.1
  58. Man_auto alias pinf.2
  59. Led_test alias portb.7
  60. '****************************************************************
  61. Dim nex_ekran as Byte
  62. Dim dp as Byte
  63. Dim spindle_h as bit
  64. Dim posZmm_new as word
  65. Dim posZmm_old as word
  66. Dim posZmm_eeprom as word
  67. Dim posZmm_h as single
  68. Dim posZmm as word
  69. Dim posXmm_new as word
  70. Dim posXmm_old as word
  71. Dim posXmm_eeprom as word
  72. Dim posXmm_h as single
  73. Dim posXmm as word
  74. Dim Z_step_new as word
  75. Dim Z_step_old as word
  76. Dim Z_step_eeprom as word
  77. Dim Z_step as word
  78. Dim X_step_new as word
  79. Dim X_step_old as word
  80. Dim X_step_eeprom as word
  81. Dim X_step as word
  82. Dim Z_screw_new as byte
  83. Dim Z_screw_old as byte
  84. Dim Z_screw_eeprom as byte
  85. Dim Z_screw as byte
  86. Dim X_screw_new as byte
  87. Dim X_screw_old as byte
  88. Dim X_screw_eeprom as byte
  89. Dim X_screw as byte
  90. Dim Enc_spind_new as word
  91. Dim Enc_spind_old as word
  92. Dim Enc_spind_eeprom as word
  93. Dim Enc_spind as word
  94. Dim Enc_Z_new as word
  95. Dim Enc_Z_old as word
  96. Dim Enc_Z_eeprom as word
  97. Dim Enc_Z as word
  98. Dim Enc_X_new as word
  99. Dim Enc_X_old as word
  100. Dim Enc_X_eeprom as word
  101. Dim Enc_X as word
  102. Dim New_id as Byte
  103. Dim New_Touch as Byte
  104. Dim New_page as long
  105. Dim Old_page as long
  106. Dim Help_print_nex as byte
  107. H_print_nex_Z alias help_print_nex.0
  108. H_print_nex_X alias help_print_nex.1
  109. H_print_nex_M_A alias help_print_nex.2
  110. Dim Help_print_eep_nex as byte
  111. H_print_Zmm_eep alias help_print_eep_nex.0
  112. H_print_Xmm_eep alias help_print_eep_nex.1
  113. H_print_Z_steps_eep alias help_print_eep_nex.2
  114. H_print_X_steps_eep alias help_print_eep_nex.3
  115. H_print_Z_screw_eep alias help_print_eep_nex.4
  116. H_print_X_screw_eep alias help_print_eep_nex.5
  117. H_print_Enc_spind_eep alias help_print_eep_nex.6
  118. H_print_Enc_Z_eep alias help_print_eep_nex.7
  119. H_print_Enc_X_eep alias help_print_eep_nex.8
  120.  
  121.  
  122. '****************************************************************
  123.  
  124.     'BARTek multipurpose
  125. Dim Helpb As Byte , Helpstr As String * 30 , N As Byte , Tempb As Byte , Helpl As Long
  126.  
  127. Enable Interrupts                                                               'buffered USART
  128.  
  129. Print #usb , "Program restarted"
  130.  
  131.     'NEXTION RETURN DATA                                        LENGTH
  132. Const Invalid_instruction = &H00                                                '4
  133. Const Instruction_okay = &H01                                                   '4
  134. Const Invalid_component_id = &H02                                               '4
  135. Const Invalid_page_id = &H03                                                    '4
  136. Const Invalid_picture_id = &H04                                                 '4
  137. Const Invalid_font_id = &H05                                                    '4
  138. Const Invalid_file_operation = &H06                                             '4
  139. Const Invalid_crc = &H09                                                        '4
  140. Const Invalid_baud_rate = &H11                                                  '4
  141. Const Invalid_vaweform_id = &H12                                                '4
  142. Const Invalid_variable_name = &H1A                                              '4
  143. Const Invalid_variable_operation = &H1B                                         '4
  144. Const Assignement_failed = &H1C                                                 '4
  145. Const Eeprom_operation_failed = &H1D                                            '4
  146. Const Invalid_parameters_quantity = &H1E                                        '4
  147. Const Io_operation_failed = &H1F                                                '4
  148. Const Escape_char_invalid = &H20                                                '4
  149. Const Variable_name_to_long = &H23                                              '4
  150.     'return codes valid  in all cases
  151.     '00 00 00 FF FF FF =>Nextion starup                          '6
  152. Const Serial_buff_overflow = &H24                                               '4
  153. Const Touch_event = &H65                                                        '7
  154.   ' 65 00 01 01 FF FF FF
  155.     ' |     |    |    |
  156.     ' |     |    |   event 01=press, 00=release
  157.     ' |     |   component ID
  158.     ' |    page number
  159.     ' touch event
  160. Const Curr_page_num = &H66                                                      '5 second byte is page num
  161. Const Touch_awake_coordinate = &H67                                             '9
  162. Const Touch_sleep_coordinate = &H68
  163.      'first two bytes is X
  164.      'next two bytes is Y
  165.      'last byte is event 01=press, 00=release
  166.      'eg. 67 00 7A 00 1E 01 FF FF FF
  167. Const String_data = &H70                                                        'varied len eg.70 xx xx xx xx xx xx FF FF FF
  168. Const Numeric_data = &H71                                                       '8 eg.71 xx xx xx xx FF FF FF  <-4bytes 32bit value, little endian
  169. Const Auto_sleep = &H86                                                         '4
  170. Const Auto_awake = &H87                                                         '4
  171. Const Nextion_ready = &H88                                                      '4
  172. Const Micro_sd_upgrade = &H89                                                   '4
  173. Const Transp_data_finished = &HFD                                               '4
  174. Const Transp_data_ready = &HFE                                                  '4
  175.  
  176. Macro Nexend                                                                    'to end a tx sequence--------------------------
  177.    Printbin #nex , &HFF ; &HFF ; &HFF
  178. End Macro
  179.  
  180. Macro Nexq                                                                      ' to send quote before or after a sentence---------
  181.    Printbin &H22
  182. End Macro
  183.  
  184. Sub Set_return_level()
  185.       'how much return will be sent over serial
  186.       'LEVEL (2 is default)
  187.       '0=no return command will be sent
  188.       '1=only confirm succes commands
  189.       '2=only if command failed
  190.       '3=all return command from &H00 to &H23 will be sent
  191.    Print #nex , "bkcmd=1";
  192.    Nexend
  193. End Sub
  194.  
  195. Dim Nex_buff(30) As Byte , Nex_idx As Byte , End_cnt As Byte , Min_len As Byte
  196. Dim New_long As Long At Nex_buff(2) Overlay
  197. Dim New_string As String * 29 At Nex_buff(2) Overlay
  198.     'for touch event
  199. Dim Touch_page As Byte At Nex_buff(2) Overlay
  200. Dim Touch_id As Byte At Nex_buff(3) Overlay
  201. Dim Touch_state As Byte At Nex_buff(4) Overlay                                  '1=press , 0=release
  202.     'for coordinates
  203. Dim New_x As Word At Nex_buff(2) Overlay
  204. Dim New_y As Word At Nex_buff(4) Overlay
  205.  
  206. Call Set_return_level
  207. '****************************************************************
  208. Help_print_eep_nex = 0
  209. Help_print_nex = 0
  210. Readeeprom posZmm_eeprom , 10
  211. Readeeprom posXmm_eeprom , 30
  212. Readeeprom Z_step_eeprom , 50
  213. Readeeprom X_step_eeprom , 70
  214. Readeeprom Z_screw_eeprom , 90
  215. Readeeprom X_screw_eeprom , 110
  216. Readeeprom Enc_spind_eeprom , 130
  217. Readeeprom Enc_Z_eeprom , 150
  218. Readeeprom Enc_X_eeprom , 170
  219. '****************************************************************
  220. posZmm_old = posZmm_eeprom
  221. posXmm_old = posXmm_eeprom
  222. Z_step_old = Z_step_eeprom
  223. X_step_old = X_step_eeprom
  224. Z_screw_old = Z_screw_eeprom
  225. X_screw_old = X_screw_eeprom
  226. Enc_spind_old = Enc_spind_eeprom
  227. Enc_Z_old = Enc_Z_eeprom
  228. Enc_X_old = Enc_X_eeprom
  229. spindle_h = 0
  230. '****************************************************************
  231.  
  232. Do
  233.  
  234.       '--[ USART0 COM1 USB ]------------------------
  235.    If 0 < Ischarwaiting(#usb) Then
  236.  
  237.       Char = Inkey(#usb)
  238.       Cmd_timeout1 = 10                                                         '
  239.  
  240.       Select Case Char
  241.          Case 10 : Got_str1 = 1
  242.          Case 13
  243.          Case Else
  244.             Command1 = Command1 + Chr(char)
  245.  
  246.       End Select
  247.  
  248.       If Len(command1) > 49 Then Got_str1 = 1
  249.  
  250.       If Got_str1 = 0 Then Cmd_timeout1 = 50                                    '50x10ms
  251.  
  252.        'end if Ischarwaiting
  253.    End If
  254.  
  255.       '--[ PARSE COM1 USB ]-------------------------
  256.    If Got_str1 = 1 Then
  257.  
  258.  
  259.       If 0 < Instr(command1 , "AT+RST") Then
  260.  
  261.          Print #usb , "Reseting in progress..."
  262.  
  263.          Config Watchdog = 16
  264.          Start Watchdog
  265.          Do : Loop
  266.  
  267.       Elseif 0 < Instr(command1 , "AT+ON") Then
  268.  
  269.          Print #nex , "sendxy=1";
  270.          Nexend
  271.  
  272.       Elseif 0 < Instr(command1 , "AT+OFF") Then
  273.  
  274.          Print #nex , "sendxy=0";
  275.          Nexend
  276.  
  277.       End If
  278.  
  279.       Got_str1 = 0
  280.       Command1 = ""
  281.       Cmd_timeout1 = 0
  282.  
  283.  
  284.    End If
  285.  
  286.      '--[ USART1 COM2 nex ]---------------------
  287.    If 0 < Ischarwaiting(#nex) Then
  288.  
  289.       Incr Nex_idx
  290.       Nex_buff(nex_idx) = Waitkey(#nex)
  291.       Cmd_timeout = 10                                                          'unnecessary
  292.  
  293.       If Nex_idx = 1 Then                                                       'check what type of msg we receiving
  294.          Select Case Nex_buff(1)
  295.  
  296.             Case 0
  297.            'it can be 4bytes Invalid_instruction
  298.            'or 6 bytes Nextion_startup (may be after reset)
  299.                Min_len = 1
  300.  
  301.             Case Touch_event
  302.                Min_len = 4
  303.             Case Touch_awake_coordinate                                         '9 bytes
  304.                Min_len = 6
  305.             Case Touch_sleep_coordinate                                         '9 bytes
  306.                Min_len = 6
  307.  
  308.             Case String_data                                                    'it will be string with variable len
  309.                Min_len = 2
  310.             Case Numeric_data                                                   'there can be FF`s so we must wait for 8 bytes
  311.                Min_len = 5
  312.  
  313.             Case Else
  314.                Min_len = 1                                                      'rest of return`s have one byte followed three FF`s
  315.  
  316.          End Select
  317.  
  318.       Else
  319.                                                             'msg continue
  320.          If Nex_buff(nex_idx) = &HFF Then
  321.             If Nex_idx > Min_len Then
  322.  
  323.                If End_cnt < 2 Then
  324.                   Incr End_cnt
  325.  
  326.                Else                                                             'we received third FF
  327.  
  328.     '         '-----------------------------[ DEBUG ]----------
  329. ''                  Debug #usb , "Debug=> ";
  330. ''                  For N = 1 To Nex_idx
  331. ''                     Debug #usb , Hex(nex_buff(n)) ; " ";
  332. ''                  Next
  333. ''                  Debug #usb , ""
  334.     '         '------------------------------------------------
  335.  
  336.              'parse
  337.                   Select Case Nex_buff(1)
  338.  
  339.                      Case Invalid_instruction
  340.  
  341.                         If Nex_idx = 4 Then
  342.                            Debug #usb , "Invalid instruction!"
  343.                         Elseif Nex_idx = 6 Then
  344.                            Debug #usb , "Nextion rebooted OK"
  345.                         End If
  346.  
  347.                      Case Instruction_okay
  348.                         Debug #usb , "Command accepted"
  349.                      Case Invalid_variable_name
  350.                         Debug #usb , "Variable or component NAME not recognized!"
  351.  
  352.                      Case Touch_event
  353.                         If Touch_state = 0 Then
  354.                            Debug #usb , "Relased object " ; Touch_id ; " on page " ; Touch_page
  355.                         Else
  356.                            Debug #usb , "Pressed object " ; Touch_id ; " on page " ; Touch_page
  357.                         End If
  358.                         New_id = Touch_id                                       'ID obiektu
  359.                         New_Touch = Touch_page                                  'strona
  360. '||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  361.  
  362.                         if Touch_id = 5 and Touch_page = 0 then
  363.                            print #nex , "get dp";
  364.                            printbin #nex , &hff
  365.                            printbin #nex , &hff
  366.                            printbin #nex , &hff
  367.                         end if
  368.                         if Touch_id = 2 and Touch_page = 1 then
  369.                            print #nex , "get dp";
  370.                            printbin #nex , &hff
  371.                            printbin #nex , &hff
  372.                            printbin #nex , &hff
  373.                         end if
  374.                         if Touch_id = 3 and Touch_page = 1 then
  375.                            print #nex , "get dp";
  376.                            printbin #nex , &hff
  377.                            printbin #nex , &hff
  378.                            printbin #nex , &hff
  379.                         end if
  380.                         if Touch_id = 2 and Touch_page = 2 then
  381.                            print #nex , "get dp";
  382.                            printbin #nex , &hff
  383.                            printbin #nex , &hff
  384.                            printbin #nex , &hff
  385.                         end if
  386.                         if Touch_id = 5 and Touch_page = 1 then
  387.                            print #nex , "get dp";
  388.                            printbin #nex , &hff
  389.                            printbin #nex , &hff
  390.                            printbin #nex , &hff
  391.                         end if
  392.                         if Touch_id = 7 and Touch_page = 4 then
  393.                            print #nex , "get dp";
  394.                            printbin #nex , &hff
  395.                            printbin #nex , &hff
  396.                            printbin #nex , &hff
  397.                         end if
  398. '****************************************************************
  399. '                        spindle pic
  400. '****************************************************************
  401.                         if Touch_id = 11 and Touch_page = 2 and spindle_h = 0 then
  402.                            if spindle_h = 0 then
  403.                               print #nex , "pic 380,20,5" ;
  404.                               printbin #nex , &hFF
  405.                               printbin #nex , &hff
  406.                               printbin #nex , &hff
  407.                               toggle spindle_h
  408.                               Debug #usb , "Spindle " ; spindle_h
  409.                            end if
  410.                         elseif Touch_id = 11 and Touch_page = 2 and spindle_h = 1 then
  411.                            if spindle_h = 1 then
  412.                               print #nex , "pic 380,20,4" ;
  413.                               printbin #nex , &hFF
  414.                               printbin #nex , &hff
  415.                               printbin #nex , &hff
  416.                               toggle spindle_h
  417.                               Debug #usb , "Spindle " ; spindle_h
  418.                            end if
  419.                         end if
  420. '||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  421.                      Case Touch_awake_coordinate To Touch_sleep_coordinate
  422.  
  423.                         Swap New_x                                              'big endian order received
  424.                         Swap New_y
  425.                         Debug #usb , "Coordinates are: X=" ; New_x ; " Y=" ; New_y
  426.  
  427.                      Case String_data
  428.                         Helpb = Nex_idx - 2
  429.                         Nex_buff(helpb) = 0                                     'add string terminator
  430.                         ''Debug #usb , "New string=> " ; New_string
  431.  
  432. '****************************************************************
  433.                   'You can parse commands/data here
  434.  
  435.  
  436.                      Case Numeric_data
  437.                         Debug #usb , "New value=> " ; New_long
  438. '||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  439.                         if New_Touch = 0 and New_id = 5 and New_long = 1 then
  440.                            New_page = New_long
  441.                         end if
  442.                         if New_Touch = 1 and New_id = 2 and New_long = 0 then
  443.                            New_page = New_long
  444.                         end if
  445.                         if New_Touch = 1 and New_id = 3 and New_long = 2 then
  446.                            New_page = New_long
  447.                         end if
  448.                         if New_Touch = 2 and New_id = 2 and New_long = 1 then
  449.                            New_page = New_long
  450.                         end if
  451.                         if New_Touch = 1 and New_id = 5 and New_long = 4 then
  452.                            New_page = New_long
  453.                         end if
  454.                         if New_Touch = 4 and New_id = 7 and New_long = 1 then
  455.                            New_page = New_long
  456.                         end if
  457.  
  458.  
  459. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  460. '                                          NEW FEED Z AXIS
  461.                         if New_Touch = 2 and New_id = 5 and New_page = 2 then
  462.                            posZmm_new = New_long
  463.                            if posZmm_old <> posZmm_new then
  464.                               posZmm_old = posZmm_new
  465.                               posZmm_h = posZmm_old / 100
  466.                               Debug #usb , "nowy posow osi Z " ; posZmm_h
  467.                               posZmm_eeprom = posZmm_old
  468.                               Writeeeprom posZmm_eeprom , 10
  469.                               Debug #usb , "Zapisana do EEprom " ; posZmm_eeprom
  470.                            end if
  471.                         end if
  472.  '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  473.  '                                    NEW FEED X AXIS
  474.                         if New_Touch = 2 and New_id = 8 and New_page = 2 then
  475.                            posXmm_new = New_long
  476.                            if posXmm_old <> posXmm_new then
  477.                               posXmm_old = posXmm_new
  478.                               posXmm_h = posXmm_old / 100
  479.                               Debug #usb , "nowy posow osi X " ; posXmm_h
  480.                               posXmm_eeprom = posXmm_old
  481.                               Writeeeprom posXmm_eeprom , 30
  482.                               Debug #usb , "Zapisana do EEprom " ; posXmm_eeprom
  483.                            end if
  484.                         end if
  485. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  486. '                                   NEW STEPS Z AXIS
  487.                         if New_Touch = 4 and New_id = 2 and New_page = 4 then
  488.                            Z_step_new = New_long
  489.                            if Z_step_old <> Z_step_new then
  490.                               Z_step_old = Z_step_new
  491.                               Debug #usb , "stepper Z " ; Z_step_old
  492.                               Z_step_eeprom = Z_step_old
  493.                               Writeeeprom Z_step_eeprom , 50
  494.                               Debug #usb , "Zapisana do EEprom " ; Z_step_eeprom
  495.                            end if
  496.                         end if
  497. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  498. '                                    NEW STEPS X AXIS
  499.                         if New_Touch = 4 and New_id = 3 and New_page = 4 then
  500.                            X_step_new = New_long
  501.                            if X_step_old <> X_step_new then
  502.                               X_step_old = X_step_new
  503.                               Debug #usb , "stepper X " ; X_step_old
  504.                               X_step_eeprom = X_step_old
  505.                               Writeeeprom X_step_eeprom , 70
  506.                               Debug #usb , "Zapisana do EEprom " ; X_step_eeprom
  507.                            end if
  508.                         end if
  509. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  510. '                                              THREAD PITCH Z AXIS
  511.                         if New_Touch = 4 and New_id = 8 and New_page = 4 then
  512.                            Z_screw_new = New_long
  513.                            if Z_screw_old <> Z_screw_new then
  514.                               Z_screw_old = Z_screw_new
  515.                               Debug #usb , "new pitch Z  " ; Z_screw_old
  516.                               Z_screw_eeprom = Z_screw_old
  517.                               Writeeeprom Z_screw_eeprom , 90
  518.                               Debug #usb , "Zapisana do EEprom " ; Z_screw_eeprom
  519.                            end if
  520.                         end if
  521. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  522. '                                          THREAD PITCH X AXIS
  523.                         if New_Touch = 4 and New_id = 9 and New_page = 4 then
  524.                            X_screw_new = New_long
  525.                            if X_screw_old <> X_screw_new then
  526.                               X_screw_old = X_screw_new
  527.                               Debug #usb , "new pitch X  " ; X_screw_old
  528.                               X_screw_eeprom = X_screw_old
  529.                               Writeeeprom X_screw_eeprom , 110
  530.                               Debug #usb , "Zapisana do EEprom " ; X_screw_eeprom
  531.                            end if
  532.                         end if
  533. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  534.  '                                  SPINDLE ENCODER PULSE
  535.                         if New_Touch = 4 and New_id = 4 and New_page = 4 then
  536.                            Enc_spind_new = New_long
  537.                            if Enc_spind_old <> Enc_spind_new then
  538.                               Enc_spind_old = Enc_spind_new
  539.                               Debug #usb , "Encoder Spindle " ; Enc_spind_old
  540.                               Enc_spind_eeprom = Enc_spind_old
  541.                               Writeeeprom Enc_spind_eeprom , 130
  542.                               Debug #usb , "Zapisana do EEprom " ; Enc_spind_eeprom
  543.                            end if
  544.                         end if
  545. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  546.  '                                  Z AXIS ENCODER PULSE
  547.                         if New_Touch = 4 and New_id = 5 and New_page = 4 then
  548.                            Enc_Z_new = New_long
  549.                            if Enc_Z_old <> Enc_Z_new then
  550.                               Enc_Z_old = Enc_Z_new
  551.                               Debug #usb , "Encoder Z " ; Enc_Z_old
  552.                               Enc_Z_eeprom = Enc_Z_old
  553.                               Writeeeprom Enc_Z_eeprom , 150
  554.                               Debug #usb , "Zapisana do EEprom " ; Enc_Z_eeprom
  555.                            end if
  556.                         end if
  557. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  558.   '                                  X AXIS ENCODER PULSE
  559.                         if New_Touch = 4 and New_id = 6 and New_page = 4 then
  560.                            Enc_X_new = New_long
  561.                            if Enc_X_old <> Enc_X_new then
  562.                               Enc_X_old = Enc_X_new
  563.                               Debug #usb , "Encoder X " ; Enc_X_old
  564.                               Enc_X_eeprom = Enc_X_old
  565.                               Writeeeprom Enc_X_eeprom , 170
  566.                               Debug #usb , "Zapisana do EEprom " ; Enc_X_eeprom
  567.                            end if
  568.                         end if
  569. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  570. '                                            loading initial settings
  571.                         if New_page = 2 then
  572.                            posZmm = posZmm_old
  573.                            posXmm = posXmm_old
  574.                            print #nex , "posZmm.val=" ; posZmm ;
  575.                            printbin #nex , &hff
  576.                            printbin #nex , &hff
  577.                            printbin #nex , &hff
  578.                            print #nex , "posXmm.val=" ; posXmm;
  579.                            printbin #nex , &hff
  580.                            printbin #nex , &hff
  581.                            printbin #nex , &hff
  582.                         end if
  583. '8888888888888888888888888888888888888888888888888888888888
  584.                         if New_page = 4 then
  585.                            Z_step = Z_step_old
  586.                            X_step = X_step_old
  587.                            Z_screw = Z_screw_old
  588.                            X_screw = X_screw_old
  589.                            Enc_spind = Enc_spind_old
  590.                            Enc_Z = Enc_Z_old
  591.                            Enc_X = Enc_X_old
  592.                            print #nex , "Z_step.val=" ; Z_step ;
  593.                            printbin #nex , &hff
  594.                            printbin #nex , &hff
  595.                            printbin #nex , &hff
  596.                            print #nex , "X_step.val=" ; X_step;
  597.                            printbin #nex , &hff
  598.                            printbin #nex , &hff
  599.                            printbin #nex , &hff
  600.                            print #nex , "Z_screw.val=" ; Z_screw ;
  601.                            printbin #nex , &hff
  602.                            printbin #nex , &hff
  603.                            printbin #nex , &hff
  604.                            print #nex , "X_screw.val=" ; X_screw;
  605.                            printbin #nex , &hff
  606.                            printbin #nex , &hff
  607.                            printbin #nex , &hff
  608.                            print #nex , "Enc_spind.val=" ; Enc_spind;
  609.                            printbin #nex , &hff
  610.                            printbin #nex , &hff
  611.                            printbin #nex , &hff
  612.                            print #nex , "Enc_Z.val=" ; Enc_Z;
  613.                            printbin #nex , &hff
  614.                            printbin #nex , &hff
  615.                            printbin #nex , &hff
  616.                            print #nex , "Enc_X.val=" ; Enc_X;
  617.                            printbin #nex , &hff
  618.                            printbin #nex , &hff
  619.                            printbin #nex , &hff
  620.                         end if
  621. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  622.  
  623.  
  624.                  'If you expect numeric data from Nextion then it will be here
  625.  
  626.                   End Select
  627.  
  628.  
  629.  
  630.  
  631.                   Nex_idx = 0
  632.                   End_cnt = 0
  633.                End If
  634.  
  635.             End If
  636.          End If
  637.  
  638.       End If
  639. '****************************************************************
  640.  
  641. '****************************************************************
  642.    End If
  643. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  644. 'działa By Pikczu
  645. '****************************************************************
  646. 'ERROR Z AXIS
  647. '+++++++++++++++++++++++++++++++++++++++++++++++++++++
  648.    if new_page = 2 and Z_error = 0 then
  649.       if H_print_nex_Z = 0 then
  650.          toggle h_print_nex_Z
  651.          print #nex , "pic 500,340,10" ;
  652.          printbin #nex , &hFF
  653.          printbin #nex , &hff
  654.          printbin #nex , &hff
  655.       end if
  656.    end if
  657.  
  658.  
  659. '+++++++++++++++++++++++++++++++++++++++++++++++++++++
  660.    if new_page = 2 and Z_error = 1 then
  661.       if H_print_nex_Z = 1 then
  662.          toggle h_print_nex_Z
  663.          print #nex , "pic 500,340,9" ;
  664.          printbin #nex , &hFF
  665.          printbin #nex , &hff
  666.          printbin #nex , &hff
  667.       end if
  668.    end if
  669.  
  670. '+++++++++++++++++++++++++++++++++++++++++++++++++++++
  671. 'ERROR X AXIS
  672. '+++++++++++++++++++++++++++++++++++++++++++++++++++++
  673.    if new_page = 2 and X_error = 0 then
  674.       if H_print_nex_X = 0 then
  675.          toggle h_print_nex_X
  676.          print #nex , "pic 650,340,10" ;
  677.          printbin #nex , &hFF
  678.          printbin #nex , &hff
  679.          printbin #nex , &hff
  680.       end if
  681.    end if
  682. '+++++++++++++++++++++++++++++++++++++++++++++++++++++
  683.    if new_page = 2 and X_error = 1 then
  684.       if H_print_nex_X = 1 then
  685.          toggle h_print_nex_X
  686.          print #nex , "pic 650,340,9" ;
  687.          printbin #nex , &hFF
  688.          printbin #nex , &hff
  689.          printbin #nex , &hff
  690.       end if
  691.    end if
  692.  
  693. '+++++++++++++++++++++++++++++++++++++++++++++++++++++
  694. 'changing the operating mode from manual to automatic
  695. '+++++++++++++++++++++++++++++++++++++++++++++++++++++
  696.    if new_page = 2 and Man_auto = 0 then
  697.       if H_print_nex_M_A = 0 then
  698.          toggle H_print_nex_M_A
  699.          print #nex , "pic 20,330,8" ;
  700.          printbin #nex , &hFF
  701.          printbin #nex , &hff
  702.          printbin #nex , &hff
  703.       end if
  704.    end if
  705. '+++++++++++++++++++++++++++++++++++++++++++++++++++++
  706.    if new_page = 2 and Man_auto = 1 then
  707.       if H_print_nex_M_A = 1 then
  708.          toggle H_print_nex_M_A
  709.          print #nex , "pic 20,330,6" ;
  710.          printbin #nex , &hFF
  711.          printbin #nex , &hff
  712.          printbin #nex , &hff
  713.       end if
  714.    end if
  715. '+++++++++++++++++++++++++++++++++++++++++++++++++++++
  716. 'if old_page=0 and
  717.    if Z_error = 0 or X_error = 0 then
  718.       Led_test = 1
  719.    else
  720.       Led_test = 0
  721.    end if
  722.  
  723.  
  724.  '****************************************************************
  725.      '--[ TIMER2 10ms ]----------------------------
  726.    If Tifr2.ocf2a = 1 Then
  727.       Tifr2.ocf2a = 1
  728.  
  729.       If Cmd_timeout1 > 0 Then
  730.          Decr Cmd_timeout1
  731.          If Cmd_timeout1 = 0 Then
  732.             Command1 = ""
  733.          End If
  734.       End If
  735.  
  736.       If Cmd_timeout > 0 Then
  737.          Decr Cmd_timeout
  738.          If Cmd_timeout = 0 Then
  739.             Nex_idx = 0
  740.             End_cnt = 0
  741.          End If
  742.       End If
  743.  
  744.  
  745.  
  746.       '10ms
  747.    End If
  748.  
  749.  
  750. Loop
  751. End
  752.  
Nagrałem krótki film jak to narazie działa https://www.youtube.com/watch?v=ShikggGkD58
Napewno można to duzo poprawić.
Próbuje ten Bartka program przenieść na Xmegę ale juz przy konfiguracji portu wyskakuje błąd
  1.  
  2. '************ CONFIGURATION 'COM5 UART_E0 **************************************
  3. '              ' TX-PORTE.3 ' RX-PORTE.2   debug
  4. Config Com5 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
  5.  'Open "COM5:" For Binary As #buart_channel                  'channel 4
  6. Config Serialin4 = Buffered , Size = Max_usb_in_command_len                     '128 , Bytematch = None                     'for COM4
  7. 'Config Serialout4 = Buffered , Size = Max_usb_out_command_len                   '128
  8. Dim Char As Byte , Cmd_timeout1 As Byte , Got_str1 As Byte
  9. Dim Command1 As String * Max_usb_in_command_len
  10. Open "COM5:" For Binary As #4
  11. Const Usb = 4
  12.  
  1.  
  2. Error : 222   Line :   101   Illegal character [expected (, got '' [MAX_USB_IN_COMMAND_LEN]]  , in File : J:\Projekty-Bascom\Tokarka5\Tokarka5.bas
  3. Error : 377   Line :   101   Unexpected non numeric characters found [MAX_USB_IN_COMMAND_LEN]  , in File : J:\Projekty-Bascom\Tokarka5\Tokarka5.bas
  4.  
Gdzie leży problem, proszę o pomoc.
pozdrawiam Jacek.
ODPOWIEDZ