Android Question COMUNICATION USB FTDI

llorenç Galofré

Member
Licensed User
Longtime 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
 

llorenç Galofré

Member
Licensed User
Longtime 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
 
Upvote 0
Top