B4J Question use /dev/ttymxc0 in ubuntu

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

I use following code. It's OK in window7.
It always received 0 or -1 in the AStream_NewData when i run it use /dev/ttymxc2 in ubuntu. Why ???

jserial --> v1.05

B4X:
private Sub OpenSerial(port As String,baudrate As Int)
    sp.Open(port)
    sp.Initialize("")
    sp.SetParams(baudrate,8,1,0)   
    'sp.SetPort(port,baudrate,2)
    AStream.Initialize(sp.GetInputStream, sp.GetOutputStream, "AStream")
    pgConnected = True
    Queue.Clear
    '   
    t2.Reset
    Timer1.Enabled=True
End Sub
'
private Sub AStream_NewData(buffer() As Byte)
    Dim n1 As Int=buffer.Length
    Dim bc As ByteConverter
    bc.ArrayCopy(buffer,0,Rxb.Data,Rxb.Count,n1)
    Rxb.Count=Rxb.Count+n1
End Sub
'
 

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

I try following code in ubuntu but i don't connect anything, why i get lofs of "FF" ?

In this Panel pc have three serial port (ttymxc0~2), 0 and 1 are OK( they cann't display anything) !

ttymxc0 and 1 are RS-232, ttymxc2 is RS-485/2W


B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Private astream As AsyncStreams
    Private sp As Serial
    Private s1 As String=""
    Private n3 As Int=0
End Sub

Sub AppStart (Args() As String)
    sp.Open("/dev/ttymxc2")
    sp.Initialize("")
    sp.SetParams(19200,8,1,0)  
    'sp.SetPort(port,baudrate,2)
    astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "AStream")      
    'astream.Write2(Array As Byte(1,2,3,4,5),0,5)
  StartMessageLoop
End Sub

Sub astream_NewData (Buffer() As Byte)
    Dim n1 As Int=Buffer.Length
    If n1 >0 Then
        Dim n2 As Int
        For n2=0 To n1-1
            s1= s1 & " " & b4jlib.Byte2Hex(Buffer(n2))
            n3=n3+1
            If n3>=16 Then
                Log(s1)'BytesToString(Buffer, 0, Buffer.Length, "utf8").Trim)  
                s1=""
                n3=0
            End If          
        Next
       End If
End Sub
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
I hate the cable. give me more nosie ! :p
 
Upvote 0
Top