miss match result using B4A

suciwulans

Active Member
Licensed User
Longtime User
I want to control PLC omron CPM1A using this command
00KSCIO 000000 and the result must @00KSCIO 0000003D*. when i use
VB 6 the result is ok but when i convert to B4A the result missmatch become
@00KSCIO 0000003d*. I got lower case d. any mistake conversion to B4A? can anyone help me?:sign0163:

VB6

B4X:
Private Sub Command1_Click()
txt=txtcommandPLC.text
call send
end sub

Send:                                                      
Length = Len(txt)
    R = Asc( "@")
    For I = 1 To Length
        K = Mid(txt , I , 1)
        R = R Xor Asc(k)
    Next
txtsend.text= "@" ; Txt ; Hex(R) ; "*" ; Chr(13)

B4A
B4X:
Dim type_PLC As String
dim length as string
type_PLC= edtPLC.Text
Length=type_PLC.Length
     R = Asc( "@")
    For I = 1 To Length
        K = Asc(type_PLC.CharAt(I-1)) 
         R=Bit.Xor(R,K)
    Next
   R=Bit.ToHexString(R)
   edtSendPLC.Text ="@" & type_PLC & R & "*" & Chr(13)
 

stevel05

Expert
Licensed User
Longtime User
Bit.ToHexString return lowercase characters in the hexstring, you could use:

B4X:
edtSendPLC.Text ="@" & type_PLC & R.ToUpperCase & "*" & Chr(13)

Provided you have declared R as a string.
 
Last edited:
Upvote 0
Top