Job: Communicate with my Lasercutter....
Hallo, here i Translate "Textstring" to "HexString" and it's work perfect!
Any where any Idea to an shorter Version of my Sub(TranslateTextToHex)?
e.g....
Call's...
0.TranslateTextToHex("G0 X100 Y100 F10","")
1.TranslateTextToHex("G0 X10 Y210 F1000","")
2.TranslateTextToHex("G0 X200 Y210 F10","")
3.TranslateTextToHex("G0 X200 Y200 F1000","")
4.TranslateTextToHex("G0 X200 Y50 F10","")
5.TranslateTextToHex("G0 X10 Y10 F1000","")
6.TranslateTextToHex("G0 X0 Y0 F10","")
7.TranslateTextToHex("G1 X0 Y240 F1000","")
Sub TranslateTextToHex(Text As String,Tail As String)
Log("Show Text : " & Text)
Dim Dummy1 As Int
Dim Dummy2 As Int
Dim Dummy3 As Int
Dim Result As String
Text = Text.Replace(" ","")
Log("Show Text Clear: " & Text)
For I = 0 To Text.Length-1
Dummy1 = (Asc(Text.SubString2(I,I+1))/16)
Dummy1 = Dummy1 * 10
Log("Dummy1 :" & Dummy1)
Dummy2 = Asc(Text.SubString2(I,I+1)) Mod 16
Log("Dummy2 :" & Dummy2)
Dummy3 = Dummy1+Dummy2
Log("Result = " & Dummy3)
Result = Result & Dummy3
Next
'CRLF anfügen
'Add Tail here... Moment Constant
Result = Result & "0D0A"
Log(Result)
astream.Write(bc.HexToBytes(Result))
End Sub
Results:
0. Show Text : G0X100Y100F10
0. RESULT : 473058313030593130304631300D0A
1. Show Text : G0X10Y210F1000
1. RESULT : 47305831305932313046313030300D0A
2. Show Text : G0X200Y210F10
2. RESULT : 473058323030593231304631300D0A
3. Show Text : G0X200Y200F1000
3. RESULT : 4730583230305932303046313030300D0A
4. Show Text : G0X200Y50F10
4. RESULT : 4730583230305935304631300D0A
5. Show Text : G0X10Y10F1000
5. RESULT : 473058313059313046313030300D0A
6. Show Text : G0X0Y0F10
6. RESULT : 4730583059304631300D0A
7. Show Text : G1X0Y240F1000
7. RESULT : 473158305932343046313030300D0A
Thx, Skyracer...
Hallo, here i Translate "Textstring" to "HexString" and it's work perfect!
Any where any Idea to an shorter Version of my Sub(TranslateTextToHex)?
e.g....
Call's...
0.TranslateTextToHex("G0 X100 Y100 F10","")
1.TranslateTextToHex("G0 X10 Y210 F1000","")
2.TranslateTextToHex("G0 X200 Y210 F10","")
3.TranslateTextToHex("G0 X200 Y200 F1000","")
4.TranslateTextToHex("G0 X200 Y50 F10","")
5.TranslateTextToHex("G0 X10 Y10 F1000","")
6.TranslateTextToHex("G0 X0 Y0 F10","")
7.TranslateTextToHex("G1 X0 Y240 F1000","")
Sub TranslateTextToHex(Text As String,Tail As String)
Log("Show Text : " & Text)
Dim Dummy1 As Int
Dim Dummy2 As Int
Dim Dummy3 As Int
Dim Result As String
Text = Text.Replace(" ","")
Log("Show Text Clear: " & Text)
For I = 0 To Text.Length-1
Dummy1 = (Asc(Text.SubString2(I,I+1))/16)
Dummy1 = Dummy1 * 10
Log("Dummy1 :" & Dummy1)
Dummy2 = Asc(Text.SubString2(I,I+1)) Mod 16
Log("Dummy2 :" & Dummy2)
Dummy3 = Dummy1+Dummy2
Log("Result = " & Dummy3)
Result = Result & Dummy3
Next
'CRLF anfügen
'Add Tail here... Moment Constant
Result = Result & "0D0A"
Log(Result)
astream.Write(bc.HexToBytes(Result))
End Sub
Results:
0. Show Text : G0X100Y100F10
0. RESULT : 473058313030593130304631300D0A
1. Show Text : G0X10Y210F1000
1. RESULT : 47305831305932313046313030300D0A
2. Show Text : G0X200Y210F10
2. RESULT : 473058323030593231304631300D0A
3. Show Text : G0X200Y200F1000
3. RESULT : 4730583230305932303046313030300D0A
4. Show Text : G0X200Y50F10
4. RESULT : 4730583230305935304631300D0A
5. Show Text : G0X10Y10F1000
5. RESULT : 473058313059313046313030300D0A
6. Show Text : G0X0Y0F10
6. RESULT : 4730583059304631300D0A
7. Show Text : G1X0Y240F1000
7. RESULT : 473158305932343046313030300D0A
Thx, Skyracer...
Last edited: