Android Question COMUNICATION USB FTDI

Discussion in 'Android Questions' started by llorenç Galofré, Jun 5, 2015.

  1. llorenç Galofré

    llorenç Galofré Member Licensed User

    hello
    I am programmed to read data from a SD84 plate (with FTDI chip), which has a number of analog inputs. Aparantemente everything works fine (USB permit communication with the plate in one direction or the other, etc.), but I find that the received data (in the event AStreams_NewData AsyncStreams), which should be two bytes, is They receive both 1 byte and 2 nonsense in value (for example 67 for receiving an analog input to zero); Maybe this is the format of the data received or some other problem. ). Anyone know how to fix the problem. Here I put the code reception:
    Sub AStreams_NewData(buffer() As Byte)
    Dim ValorTotal As Int, IntRetornats(2) As Short
    EsperantDades=False
    Try
    If buffer.Length=0 Then
    Codi1.OutPutNou("SD84Cont.AStreams_NewData: error: dimensió del buffer rebut igual a 0.")
    Else If buffer.Length=1 Then
    NumRes1=NumRes1+1
    IntRetornats(0)=buffer(0)
    If NumCanalEA=13 Then
    ListBuffer1.Add(IntRetornats(0))
    EAValor(NumCanalEA)=5*ValorTotal/1024
    End If
    Select IntRetornats(0)
    Case 0 ' no error
    Case 1
    Codi1.OutPutNou("SD84Cont.AStreams_NewData: error 1: advertencia -intent de canviar de
    escritura de mode analògic a mode registre, s'ignora-.")
    Case 2
    Codi1.OutPutNou("SD84Cont.AStreams_NewData: error 2: Rang de canals no vàlit.")
    Case 3
    Codi1.OutPutNou("SD84Cont.AStreams_NewData: error 3: mode desconegut.")
    Case Else
    End Select
    Else If buffer.Length=2 Then
    NumRes2=NumRes2+1
    IntRetornats(0)=buffer(0)
    IntRetornats(1)=buffer(1)
    ValorTotal=IntRetornats(0) + 256 * IntRetornats(1)
    EAValor(NumCanalEA)=5*ValorTotal/1024
    If NumCanalEA=13 Then
    ListBuffer1.Add(IntRetornats(0) & " + " & IntRetornats(1))
    End If
    Dim i As Int, Posicions() As Int
    For i=NumCanalEA+1 To 25
    If EALectura(i)<=DateTime.Now Then
    NumCanalEA=0
    Codi1.ServoOperacio("LLEGIR EA",i,0,Posicions)
    Return
    End If
    Next
    NumCanalEA=0
    Else
    Codi1.OutPutNou("SD84Cont.AStreams_NewData: Dimensió de retorn superior a 2: " & buffer.Length)
    End If
    Catch
    Codi1.outputnou("SD84Cont.AStreams_NewData: " & LastException.Message)
    End Try
    NumCanalEA=0
    End Sub
     
  2. giga

    giga Well-Known Member Licensed User

  3. llorenç Galofré

    llorenç Galofré Member Licensed User

    Is not that I want to read the plate SD84 the value of an analog input voltage (0 to 5V); in Visual Basic for Windows running the following code:

    dim Entrada1 as byte, Entrada2 as byte, DigitalValue as int, AnalogValue as single
    'here code analog code reading application
    doevents
    Get #1, , Entrada1
    DoEvents
    Get #1, , Entrada2
    If CInt(Entrada2) >= 127 Then
    'error
    Else
    DigitalValue = CInt(Entrada1) + 256 * CInt(Entrada2)
    AnalogValue=5*DigitalValue/1024 'The analog inputs have a resolution of 10 bits = 1024 i can measure 0 to 5V
    End If

    Thank you for any help
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    AsyncStreams (in non-prefix mode) returns the data exactly as it returned from the native code.

    I'm not sure that I understand your code. Use the debugger and check the values of buffer before you do anything else with the data.
     
    Peter Simpson likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice