Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:52 18 Sep 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Serial HEX Receive to ASCII

Author Message
2001cpx

Regular Member

Joined: 03/10/2013
Location: Canada
Posts: 59
Posted: 02:06pm 28 Nov 2016
Copy link to clipboard 
Print this post

HI!

(Using Micromite,with Graph Il9341)
Tried to Convert Serial data (HEX) ((Non Printable) to ASCII witout Succes,
with Read,Search,Trial error,etc.

Here is What is Receive In Micromite: (also Sniffed)

(20 Bytes)
0x13,0x00,0x01,0x01,0x01,0x0C,0x33,0x0F,0x2C,0xD4,0xB7,0xB0,0x67,0x09,0x97,0xE3,0x2B,0x2B,0x40,0xB4
(13000101010C330F2CD4B7B0670997E32B2B40B4)HEX
what i want is to Convert this data to ASCII,here Sloppy Code,only for test :

Option autorun on
SetTick 1000,DOINT
's$="0997D87388" 'String Chooped, test
't$="330F2CD4B7B0670997D87388" 'string complete
'u$="41202250634"'string decimal
'050001FBF23D reception
'13000101010C330F2CD4B7B0670997E32B2B40B4 string 20 bytes
'dim integer i=val("&h"+ e$)
c$=""
Open "com1:57600,42,SerialInt" As #1
Color RGB(255,255,255),RGB(120,120,120):CLS:Font 2
GUI caption #3, "1 abc 2", 0,0,,RGB(white),0
GUI caption #4, "3 def 4", 0,20,,RGB(green),0
GUI caption #5, "5 ghi 6", 0,40,,RGB(red),0
GUI displaybox #11,1,62,317,176,RGB(yellow),0

Do
Text 18,190," ",,,,RGB(RED),0
Text 18,210," ",,,,RGB(green),0
Pause 500
Text 18,70, c$,,,,RGB(red),0
Print c$
Print ess
Print e$

Loop

SerialInt:
c$=""
Text 18,210,"(COM1==> RX )",,,,RGB(Green),0
C$= Input$(20,#1)
ess = Len(c$)
e$= Mid$(c$,7,8)

'e$ = Left$(c$,1)
'If e$ <> Chr$(&H33) Then flag3=1:IReturn
'If e$ <> "33" Then flag3=1:IReturn
'd$ = Right$( c$, 10 )
'i=Val("&H"+ d$)
'Print #2, Str$(i)
'flag2 = 1
IReturn

Sub DOINT
Text 18,190,"(COM1==> TX )",,,,RGB(RED),0
Print #1,Chr$(&h04);Chr$(&h00);Chr$(&h01);Chr$(&hDB);Chr$(&h4B);'send command to RFID Module

End Sub


Thanks In Advance for your Help

"Color Maximite,(Duinomite-Mega,Mini),CGmmStick,GCmicroboard2b,Micromite + explore 64,100,LCD backpack,Lcd Backpack V2,TFT Backpack,Micromite Extreme,Armmite L,F,H,CMM2"
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10406
Posted: 10:24pm 28 Nov 2016
Copy link to clipboard 
Print this post

I assume the incoming data is in a string variable?

say s$

then to print the 5th character in hex use:

print hex$(asc(mid$(s$,5,1)),2)
Edited by matherp 2016-11-30
 
2001cpx

Regular Member

Joined: 03/10/2013
Location: Canada
Posts: 59
Posted: 09:39am 29 Nov 2016
Copy link to clipboard 
Print this post

Thanks For Your Help!

and Now,
how i can Print all Chars? and saving in Strings?

Thanks!
(before i used Proton Basic,which is Good,but i like More Micromite,and
i learn everyday!)




"Color Maximite,(Duinomite-Mega,Mini),CGmmStick,GCmicroboard2b,Micromite + explore 64,100,LCD backpack,Lcd Backpack V2,TFT Backpack,Micromite Extreme,Armmite L,F,H,CMM2"
 
2001cpx

Regular Member

Joined: 03/10/2013
Location: Canada
Posts: 59
Posted: 03:23pm 29 Nov 2016
Copy link to clipboard 
Print this post


Now this Work,But not sure is a good way to do that,anyway,
i begin to know more about HEX to Ascii,dec etc

when you know another language,it s very difficult,anyway for me.

I love Micromite!!!
(more than 2 days to achieve this...)



Option autorun on
SetTick 1000,DOINT
option explicit
's$="0997D87388" 'String Chooped, test
't$="330F2CD4B7B0670997D87388" 'string complete
'u$="41202250634"'string decimal
'050001FBF23D reception
'13000101010C330F2CD4B7B0670997E32B2B40B4 string 20 bytes(i receive this <==)
Dim string Var1$,Var2$,var5$,S$
dim integer K=val("&h"+ var5$)
DIM RECBYTE$(20)
dim var3,var4(20),i,a,b,var6
Open "com1:57600,42,SerialInt" As #1
Color RGB(255,255,255),RGB(120,120,120):CLS:Font 2
GUI caption #3, "1 abc 2", 0,0,,RGB(white),0
GUI caption #4, "3 def 4", 0,20,,RGB(green),0
GUI caption #5, "5 ghi 6", 0,40,,RGB(red),0
GUI displaybox #11,1,62,317,176,RGB(yellow),0
Do
Text 18,90,str$(var6),,,,RGB(RED),0
Text 18,190," ",,,,RGB(RED),0
Text 18,210," ",,,,RGB(green),0
Pause 500
Text 18,110, var5$,,,,RGB(red),0
Print recbyte$(13),recbyte$(14),recbyte$(15),recbyte$(16),recbyte$(17)
var5$= recbyte$(13)+ recbyte$(14)+ recbyte$(15)+ recbyte$(16)+recbyte$(17)

K=Val("&H"+ var5$)
if k <10 then
var6 = 0
else
var6 = 1
endif

if var6 = 1 then
Text 18,130, str$(K),,,,RGB(white),0
else
Text 18,130, " ",,,,RGB(white),0

endif

Loop

SerialInt:
Text 18,210,"(COM1==> RX )",,,,RGB(Green),0
FOR A = 0 TO 19
S$ = INPUT$(1, #1)
RECBYTE$(A) = HEX$(ASC(S$),2)
NEXT A

IReturn

Sub DOINT
Text 18,190,"(COM1==> TX )",,,,RGB(RED),0
Print #1,Chr$(&h04);Chr$(&h00);Chr$(&h01);Chr$(&hDB);Chr$(&h4B);'send command to RFID Module

End Sub

"Color Maximite,(Duinomite-Mega,Mini),CGmmStick,GCmicroboard2b,Micromite + explore 64,100,LCD backpack,Lcd Backpack V2,TFT Backpack,Micromite Extreme,Armmite L,F,H,CMM2"
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025