View previous topic :: View next topic |
Author |
Message |
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Fri Mar 01, 2019 3:59 pm Post subject: Recept nul char / Bascom |
|
|
Hello,I am trying to receive characters from a LCD 4D System. Commands sent by the LCD may contain Nulls (00).For example: 01 05 00 00 00 04 but my reception function is unable to receive them!Can you help me ?
Thank you Bernard
Exemple commande recue: 01 05 00 00 00 04 , Chr_cnt affiche 4 au lieu de 6
A = Ischarwaiting()
If A = 1 Then 'Si char présent
A = Udr 'Lire Le Char
Cmd_rcv = Cmd_rcv + Chr(a) 'stocker le char
Incr Chr_cnt ' incrementer le Nbr de char.
Lcd Chr_cnt ?afficher sur un LCD le nbr. de char recu
A = 0
End If[/code]
(BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.8.1 ) |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Fri Mar 01, 2019 5:14 pm Post subject: |
|
|
If the first character is never zero, then you can try INPUTBIN after detection of the first character.
It helps, if you know how many characters there are per transmission.
Regards
Hubert |
|
Back to top |
|
|
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Fri Mar 01, 2019 5:32 pm Post subject: |
|
|
yes, the first and last character is never zero (00) but the length is not fixed (between 4 and 10 char)
in fact I'm trying to communicate with a TFT LCD from 4D Systems!
Thanks for your help ! |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Mar 01, 2019 9:58 pm Post subject: |
|
|
a string may not contain a 0 byte since it is the end of string marker.
but you can also use a byte array to store the data.
or better, use buffered serial input
' 01 05 00 00 00 04
then inside the main loop, check if you have data and process it
Code: | do
if ischarwaiting() =1 then
b=waitkey() ' get the data
if state=0 then ' we did not handled data yet
state=1 ' set state so we know where we are in the process
elseif state=1 then ' we got the header byte
numofbytes=b 'this is the number of bytes that follow which is 5
state=2
elseif state=2 then
' get the actual data
end if
end if
loop |
this is just a partial example of 1 option on how to deal with the data.
another options is to just wait for enough data in the buffer and get it all at once using inputbin _________________ Mark |
|
Back to top |
|
|
Pikczu
Joined: 22 Jan 2006 Posts: 72 Location: Dublin, Ireland
|
Posted: Sat Mar 02, 2019 2:21 pm Post subject: |
|
|
Bellon is this for VISI Genie ?
If so data frame has fixed length 6 bytes.
I have back bone for the library almost ready I can share "As is".
I'm not sure about the magic_object as this requires extra license.
For read object command, the response always starts with 05 as highlighted in green in the table below.
************************Edit*********************************************************
What is done so far:
Read object- this need to be change to function
Write object
Write string - CR and LF need to be added
Write contrast
Report object
Report event
Obviously I need to clean it and optimize.
Code: | '$sim
'****!!! Xmega do not use $baud!!*******
$regfile = "xm128a3udef.dat"
$crystal = 32000000 '32MHz
$hwstack = 128
$swstack = 128
$framesize = 128
$lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
'*******************************************************************************
'*******************************************************************************
$projecttime = 149
$version 0 , 0 , 1143
Dim Firmware As String * 6
Firmware = "1.0A"
Config Submode = New
' ***************** SYSTEM CLOCK CONFIG ****************************************
' INTERNAL 32MHz NO PRESCALE
'
Config Osc = Disabled , 32mhzosc = Enabled , 32khzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
'
' ENABLING AUTOMATIC OSCILLATOR CALIBRATION
Osc_dfllctrl.0 = 1
Dfllrc32m_ctrl.0 = 1
'
'*******************************************************************************
'***************************Dynamic uart ***************************************
'Dim Buart_channel As Byte ' variable for dynamic UART channels
Const Main_bus = 1 'main RS485 bus
Const Debug_port = 2 'Debug port
Const Sensor_bus = 3 'sensors rs485 bus
Const Lcd_4d = 4 'uart port
'*******************************************************************************
'************ CONFIGURATION FOR COM1 UART_C0************************************
' ' TX-PORTC.3 RX-PORTC.2 com 2 tcp
Config Com1 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Open "COM1:" For Binary As #buart_channel 'no need to open any more
Config Serialin1 = Buffered , Size = 128 , Bytematch = None 'for COM1
Config Serialout1 = Buffered , Size = 128
Open "COM1:" For Binary As #1
'Config Input1 = Crlf , Echo = Cr
'Echo On
'
'*******************************************************************************
'*********** CONFIGURATION FOR COM2 UART_C1*************************************
' ' TX-PORTC.7 RX-PORTC.6 (udp com 1 )
Config Com2 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Open "COM2:" For Binary As #buart_channel
'no need to open any more
Config Serialin2 = Buffered , Size = 128 , Bytematch = None 'for COM2
Config Serialout2 = Buffered , Size = 128
Open "COM2:" For Binary As #2
' Config Input2 = Cr , Echo = Cr
'Echo On
'*******************************************************************************
'************ CONFIGURATION FOR COM3 UART_D0************************************
' ' TX-PORTD.3 RX-PORTD.2 wifi
Config Com3 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Open "COM3:" For Binary As #buart_channel 'no need to open any more
Config Serialin3 = Buffered , Size = 128 , Bytematch = None 'for COM1
Config Serialout3 = Buffered , Size = 128
Open "COM3:" For Binary As #3
'Echo On
'
'*******************************************************************************
'************ CONFIGURATION 'COM5 UART_E0 **************************************
' ' TX-PORTE.3 ' RX-PORTE.2 4D Systems LCD
Config Com5 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Open "COM5:" For Binary As #buart_channel 'channel 4
Config Serialin4 = Buffered , Size = 128 , Bytematch = None 'for COM4
Config Serialout4 = Buffered , Size = 128
Open "COM5:" For Binary As #4
'Config Input1 = Crlf , Echo = Cr
' Echo on
'
'*******************************************************************************
'********************** CLOCK CONFIG *******************************************
' we select the internal 1 KHz clock from the 32khz Internal Oscillator
Config Clock = Soft , Rtc = 1khz_int32khz_rcosc
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled ' the RTC uses LO priority
'*******************************************************************************
'********************Config all ports ******************************************
'config pinA.2 = input 'index pin of encoder
Config Pina.1 = Input 'encoder B
Config Pina.0 = Input 'encoder A
'Config Xpin = PinA.2 , Outpull = pullup , Sense = low_level
Config Xpin = Porta.1 , Outpull = Pullup , Sense = Low_level 'enable Pull up and reaction on low level
Config Xpin = Porta.0 , Outpull = Pullup , Sense = Low_level
Config Pine.2 = Input 'index (home_1 sensor)
Config Xpin = Porte.2 , Outpull = Pullup , Sense = Falling
Config Porte.3 = Output 'buzzer
Config Xpin = Porte.3 , Outpull = Totem
'**********************************Event system config**************************
'**********************************encoder for driver_1*************************
Config Event_system = Dummy , Mux0 = Porta.0 , Qd0 = Enabled , Qdi0 = Enabled , Digflt0 = 8
'**********************************encoder for driver_2*************************
Config Tce0 = Normal , Prescale = E0 , Event_source = E0 , Event_action = Qdec
'Config Tcd0 = Normal , Prescale = E0 , Event_source = E0 , Event_action = Qdec
'*******************************************************************************
'************************* Variables *******************************************
'*******************************************************************************
Dim S_pace As Byte
Dim A As Byte
Dim Enkoder_tmp As Word 'for the encoder
Dim Enkoder_tmp_1 As Word 'for the encoder
Dim Enkoder_tmp_2 As Word 'for the encoder
Dim C As Byte
Dim R As Byte
Dim Tablica(6)as Byte
'*******************************************************************************
'********************************used in TX subs********************************
Dim Ack_flag As Byte ' ack byte flag setup each time we expect the ack to come form the display
Dim 4d_arr_tx(6)as Byte '
Dim 4d_helpa As Word At 4d_arr_tx(4) Overlay
Dim 4d_string_tx_arr(39) As Byte
Dim 4d_string_tx As String * 34 At 4d_string_tx_arr(1) + 3 Overlay
'*******************************************************************************
Dim 4d_arr_rx(6) As Byte
Dim 4d_var_rx As Word At 4d_arr_rx(4) Overlay 'overlay for rx
Dim 4d_var_rx_tmp As Word
Dim Obj_index As Byte '4d object index
'Macro
'###############################################################################
Dim Xor_crc As Byte 'xor crc for 4d
Xor_crc = 0
'*******************************************************************************
Dim Dipswitch_idx As Byte '0
Dim Knob_idx As Byte
Dim Rockerswitch_idx As Byte
Dim Rotaryswitch_idx As Byte
Dim Slider_idx As Byte
Dim Trackbar_idx As Byte
Dim Winbutton_idx As Byte
Dim Angularmeter_idx As Byte
Dim Coolgauge_idx As Byte
Dim Customdigits_idx As Byte
Dim Form_idx As Byte 'Used To Set The Current Form
Dim Gauge_idx As Byte '
'Dim Image_idx As Byte ' Displayed As Part Of Form , No Method To Alter
Dim Keyboard_idx As Byte ' KEYBOARD Inputs Are Always Single Bytes And Are Unsolicited
Dim Led_idx As Byte
Dim Leddigits_idx As Byte
Dim Meter_idx As Byte
Dim Strings_idx As Byte
Dim Thermometer_idx As Byte
Dim Userled_idx As Byte
Dim Video_idx As Byte
'Dim Statictext_idx As Byte ' Displayed As Part Of Form , No Method To Alter
Dim S_ound_idx As Byte
Dim T_imer_idx As Byte
Dim Spectrum_idx As Byte
Dim Scope_idx As Byte
Dim Tank_idx As Byte
Dim Userimages_idx As Byte
Dim Pinoutput_idx As Byte
Dim Pininput_idx As Byte
Dim 4dbutton_idx As Byte
Dim Anibutton_idx As Byte
Dim Colorpicker_idx As Byte
Dim Userbutton_idx As Byte
Dim Magicobject_idx As Byte 'ONLY Available When Using Genie Pro
Dim Smartgauge_idx As Byte 'ONLY Available When Using Genie Pro
Dim Smartslider_idx As Byte 'ONLY Available When Using Genie Pro
Dim Smartknob_idx As Byte 'Only Available When Using Genie Pro
'*******************************************************************************
Dim Dipswitch_val(2) As Byte '0
Dim Knob_val(2) As Byte
Dim Rockerswitch_val(2) As Byte
Dim Rotaryswitch_val(2) As Byte
Dim Slider_val(2) As Byte
Dim Trackbar_val(2) As Byte
Dim Winbutton_val(2) As Byte
Dim Angularmeter_val(2) As Byte
Dim Coolgauge_val(2) As Byte
Dim Customdigits_val(2) As Byte
Dim Form_val(2) As Byte 'Used To Set The Current Form
Dim Gauge_val(2) As Byte '
'Dim Image_val(2) As Byte ' Displayed As Part Of Form , No Method To Alter
Dim Keyboard_val(2) As Byte ' KEYBOARD Inputs Are Always Single Bytes And Are Unsolicited
Dim Led_val(2) As Byte
Dim Leddigits_val(2) As Byte
Dim Meter_val(2) As Byte
Dim Strings_val(2) As Byte
Dim Thermometer_val(2) As Byte
Dim Userled_val(2) As Byte
Dim Video_val(2) As Byte
'Dim Statictext_val(2) As Byte ' Displayed As Part Of Form , No Method To Alter
Dim S_ound_val(2) As Byte
Dim T_imer_val(2) As Byte
Dim Spectrum_val(2) As Byte
Dim Scope_val(2) As Byte
Dim Tank_val(2) As Byte
Dim Userimages_val(2) As Byte
Dim Pinoutput_val As Byte
Dim Pininput_val As Byte
Dim 4dbutton_val(2) As Byte
Dim Anibutton_val(2) As Byte
Dim Colorpicker_val(2) As Byte
Dim Userbutton_val(2) As Byte
Dim Magicobject_val(2) As Byte 'ONLY Available When Using Genie Pro
Dim Smartgauge_val(2) As Byte 'ONLY Available When Using Genie Pro
Dim Smartslider_val(2) As Byte 'ONLY Available When Using Genie Pro
Dim Smartknob_val(2) As Byte 'Only Available When Using Genie Pro
'*******************************************************************************
Const A_ck = &H06
Const Nak = &H15
'Const 4d_uart = 4 'uart port
Const 4d_max_len = 32 'maximum 4D string length
'*******************************************************************************
Const Dipswitch = &H00 '0
Const Knob = &H01
Const Rockerswitch = &H02
Const Rotaryswitch = &H03
Const Slider = &H04
Const Trackbar = &H05
Const Winbutton = &H06
Const Angularmeter = &H07
Const Coolgauge = &H08
Const Customdigits = &H09
Const Form = &H0A 'Used To Set The Current Form
Const Gauge = &H0B '
Const Image = &H0C ' Displayed As Part Of Form , No Method To Alter
Const Keyboard = &H0D ' KEYBOARD Inputs Are Always Single Bytes And Are Unsolicited
Const Led = &H0E
Const Leddigits = &H0F
Const Meter = &H10
Const Strings = &H11
Const Thermometer = &H12
Const Userled = &H13
Const Video = &H14
Const Statictext = &H15 ' Displayed As Part Of Form , No Method To Alter
Const S_ound = &H16
Const T_imer = &H17
Const Spectrum = &H18
Const Scope = &H19
Const Tank = &H1A
Const Userimages = &H1B
Const Pinoutput = &H1C
Const Pininput = &H1D
Const 4dbutton = &H1E
Const Anibutton = &H1F
Const Colorpicker = &H20
Const Userbutton = &H21
Const Magicobject = &H22 'ONLY Available When Using Genie Pro
Const Smartgauge = &H23 'ONLY Available When Using Genie Pro
Const Smartslider = &H24 'ONLY Available When Using Genie Pro
Const Smartknob = &H25 'Only Available When Using Genie Pro
'*******************************************************************************
Const Read_obj = &H00
Const Write_obj = &H01
Const Write_str = &H02
Const Write_stru = &H03
Const Write_contrast = &H04
'*******************************************************************************
'*******************************************************************************
Const Report_obj = &H05 'response to read obj command
Const Report_event = &H07 'response to evnt no no request needed
Const Write_magic_bytes = &H08
Const Write_magic_dbytes = &H09
Const Report_magic_event_bytes = &H0A
'*******************************************************************************
'*******************************************************************************
'******************************************************************************
Function Xor_this(ar()as Byte ) As Byte ' Function XOR
Local Xor_ing As Byte 'temporary variable for xor value so could be a local
Xor_ing = Ar(1) Xor Ar(2) 'xoring
Xor_ing = Xor_ing Xor Ar(3)
Xor_ing = Xor_ing Xor Ar(4)
Xor_ing = Xor_ing Xor Ar(5)
'Xor_ing = Xor_ing Xor Ar(6)
Xor_this = Xor_ing 'final result assignment
End Function
'******************************************************************************
'this shoul be a function not a sub
Sub 4d_read_obj(byval 4d_object_id As Byte , Byval 4d_object_index As Byte )
'this should be a fuction
4d_arr_tx(1) = Write_obj '&h00 constant
4d_arr_tx(2) = 4d_object_id 'object ID as per constants
4d_arr_tx(3) = 4d_object_index 'object index
Xor_crc = 4d_arr_tx(1) Xor 4d_arr_tx(2) 'calculate the xor check sum
Xor_crc = Xor_crc Xor 4d_arr_tx(3)
4d_arr_tx(4) = Xor_crc
Printbin #4 , 4d_arr_tx(1) ; 4 'print binary the final result
Ack_flag.1 = 1 'for feature use
'The response from the display should be Report_obj: &h05
End Sub
'******************************************************************************
Sub 4d_write_obj(byval 4d_object_id As Byte , Byval 4d_object_index As Byte , Byval 4d_obj_value As Word )
'Dim 4d_helpa As Word At 4d_arr_tx(4) Overlay 'copy for clarity
Swap 4d_obj_value 'little endian to big endian
4d_helpa = 4d_obj_value 'assign to overlaid variable
4d_arr_tx(1) = Write_obj '&h01 constant
4d_arr_tx(2) = 4d_object_id 'object ID as per constants
4d_arr_tx(3) = 4d_object_index 'object index
'4d_arr_tx(4) as this is overlay teh values are all ready there in global array
'4d_arr_tx(5) as this is overlay teh values are all ready there in global array
Xor_crc = 4d_arr_tx(1) Xor 4d_arr_tx(2) 'calculate the xor check sum
Xor_crc = Xor_crc Xor 4d_arr_tx(3)
Xor_crc = Xor_crc Xor 4d_arr_tx(4)
4d_arr_tx(6) = Xor_crc Xor 4d_arr_tx(5)
Printbin #lcd_4d , 4d_arr_tx(1) ; 6 'print binary the final result
Ack_flag.0 = 1 'for feature use
'The response from the display should be ACK message &h06
End Sub
Sub 4d_write_str(byval 4d_str_indx As Byte , Byval 4d_string_1 As String , Byval Cr_lf As Byte )
'the body of the command is:
'code + string_index+ string_lenght + string + xorcrc
Local Index_help_a As Byte 'used to calculate the lengt of the string
Local Index_help_b As Byte 'used to calculate position of the XOR CRC in array, string lenght+3
Dim Tot_command_len As Byte 'total comand lenght
'******************************************************************************
'If Cr >= 1 Then Cr = 1
'If Lf >= 1 Then Lf = 1
'******************************************************************************
'******************************************************************************
Select Case Cr_lf
Case 0:
'Tot_command_len = Len(4d_string_1) + 4 'string lenght(+) commad (+) string index (+) string
Tot_command_len = Len(4d_string_1) 'string lenght(+) commad (+) string index (+) string
Case 1:
Tot_command_len = Len(4d_string_1) + 5 'string lenght(+) commad (+) string index (+) string
' Insertchar 4d_string_tx , Tot_command_len
Case 2:
Tot_command_len = Len(4d_string_1) '+ 6 'string lenght(+) commad (+) string index (+) string
End Select
4d_string_tx = 4d_string_1 'copy the string in to variable overlayd at array
4d_string_tx_arr(1) = Write_str '&h02 write string command
4d_string_tx_arr(2) = 4d_str_indx 'index of the string
4d_string_tx_arr(3) = Len(4d_string_1) 'lenght of the string
For Index_help_a = 1 To Tot_command_len -1 'we need to xor this and asign at the end
'the minus (-)1 skip xor of the null termination
4d_string_tx_arr(tot_command_len) = 4d_string_tx_arr(tot_command_len) Xor 4d_string_tx_arr(index_help_a)
Next Index_help_a
Select Case Tot_command_len ' total comand lenght
Case 5:
Printbin #1 , 4d_string_tx_arr(1) ; 5 'code +string index+ string lenght + 1 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 5 'code +string index+ string lenght + 1 char + crc
Case 6:
Printbin #1 , 4d_string_tx_arr(1) ; 6 'code +string index+ string lenght + 2 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 6 'code +string index+ string lenght + 2 char + crc
Case 7:
Printbin #1 , 4d_string_tx_arr(1) ; 7 'code +string index+ string lenght + 3 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 7 'code +string index+ string lenght + 3 char + crc
Case 8:
Printbin #1 , 4d_string_tx_arr(1) ; 8 'code +string index+ string lenght + 4 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 8 'code +string index+ string lenght + 4 char + crc
Case 9:
Printbin #1 , 4d_string_tx_arr(1) ; 9 'code +string index+ string lenght + 5 char + crc
Printbin #4 , 4d_string_tx_arr(1) , 9 'code +string index+ string lenght + 5 char + crc
Case 10:
Printbin #1 , 4d_string_tx_arr(1) ; 10 'code +string index+ string lenght + 6 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 10 'code +string index+ string lenght + 6 char + crc
Case 11:
Printbin #1 , 4d_string_tx_arr(1) ; 11 'code +string index+ string lenght + 7 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 11 'code +string index+ string lenght + 7 char + crc
Case 12:
Printbin #1 , 4d_string_tx_arr(1) ; 12 'code +string index+ string lenght + 8 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 12 'code +string index+ string lenght + 8 char + crc
Case 13:
Printbin #1 , 4d_string_tx_arr(1) ; 13 'code +string index+ string lenght + 9 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 13 'code +string index+ string lenght + 9 char + crc
Case 14:
Printbin #1 , 4d_string_tx_arr(1) ; 14 'code +string index+ string lenght + 10 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 14 'code +string index+ string lenght + 10 char + crc
Case 15:
Printbin #1 , 4d_string_tx_arr(1) ; 15 'code +string index+ string lenght + 11 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 15 'code +string index+ string lenght + 11 char + crc
Case 16:
Printbin #1 , 4d_string_tx_arr(1) ; 16 'code +string index+ string lenght + 12 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 16 'code +string index+ string lenght + 12 char + crc
Case 17:
Printbin #1 , 4d_string_tx_arr(1) ; 17 'code +string index+ string lenght + 13 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 17 'code +string index+ string lenght + 13 char + crc
Case 18:
Printbin #1 , 4d_string_tx_arr(1) ; 18 'code +string index+ string lenght + 14 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 18 'code +string index+ string lenght + 14 char + crc
Case 19:
Printbin #1 , 4d_string_tx_arr(1) ; 19 'code +string index+ string lenght + 15 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 19 'code +string index+ string lenght + 15 char + crc
Case 20:
Printbin #1 , 4d_string_tx_arr(1) ; 20 'code +string index+ string lenght + 16 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 20 'code +string index+ string lenght + 16 char + crc
Case 21:
Printbin #1 , 4d_string_tx_arr(1) ; 21 'code +string index+ string lenght + 17 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 21 'code +string index+ string lenght + 17 char + crc
Case 22:
Printbin #1 , 4d_string_tx_arr(1) ; 22 'code +string index+ string lenght + 18 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 22 'code +string index+ string lenght + 18 char + crc
Case 23:
Printbin #1 , 4d_string_tx_arr(1) ; 23 'code +string index+ string lenght + 19 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 23 'code +string index+ string lenght + 19 char + crc
Case 24:
Printbin #1 , 4d_string_tx_arr(1) ; 24 'code +string index+ string lenght + 20 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 24 'code +string index+ string lenght + 20 char + crc
Case 25:
Printbin #1 , 4d_string_tx_arr(1) ; 25 'code +string index+ string lenght + 21 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 25 'code +string index+ string lenght + 21 char + crc
Case 26:
Printbin #1 , 4d_string_tx_arr(1) ; 26 'code +string index+ string lenght + 22 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 26 'code +string index+ string lenght + 22 char + crc
Case 27:
Printbin #1 , 4d_string_tx_arr(1) ; 27 'code +string index+ string lenght + 23 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 27 'code +string index+ string lenght + 23 char + crc
Case 28:
Printbin #1 , 4d_string_tx_arr(1) ; 28 'code +string index+ string lenght + 24 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 28 'code +string index+ string lenght + 24 char + crc
Case 29:
Printbin #1 , 4d_string_tx_arr(1) ; 29 'code +string index+ string lenght + 25 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 29 'code +string index+ string lenght + 25 char + crc
Case 30:
Printbin #1 , 4d_string_tx_arr(1) ; 30 'code +string index+ string lenght + 26 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 30 'code +string index+ string lenght + 26 char + crc
Case 31:
Printbin #1 , 4d_string_tx_arr(1) ; 31 'code +string index+ string lenght + 27 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 31 'code +string index+ string lenght + 27 char + crc
Case 32:
Printbin #1 , 4d_string_tx_arr(1) ; 32 'code +string index+ string lenght + 28 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 32 'code +string index+ string lenght + 28 char + crc
Case 33:
Printbin #1 , 4d_string_tx_arr(1) ; 33 'code +string index+ string lenght + 29 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 33 'code +string index+ string lenght + 29 char + crc
Case 34:
Printbin #1 , 4d_string_tx_arr(1) ; 34 'code +string index+ string lenght + 30 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 34 'code +string index+ string lenght + 30 char + crc
Case 35:
Printbin #1 , 4d_string_tx_arr(1) ; 35 'code +string index+ string lenght + 31 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 35 'code +string index+ string lenght + 31 char + crc
Case 36:
Printbin #1 , 4d_string_tx_arr(1) ; 36 'code +string index+ string lenght + 32 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 36 'code +string index+ string lenght + 32 char + crc
End Select
End Sub
'******************************************************************************
Sub 4d_write_contrast(byval 4d_contrast_val As Byte)
If 4d_contrast_val => 10 Then
4d_contrast_val = 10
End If
Dim 4d_contrast_tx(3) As Byte
4d_contrast_tx(1) = Write_contrast
4d_contrast_tx(2) = 4d_contrast_val
4d_contrast_tx(3) = Write_contrast Xor 4d_contrast_val
Printbin #4 , 4d_contrast_tx(1) ; 3
End Sub
'*******************************************************************************
'###############################################################################
'************************* Main loop *******************************************
Enkoder_tmp = 0
Ack_flag = 0
Enable Interrupts
Tablica(1) = Write_obj
Tablica(2) = Leddigits
Tablica(3) = Obj_index
Tablica(4) = Tablica(4)
Tablica(5) = 0
Print #1 , "MCU Rev. = " ; Mcu_revid 'version of the MCU
'Call 4d_write_contrast(&H07)
Call 4d_write_str(0 , "Hi there" , 0 )
Do
'Call 4d_read_obj(leddigits , &H01 )
'drukuj na wifi
If Tce0_cnt <> Enkoder_tmp Then 'jesli zawartosc timera TCD0 jest różna od naszej zmiennej to
Enkoder_tmp = Tce0_cnt 'przepisz nową wartość z timera TCD0 do zmiennej enkoder_tmp
Enkoder_tmp_1 = Tce0_cnt / 4 ' four inpulses per one step of teh encoder so wee need only one
If Enkoder_tmp_1 <> Enkoder_tmp_2 Then
Enkoder_tmp_2 = Enkoder_tmp_1
Print #1 , Enkoder_tmp_2 'wyśli przez port szeregowy 2 (zmienna buart=2)
Call 4d_write_obj(leddigits , &H01 , Enkoder_tmp_2)
Call 4d_write_contrast(enkoder_tmp_2)
End If
End If
Waitms 500
Incr Tablica(5)
Tablica(6) = Xor_this(tablica(1))
'Printbin #4 , Tablica(1) ; 6
'Printbin #4 , Write_obj ; Leddigits ; &H00 ; &H00 ; Tablica(5) ; Xor_crc ;
If Ischarwaiting(#4) = 1 Then
Inputbin #4 , 4d_arr_rx(1) , 1
Print #1 , "received= " ; 4d_arr_rx(1)
Select Case 4d_arr_rx(1) 'command
Case Report_obj: '&H05
'If Ack_flag.1 = 1 Then 'for feature use
'Ack_flag.1 = 0
'Else
'Print #1 , " Error there was no &H05 request !"
'End If
Inputbin #4 , 4d_arr_rx(2) , 5 'get next 5
Xor_crc = Xor_this(4d_arr_rx(1)) ' check the crc
If 4d_arr_rx(6) = Xor_crc Then 'if crc ok then check what came
Select Case 4d_arr_rx(2) 'object ID
Case Dipswitch: '0
Dipswitch_idx = 4d_arr_rx(3)
Dipswitch_val(1) = 4d_arr_rx(4)
Dipswitch_val(2) = 4d_arr_rx(5)
Print #1 , "Dipswitch "
Case Knob: '1
Knob_idx = 4d_arr_rx(3)
Knob_val(1) = 4d_arr_rx(4)
Knob_val(2) = 4d_arr_rx(5)
Print #1 , "Knob "
Case Rockerswitch: '2
Rockerswitch_idx = 4d_arr_rx(3)
Rockerswitch_val(1) = 4d_arr_rx(4)
Rockerswitch_val(2) = 4d_arr_rx(5)
Print #1 , "Rockerswitch "
Case Rotaryswitch: '3
Rotaryswitch_idx = 4d_arr_rx(3)
Rotaryswitch_val(1) = 4d_arr_rx(4)
Rotaryswitch_val(2) = 4d_arr_rx(5)
Print #1 , "Rotaryswitch "
Case Slider: '4
Slider_idx = 4d_arr_rx(3)
Slider_val(1) = 4d_arr_rx(4)
Slider_val(2) = 4d_arr_rx(5)
Print #1 , "Slider "
Case Trackbar: '5
Trackbar_idx = 4d_arr_rx(3)
Trackbar_val(1) = 4d_arr_rx(4)
Trackbar_val(2) = 4d_arr_rx(5)
Print #1 , "Trackbar "
Case Winbutton: '6
Winbutton_idx = 4d_arr_rx(3)
Winbutton_val(1) = 4d_arr_rx(4)
Winbutton_val(2) = 4d_arr_rx(5)
Print #1 , "Winbutton "
Case Angularmeter: '7
Angularmeter_idx = 4d_arr_rx(3)
Angularmeter_val(1) = 4d_arr_rx(4)
Angularmeter_val(2) = 4d_arr_rx(5)
Print #1 , "Angularmeter "
Case Coolgauge: '8
Coolgauge_idx = 4d_arr_rx(3)
Coolgauge_val(1) = 4d_arr_rx(4)
Coolgauge_val(2) = 4d_arr_rx(5)
Print #1 , "Coolgauge "
Case Customdigits: '9
Customdigits_idx = 4d_arr_rx(3)
Customdigits_val(1) = 4d_arr_rx(4)
Customdigits_val(2) = 4d_arr_rx(5)
Print #1 , "Customdigits "
Case Form: '10
Form_idx = 4d_arr_rx(3)
Form_val(1) = 4d_arr_rx(4)
Form_val(2) = 4d_arr_rx(5)
Print #1 , "Form "
Case Gauge: '11
Gauge_idx = 4d_arr_rx(3)
Gauge_val(1) = 4d_arr_rx(4)
Gauge_val(2) = 4d_arr_rx(5)
Print #1 , "Gauge "
Case Image: '12
'Image_idx = 4d_arr_rx(3)
'Image_val(1) = 4d_arr_rx(4)
'Image_val(2) = 4d_arr_rx(5)
Print #1 , "Image "
Case Keyboard: '13
Keyboard_idx = 4d_arr_rx(3)
Keyboard_val(1) = 4d_arr_rx(4)
Keyboard_val(2) = 4d_arr_rx(5)
Print #1 , "Keyboard "
Case Led: '14
Led_idx = 4d_arr_rx(3)
Led_val(1) = 4d_arr_rx(4)
Led_val(2) = 4d_arr_rx(5)
Print #1 , "Led "
Case Leddigits: '15
Leddigits_idx = 4d_arr_rx(3)
Leddigits_val(1) = 4d_arr_rx(4)
Leddigits_val(2) = 4d_arr_rx(5)
Print #1 , "Leddigits "
Case Meter: '16
Meter_idx = 4d_arr_rx(3)
Meter_val(1) = 4d_arr_rx(4)
Meter_val(2) = 4d_arr_rx(5)
Print #1 , "Meter "
Case Strings: '17
Strings_idx = 4d_arr_rx(3)
Strings_val(1) = 4d_arr_rx(4)
Strings_val(2) = 4d_arr_rx(5)
Print #1 , "Strings "
Case Thermometer: '18
Thermometer_idx = 4d_arr_rx(3)
Thermometer_val(1) = 4d_arr_rx(4)
Thermometer_val(2) = 4d_arr_rx(5)
Print #1 , "Thermometer "
Case Userled: '19
Userled_idx = 4d_arr_rx(3)
Userled_val(1) = 4d_arr_rx(4)
Userled_val(2) = 4d_arr_rx(5)
Print #1 , "Userled "
Case Video: '20
Video_idx = 4d_arr_rx(3)
Video_val(1) = 4d_arr_rx(4)
Video_val(2) = 4d_arr_rx(5)
Debug "Video "
Case Statictext: '21
'Statictext_idx = 4d_arr_rx(3)
'Statictext_val(1) = 4d_arr_rx(4)
'Statictext_val(2) = 4d_arr_rx(5)
Print #1 , "Statictext "
Case S_ound: '22
S_ound_idx = 4d_arr_rx(3)
S_ound_val(1) = 4d_arr_rx(4)
S_ound_val(2) = 4d_arr_rx(5)
Print #1 , "S_ound "
Case T_imer: '23
T_imer_idx = 4d_arr_rx(3)
T_imer_val(1) = 4d_arr_rx(4)
T_imer_val(2) = 4d_arr_rx(5)
Print #1 , "T_imer "
Case Spectrum: '24
Spectrum_idx = 4d_arr_rx(3)
Spectrum_val(1) = 4d_arr_rx(4)
Spectrum_val(2) = 4d_arr_rx(5)
Print #1 , "Spectrum "
Case Scope: '25
Scope_idx = 4d_arr_rx(3)
Scope_val(1) = 4d_arr_rx(4)
Scope_val(2) = 4d_arr_rx(5)
Print #1 , "Scope "
Case Tank: '26
Tank_idx = 4d_arr_rx(3)
Tank_val(1) = 4d_arr_rx(4)
Tank_val(2) = 4d_arr_rx(5)
Print #1 , "Tank "
Case Userimages: '27
Userimages_idx = 4d_arr_rx(3)
Userimages_val(1) = 4d_arr_rx(4)
Userimages_val(2) = 4d_arr_rx(5)
Print #1 , "Userimages "
Case Pinoutput: '28
Pinoutput_idx = 4d_arr_rx(3)
'Pinoutput_val(1) = 4d_arr_rx(4)
Pinoutput_val = 4d_arr_rx(5)
Print #1 , "Pinoutput "
Case Pininput: '29
Pininput_idx = 4d_arr_rx(3)
'Pininput_val(1) = 4d_arr_rx(4)
Pininput_val = 4d_arr_rx(5)
Print #1 , "Pininput "
Case 4dbutton: '30
4dbutton_idx = 4d_arr_rx(3)
4dbutton_val(1) = 4d_arr_rx(4)
4dbutton_val(2) = 4d_arr_rx(5)
Print #1 , "4dbutton "
Case Anibutton: '31
Anibutton_idx = 4d_arr_rx(3)
Anibutton_val(1) = 4d_arr_rx(4)
Anibutton_val(2) = 4d_arr_rx(5)
Print #1 , "Anibutton "
Case Colorpicker: '32
Colorpicker_idx = 4d_arr_rx(3)
Colorpicker_val(1) = 4d_arr_rx(4)
Colorpicker_val(2) = 4d_arr_rx(5)
Print #1 , "Colorpicker "
Case Userbutton: '33
Userbutton_idx = 4d_arr_rx(3)
Userbutton_val(1) = 4d_arr_rx(4)
Userbutton_val(2) = 4d_arr_rx(5)
Print #1 , "Userbutton "
Case Magicobject: '34
Magicobject_idx = 4d_arr_rx(3)
Magicobject_val(1) = 4d_arr_rx(4)
Magicobject_val(2) = 4d_arr_rx(5)
Print #1 , "Magicobject "
Case Smartgauge: '35
Smartgauge_idx = 4d_arr_rx(3)
Smartgauge_val(1) = 4d_arr_rx(4)
Smartgauge_val(2) = 4d_arr_rx(5)
Print #1 , "Smartgauge "
Case Smartslider: '36
Smartslider_idx = 4d_arr_rx(3)
Smartslider_val(1) = 4d_arr_rx(4)
Smartslider_val(2) = 4d_arr_rx(5)
Print #1 , "Smartslider "
Case Smartknob: '37
Smartknob_idx = 4d_arr_rx(3)
Smartknob_val(1) = 4d_arr_rx(4)
Smartknob_val(2) = 4d_arr_rx(5)
Print #1 , "Smartknob "
Case Else:
Print #1 , "Event report wrong ID: " ; 4d_arr_rx(3)
'Clear Serialin4
Print #1 , "S_pace" ; S_pace
Print #1 , "frame error"
End Select
End If
Case A_ck: '&H06 ACK
Print #1 , "ACK"
Ack_flag.0 = 0 'reset ack flag not really in use yet
Case Report_event: '&H07
Inputbin #4 , 4d_arr_rx(2) , 5 'get next 5
Xor_crc = Xor_this(4d_arr_rx(1)) ' check the crc
If 4d_arr_rx(6) = Xor_crc Then 'if crc ok then check what came
Select Case 4d_arr_rx(2) 'object ID
Case Dipswitch: '0
Dipswitch_idx = 4d_arr_rx(3)
Dipswitch_val(1) = 4d_arr_rx(4)
Dipswitch_val(2) = 4d_arr_rx(5)
Print #1 , "Dipswitch "
Case Knob: '1
Knob_idx = 4d_arr_rx(3)
Knob_val(1) = 4d_arr_rx(4)
Knob_val(2) = 4d_arr_rx(5)
Print #1 , "Knob "
Case Rockerswitch: '2
Rockerswitch_idx = 4d_arr_rx(3)
Rockerswitch_val(1) = 4d_arr_rx(4)
Rockerswitch_val(2) = 4d_arr_rx(5)
Print #1 , "Rockerswitch "
Case Rotaryswitch: '3
Rotaryswitch_idx = 4d_arr_rx(3)
Rotaryswitch_val(1) = 4d_arr_rx(4)
Rotaryswitch_val(2) = 4d_arr_rx(5)
Print #1 , "Rotaryswitch "
Case Slider: '4
Slider_idx = 4d_arr_rx(3)
Slider_val(1) = 4d_arr_rx(4)
Slider_val(2) = 4d_arr_rx(5)
Print #1 , "Slider "
Case Trackbar: '5
Trackbar_idx = 4d_arr_rx(3)
Trackbar_val(1) = 4d_arr_rx(4)
Trackbar_val(2) = 4d_arr_rx(5)
Print #1 , "Trackbar "
Case Winbutton: '6
Winbutton_idx = 4d_arr_rx(3)
Winbutton_val(1) = 4d_arr_rx(4)
Winbutton_val(2) = 4d_arr_rx(5)
Print #1 , "Winbutton "
Case Angularmeter: '7
Angularmeter_idx = 4d_arr_rx(3)
Angularmeter_val(1) = 4d_arr_rx(4)
Angularmeter_val(2) = 4d_arr_rx(5)
Print #1 , "Angularmeter "
Case Coolgauge: '8
Coolgauge_idx = 4d_arr_rx(3)
Coolgauge_val(1) = 4d_arr_rx(4)
Coolgauge_val(2) = 4d_arr_rx(5)
Print #1 , "Coolgauge "
Case Customdigits: '9
Customdigits_idx = 4d_arr_rx(3)
Customdigits_val(1) = 4d_arr_rx(4)
Customdigits_val(2) = 4d_arr_rx(5)
Print #1 , "Customdigits "
Case Form: '10
Form_idx = 4d_arr_rx(3)
Form_val(1) = 4d_arr_rx(4)
Form_val(2) = 4d_arr_rx(5)
Print #1 , "Form "
Case Gauge: '11
Gauge_idx = 4d_arr_rx(3)
Gauge_val(1) = 4d_arr_rx(4)
Gauge_val(2) = 4d_arr_rx(5)
Print #1 , "Gauge "
Case Image: '12
'Image_idx = 4d_arr_rx(3)
'Image_val(1) = 4d_arr_rx(4)
'Image_val(2) = 4d_arr_rx(5)
Print #1 , "Image "
Case Keyboard: '13
Keyboard_idx = 4d_arr_rx(3)
Keyboard_val(1) = 4d_arr_rx(4)
Keyboard_val(2) = 4d_arr_rx(5)
Print #1 , "Keyboard "
Case Led: '14
Led_idx = 4d_arr_rx(3)
Led_val(1) = 4d_arr_rx(4)
Led_val(2) = 4d_arr_rx(5)
Print #1 , "Led "
Case Leddigits: '15
Leddigits_idx = 4d_arr_rx(3)
Leddigits_val(1) = 4d_arr_rx(4)
Leddigits_val(2) = 4d_arr_rx(5)
Print #1 , "Leddigits "
Case Meter: '16
Meter_idx = 4d_arr_rx(3)
Meter_val(1) = 4d_arr_rx(4)
Meter_val(2) = 4d_arr_rx(5)
Print #1 , "Meter "
Case Strings: '17
Strings_idx = 4d_arr_rx(3)
Strings_val(1) = 4d_arr_rx(4)
Strings_val(2) = 4d_arr_rx(5)
Print #1 , "Strings "
Case Thermometer: '18
Thermometer_idx = 4d_arr_rx(3)
Thermometer_val(1) = 4d_arr_rx(4)
Thermometer_val(2) = 4d_arr_rx(5)
Print #1 , "Thermometer "
Case Userled: '19
Userled_idx = 4d_arr_rx(3)
Userled_val(1) = 4d_arr_rx(4)
Userled_val(2) = 4d_arr_rx(5)
Print #1 , "Userled "
Case Video: '20
Video_idx = 4d_arr_rx(3)
Video_val(1) = 4d_arr_rx(4)
Video_val(2) = 4d_arr_rx(5)
Debug "Video "
Case Statictext: '21
'Statictext_idx = 4d_arr_rx(3)
'Statictext_val(1) = 4d_arr_rx(4)
'Statictext_val(2) = 4d_arr_rx(5)
Print #1 , "Statictext "
Case S_ound: '22
S_ound_idx = 4d_arr_rx(3)
S_ound_val(1) = 4d_arr_rx(4)
S_ound_val(2) = 4d_arr_rx(5)
Print #1 , "S_ound "
Case T_imer: '23
T_imer_idx = 4d_arr_rx(3)
T_imer_val(1) = 4d_arr_rx(4)
T_imer_val(2) = 4d_arr_rx(5)
Print #1 , "T_imer "
Case Spectrum: '24
Spectrum_idx = 4d_arr_rx(3)
Spectrum_val(1) = 4d_arr_rx(4)
Spectrum_val(2) = 4d_arr_rx(5)
Print #1 , "Spectrum "
Case Scope: '25
Scope_idx = 4d_arr_rx(3)
Scope_val(1) = 4d_arr_rx(4)
Scope_val(2) = 4d_arr_rx(5)
Print #1 , "Scope "
Case Tank: '26
Tank_idx = 4d_arr_rx(3)
Tank_val(1) = 4d_arr_rx(4)
Tank_val(2) = 4d_arr_rx(5)
Print #1 , "Tank "
Case Userimages: '27
Userimages_idx = 4d_arr_rx(3)
Userimages_val(1) = 4d_arr_rx(4)
Userimages_val(2) = 4d_arr_rx(5)
Print #1 , "Userimages "
Case Pinoutput: '28
Pinoutput_idx = 4d_arr_rx(3)
'Pinoutput_val(1) = 4d_arr_rx(4)
Pinoutput_val = 4d_arr_rx(5)
Print #1 , "Pinoutput "
Case Pininput: '29
Pininput_idx = 4d_arr_rx(3)
'Pininput_val(1) = 4d_arr_rx(4)
Pininput_val = 4d_arr_rx(5)
Print #1 , "Pininput "
Case 4dbutton: '30
4dbutton_idx = 4d_arr_rx(3)
4dbutton_val(1) = 4d_arr_rx(4)
4dbutton_val(2) = 4d_arr_rx(5)
Print #1 , "4dbutton "
Case Anibutton: '31
Anibutton_idx = 4d_arr_rx(3)
Anibutton_val(1) = 4d_arr_rx(4)
Anibutton_val(2) = 4d_arr_rx(5)
Print #1 , "Anibutton "
Case Colorpicker: '32
Colorpicker_idx = 4d_arr_rx(3)
Colorpicker_val(1) = 4d_arr_rx(4)
Colorpicker_val(2) = 4d_arr_rx(5)
Print #1 , "Colorpicker "
Case Userbutton: '33
Userbutton_idx = 4d_arr_rx(3)
Userbutton_val(1) = 4d_arr_rx(4)
Userbutton_val(2) = 4d_arr_rx(5)
Print #1 , "Userbutton "
Case Magicobject: '34
Magicobject_idx = 4d_arr_rx(3)
Magicobject_val(1) = 4d_arr_rx(4)
Magicobject_val(2) = 4d_arr_rx(5)
Print #1 , "Magicobject "
Case Smartgauge: '35
Smartgauge_idx = 4d_arr_rx(3)
Smartgauge_val(1) = 4d_arr_rx(4)
Smartgauge_val(2) = 4d_arr_rx(5)
Print #1 , "Smartgauge "
Case Smartslider: '36
Smartslider_idx = 4d_arr_rx(3)
Smartslider_val(1) = 4d_arr_rx(4)
Smartslider_val(2) = 4d_arr_rx(5)
Print #1 , "Smartslider "
Case Smartknob: '37
Smartknob_idx = 4d_arr_rx(3)
Smartknob_val(1) = 4d_arr_rx(4)
Smartknob_val(2) = 4d_arr_rx(5)
Print #1 , "Smartknob "
Case Else:
Print #1 , "Event report wrong ID: " ; 4d_arr_rx(3)
Clear Serialin4
Print #1 , "S_pace" ; S_pace
Print #1 , "frame error"
End Select
End If
Case Nak:
Print #1 , "NACK" '&h15 NAK
Case Else:
Print #1 , "Error in Code =: " ; 4d_arr_rx(1)
Clear Serialin4
Print #1 , "S_pace= " ; S_pace
Print #1 , "frame error"
End Select
End If
Loop
End |
Last edited by Pikczu on Sun Mar 03, 2019 12:34 pm; edited 1 time in total |
|
Back to top |
|
|
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Sat Mar 02, 2019 4:56 pm Post subject: Recept nul char / Bascom |
|
|
Hello Pikczu
yes it is for a screen visi genie. I just discovered it and I'd like to test it to display on a manometer
the distance measured with an ultrasonic sensor. While simulating manometer with Genie Test Executor I found that my serial reception routine was unable to read null characters (00). This was the subject of my basic question. I think I found the answer in your source code (you use com4 for the lcd I think) me I use an Atmega 2560, the libraries are they necessary?
In any case, I thank you for sharing your knowledge and I will take inspiration from your example.
Cordial greetings. Bernard |
|
Back to top |
|
|
Pikczu
Joined: 22 Jan 2006 Posts: 72 Location: Dublin, Ireland
|
Posted: Sat Mar 02, 2019 5:17 pm Post subject: |
|
|
Yes I have used com 4 on xmega 128A3u and com 1 used for the debug.
As you can see code is not fully finished.
I still have to add:
Write_ STRU
Write_magic_byte
Write_magic_Dbytes
Report_magic_events_Bytes
Report_magic_events_Dbytes
I will create user friendly library and a I will post it on the 4D forum and here in MCS forum.
String has limit of 32 characters this is only because i did not found neat way of sending array with variable length.
So currently there is 36 cases of select case "Tot_command_len" for each number of characters.
Any way feel free to use it, also I'm open for any suggestions.
Regards
Pikczu
Last edited by Pikczu on Sun Apr 28, 2019 4:15 pm; edited 1 time in total |
|
Back to top |
|
|
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Mon Mar 04, 2019 3:34 pm Post subject: Recept nul char / Bascom |
|
|
Hello Pikczu
I more or less understood the operation of your program that I adapted for a mega 2560 processor. I can not test it for the moment because I have not received the TFT lcd yet. as I explained before, my project and display on the lcd (in an object (Coolgauge0)
the distance measured with an ultrasonic sensor. the result of this measurement is in a (word). my question is, what is the function in your program that allows to send the data to Ldc for example:
01 (object_id) (object_index) (my word) checksum?
I specify that the distance measurement routine is integrated into the program (it does not come from rs232)
If I'm abusing your time, you have to tell me!)
Sincerely Bernard |
|
Back to top |
|
|
Pikczu
Joined: 22 Jan 2006 Posts: 72 Location: Dublin, Ireland
|
Posted: Mon Mar 04, 2019 7:59 pm Post subject: |
|
|
Hi Bernard,
It is pretty simple, if you want to update some objects on the screen you need to use:
Call 4d_write_obj(object ID, object index , value )
I have created constants for object ID for easy use (table attached for clarity)
For example you would like to change value of Coolgauge index 0 to lets say value = 50
XOR crc are calculated in the sub.
Command will look like that:
Call 4d_write_obj(Coolgauge , &H00 , &h32)
Then this sub is called:
Code: | Sub 4d_write_obj(byval 4d_object_id As Byte , Byval 4d_object_index As Byte , Byval 4d_obj_value As Word )
'Dim 4d_helpa As Word At 4d_arr_tx(4) Overlay 'copy for clarity
Swap 4d_obj_value 'litle endian to big endian
4d_helpa = 4d_obj_value 'assign to overlaid variable
4d_arr_tx(1) = Write_obj '&h01 constant
4d_arr_tx(2) = 4d_object_id 'object ID as per constants
4d_arr_tx(3) = 4d_object_index 'object index
'4d_arr_tx(4) for clarity this is overlay, the values are all ready there in global array
'4d_arr_tx(5) for clarity this is overlay, the values are all ready there in global array
Xor_crc = 4d_arr_tx(1) Xor 4d_arr_tx(2) 'calculate the xor check sum
Xor_crc = Xor_crc Xor 4d_arr_tx(3)
Xor_crc = Xor_crc Xor 4d_arr_tx(4)
4d_arr_tx(6) = Xor_crc Xor 4d_arr_tx(5)
Printbin #lcd_4d , 4d_arr_tx(1) ; 6 'print binary the final result
Ack_flag.0 = 1 'for feature use
'The response from the display should be ACK message &h06
End Sub |
PS. don't forget to change constant for your uart:
Const Lcd_4d = 4 '4d system uart |
|
Back to top |
|
|
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Mon Mar 04, 2019 8:43 pm Post subject: Recept nul char / Bascom |
|
|
Hello Pikczu
Thank you for the info, between the moment I paused the question and the moment when you answer me, I found the solution. But I tested the function with the parameters: Call 4d_write_obj (Coolgauge, & H00, & h32) and GTX shows this!
Apparently he does not understand the command because I do not get an ACK!
See print sreen
Sincerely Bernard |
|
Back to top |
|
|
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Mon Mar 04, 2019 8:45 pm Post subject: Recept nul char / Bascom |
|
|
GTX Attachement |
|
Back to top |
|
|
Pikczu
Joined: 22 Jan 2006 Posts: 72 Location: Dublin, Ireland
|
Posted: Mon Mar 04, 2019 9:34 pm Post subject: |
|
|
Yes that is fine be cause you sending data to Software not to the display.
You need the display for that. |
|
Back to top |
|
|
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Mon Mar 04, 2019 9:57 pm Post subject: Recept nul char / Bascom |
|
|
Ok I thought that GTX emulated the display completely!
So I'm waiting for the display.
in any case I thank you and give you news
Bernard |
|
Back to top |
|
|
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Wed Mar 06, 2019 7:31 pm Post subject: Recept nul char / Bascom |
|
|
hi pikczu
i got the lcd is the update function of the coolgauge with ultrasonic distance sensor works with your program !!
I would like to write text on the lcd is why I wrote:
4d_string_tx = "Little demonstration" (assign the string) and call the function:
Call 4d_write_str (4d_str_indx, 4d_string_tx, ..? ..)
what is the 3rd parameter?
Thanks for your info
Bernard |
|
Back to top |
|
|
Pikczu
Joined: 22 Jan 2006 Posts: 72 Location: Dublin, Ireland
|
Posted: Wed Mar 06, 2019 11:12 pm Post subject: |
|
|
Hi Bernard,
You can create string in the workshop4 and then just call them by write_obj command.
Or you can send new string in to it.
I don't have string sub routine ready yet. The 3td parameter should be 0 no characters added or 1 for CR or 2 LF.
I spend some time on it during Sunday evening, but then I have realized it is wrong way.
simply chr(13) should do the same job.
and all of them select cases for LF and CR are not needed.
Any way I will fix it soon.
Use this one for the moment but put zero (0) as the 3rd parameter.
Code: | Sub 4d_write_str(byval 4d_str_indx As Byte , Byval 4d_string_tmp As String , Byval Cr_lf As Byte )
'the body of the command is:
'code + string_index+ string_length + string + xorcrc
Local Index_help_a As Byte 'used to calculate the length of the string
Local Index_help_b As Byte 'used to calculate position of the XOR CRC in array, string length+3
Local Str_tmp_len As Byte 'used for calculating the length before adding CR or LF
Dim Tot_command_len As Byte 'total command length
'******************************************************************************
'******************************************************************************
Str_tmp_len = Len(4d_string_tmp) + 1 'get the length of the original string
'if we adding CR or LF then we need to find the length.
Select Case Cr_lf
Case 0: 'no CR or LF added
Tot_command_len = Len(4d_string_tmp) + 4 'string length(+) command (+) string index (+) string
Case 1:
Insertchar 4d_string_tmp , Str_tmp_len , &H0D 'insert CR at the end, now we have to recalculate length again
Tot_command_len = Len(4d_string_tmp) + 4 'string length(+) command (+) string index (+) string
Case 2:
Insertchar 4d_string_tmp , Str_tmp_len , &H0A 'insert LF at the end, now we have to recalculate length again
Tot_command_len = Len(4d_string_tmp) + 4 'string length(+) command (+) string index (+) string
End Select
4d_string_tx = 4d_string_tmp 'copy the string in to variable overlaid at array
4d_string_tx_arr(1) = Write_str '&h02 write string command
4d_string_tx_arr(2) = 4d_str_indx 'index of the string
4d_string_tx_arr(3) = Len(4d_string_tmp) 'length of the string
For Index_help_a = 1 To Tot_command_len -1 'we need to xor this and assign at the end
'the minus (-)1 skip xor of the null termination
4d_string_tx_arr(tot_command_len) = 4d_string_tx_arr(tot_command_len) Xor 4d_string_tx_arr(index_help_a)
Next Index_help_a
Select Case Tot_command_len ' total command length
Case 5:
Printbin #1 , 4d_string_tx_arr(1) ; 5 'code +string index+ string length + 1 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 5 'code +string index+ string length + 1 char + crc
Case 6:
Printbin #1 , 4d_string_tx_arr(1) ; 6 'code +string index+ string length + 2 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 6 'code +string index+ string length + 2 char + crc
Case 7:
Printbin #1 , 4d_string_tx_arr(1) ; 7 'code +string index+ string length + 3 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 7 'code +string index+ string length + 3 char + crc
Case 8:
Printbin #1 , 4d_string_tx_arr(1) ; 8 'code +string index+ string length + 4 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 8 'code +string index+ string length + 4 char + crc
Case 9:
Printbin #1 , 4d_string_tx_arr(1) ; 9 'code +string index+ string length + 5 char + crc
Printbin #4 , 4d_string_tx_arr(1) , 9 'code +string index+ string length + 5 char + crc
Case 10:
Printbin #1 , 4d_string_tx_arr(1) ; 10 'code +string index+ string length + 6 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 10 'code +string index+ string length + 6 char + crc
Case 11:
Printbin #1 , 4d_string_tx_arr(1) ; 11 'code +string index+ string length + 7 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 11 'code +string index+ string length + 7 char + crc
Case 12:
Printbin #1 , 4d_string_tx_arr(1) ; 12 'code +string index+ string length + 8 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 12 'code +string index+ string length + 8 char + crc
Case 13:
Printbin #1 , 4d_string_tx_arr(1) ; 13 'code +string index+ string length + 9 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 13 'code +string index+ string length + 9 char + crc
Case 14:
Printbin #1 , 4d_string_tx_arr(1) ; 14 'code +string index+ string length + 10 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 14 'code +string index+ string length + 10 char + crc
Case 15:
Printbin #1 , 4d_string_tx_arr(1) ; 15 'code +string index+ string length + 11 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 15 'code +string index+ string length + 11 char + crc
Case 16:
Printbin #1 , 4d_string_tx_arr(1) ; 16 'code +string index+ string length + 12 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 16 'code +string index+ string length + 12 char + crc
Case 17:
Printbin #1 , 4d_string_tx_arr(1) ; 17 'code +string index+ string length + 13 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 17 'code +string index+ string length + 13 char + crc
Case 18:
Printbin #1 , 4d_string_tx_arr(1) ; 18 'code +string index+ string length + 14 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 18 'code +string index+ string length + 14 char + crc
Case 19:
Printbin #1 , 4d_string_tx_arr(1) ; 19 'code +string index+ string length + 15 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 19 'code +string index+ string length + 15 char + crc
Case 20:
Printbin #1 , 4d_string_tx_arr(1) ; 20 'code +string index+ string length + 16 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 20 'code +string index+ string length + 16 char + crc
Case 21:
Printbin #1 , 4d_string_tx_arr(1) ; 21 'code +string index+ string length + 17 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 21 'code +string index+ string length + 17 char + crc
Case 22:
Printbin #1 , 4d_string_tx_arr(1) ; 22 'code +string index+ string length + 18 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 22 'code +string index+ string length + 18 char + crc
Case 23:
Printbin #1 , 4d_string_tx_arr(1) ; 23 'code +string index+ string length + 19 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 23 'code +string index+ string length + 19 char + crc
Case 24:
Printbin #1 , 4d_string_tx_arr(1) ; 24 'code +string index+ string length + 20 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 24 'code +string index+ string length + 20 char + crc
Case 25:
Printbin #1 , 4d_string_tx_arr(1) ; 25 'code +string index+ string length + 21 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 25 'code +string index+ string length + 21 char + crc
Case 26:
Printbin #1 , 4d_string_tx_arr(1) ; 26 'code +string index+ string length + 22 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 26 'code +string index+ string length + 22 char + crc
Case 27:
Printbin #1 , 4d_string_tx_arr(1) ; 27 'code +string index+ string length + 23 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 27 'code +string index+ string length + 23 char + crc
Case 28:
Printbin #1 , 4d_string_tx_arr(1) ; 28 'code +string index+ string length + 24 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 28 'code +string index+ string length + 24 char + crc
Case 29:
Printbin #1 , 4d_string_tx_arr(1) ; 29 'code +string index+ string length + 25 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 29 'code +string index+ string length + 25 char + crc
Case 30:
Printbin #1 , 4d_string_tx_arr(1) ; 30 'code +string index+ string length + 26 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 30 'code +string index+ string length + 26 char + crc
Case 31:
Printbin #1 , 4d_string_tx_arr(1) ; 31 'code +string index+ string length + 27 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 31 'code +string index+ string length + 27 char + crc
Case 32:
Printbin #1 , 4d_string_tx_arr(1) ; 32 'code +string index+ string length + 28 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 32 'code +string index+ string length + 28 char + crc
Case 33:
Printbin #1 , 4d_string_tx_arr(1) ; 33 'code +string index+ string length + 29 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 33 'code +string index+ string length + 29 char + crc
Case 34:
Printbin #1 , 4d_string_tx_arr(1) ; 34 'code +string index+ string length + 30 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 34 'code +string index+ string length + 30 char + crc
Case 35:
Printbin #1 , 4d_string_tx_arr(1) ; 35 'code +string index+ string length + 31 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 35 'code +string index+ string length + 31 char + crc
Case 36:
Printbin #1 , 4d_string_tx_arr(1) ; 36 'code +string index+ string length + 32 char + crc
Printbin #4 , 4d_string_tx_arr(1) ; 36 'code +string index+ string length + 32 char + crc
End Select
End Sub
|
PS. is there any chance you change or add 4d systems in to the topic name?
This will help search for 4D system related topic in the feature. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|