Android Question Write2 Error ?

jinyistudio

Well-Known Member
Licensed User
Hi

I use seriallibjab to control one RS-232 in a 7" SBC(Single board computer). The PC get a wrong code when SBC send out a string to pc. But the string code is ok when SBC receive from PC.

B4X:
RS232.SetPort(port,115200,2)
AStream.Initialize(RS232.InputStream, RS232.OutputStream, "AStream")
========================================
Send code to PC ?? PC get wrong code
========================================
If     AStream.IsInitialized Then
    Dim buff() As Byte
    '
    buff = sTxt.GetBytes("UTF8")
    If     buff.Length>0 Then
        Dim n1 As Int
        n1 = buff.length
        AStream.Write2(buff,0,n1)
    End If
End If
=================================
Recieve event !! SBC get a good code
=================================
Sub AStream_NewData(buffer() As Byte)
    Dim  s1 As String
    Dim n1,n2,n3,chl,val As Int
    '
    If Qc.Com =0 Then
        Return
    End If
    '
    n2 = buffer.Length
    If n2>0 Then
        For n1=0 To n2-1
            n3 = buffer(n1)
            If b4alib.IOf(n3,57,48)  OR b4alib.IOf1 (n3, Array As Int(75,78,79)) Then
                bfbytes(bfindex) = buffer(n1)
                bfindex = bfindex + 1
            End If
       
            If buffer(n1)=35 Then '#
                bfindex = 0
            End If
           
            If buffer(n1)=13 Then '<CR>
                s1 = BytesToString(bfbytes, 0, bfindex, "UTF8")
                If s1="OK" Then
                    ' Command = 2,4,6,7,8,10,11
                    Qc.Com = 0
                Else If s1="NOK" Then
                    Qc.com = 999
                Else
                    If IsNumber(s1) Then
                        chl = Qc.cha
                        val=s1
                        Select Qc.com
                            Case 1:' PWM<n>R  Reading Registry
                                Qc.val = val
                            Case 3:'VIN Reading supply voltage
                                Qc.val = val
                            Case 5:'DLYR Reading Registry delay response (DELAY)
                                Qc.val = val
                            Case 9:'EES State saving parameters in EEPROM
                                Qc.val = val
                            Case 12:'EER Reading EEPROM user memory
                                Qc.val = val
                            Case 13:'VER HW and FW version
                        End Select
                        Qc.Com = 0
                    Else
                        Qc.com=999
                    End If
                End If
                bfindex = 0
            End If
        Next
    End If
End Sub
 

Attachments

jinyistudio

Well-Known Member
Licensed User
Hi :mad:

Sorry, This question have solve, My SBC has one RS232,one RS485. the mark of case is reverse. rs232 mark to rs485 and rs485 mark to rs232.
SBC = single board computer http://www.icnexus.com.tw/product-ec04.asp
 
Top