Y a-t-il une section RS232 dans le lien ? Comme dans 3 fils, pour les données de transmission, les données de réception et la masse électrique commune (plus peut-être quelques fils de contrôle) ? Avec un connecteur D à 9 ou 25 broches.Le lien est usb vers rs232
Je pensais que nous avions découvert qu'il n'y avait pas de 252 dans les données reçues et que le dernier octet des paquets était 249 (hex 0xF9) :c'est une entreprise qui définit le protocole de 19 octet et la valeur de 252 pour synchroniser les données.
1709187211650 19 857F00AA08000F0000122400D2410000F807F9
1709187211682 19 857F00AA0800000000157E00D24100005C00F9
1709187211698 19 857F00AA08000F000018D800D2410000B900F9
1709187211714 19 857F00AA08000000001C3200D34100001800F9
1709187211746 19 857F00AA08000F00001F8C00D34100007500F9
1709187211762 19 857F00AA08000F000022E600D3410000D200F9
1709187211794 19 857F00AA0800000000274000D44100003200F9
1709187211810 19 857F00AA08000F0000299A00D44100008E00F9
1709187211842 19 857F00AA08000F00002CF400D4410000EB00F9
1709187211858 19 857F00AA08000000002F4E00D54100004900F9
1709187211890 19 857F00AA08000F000033A800D5410000A700F9
1709187211906 19 857F00AA0800000000360200D64100000500F9
1709187211922 19 857F00AA0800000000395C00D64100006200F9
1709187211954 19 857F00AA08000F00003DB600D6410000C000F9
1709187211970 19 857F00AA0800000000401000D74100001E00F9
1709187212147 7936
Pourquoi une telle rapidité ? Quelles sont les mesures envoyées ? L'heure ? Un décompte ? Une quantité, comme les volts, les ampères, les kilogrammes ou la température ?Les paquets de 19 octets peuvent arriver toutes les 0.4 ms
Je me suis demandé si l'avant-dernier octet était une somme de contrôle, mais je me suis dit que notre première étape était de recevoir les données, et que nous pourrions nous préoccuper de la somme de contrôle plus tard.sont encodées pour minimiser le risque d'erreur de transmission et les détecter.
Si les données en série sont continues et plus rapides que ce que le smartphone peut traiter, et que nous ne pouvons pas ignorer les paquets périmés pour n'utiliser que le paquet le plus récent, l'ajout d'une mémoire tampon ne fera que retarder le problème, sans le résoudre.Ce qui compte surtout c'est d'afficher la dernière donnée que l'utilisateur souhaite filtrer,
sans aucun oubli de la part du programme.
le temps que met le smartphone ... et plus long que le temps pour recevoir et les données recues.
un buffer de quelques kilo-octet puis lancer une routine séparée qui calcule, filtre et affiche les données.
Using Google Translate, so I do not know how well it translates. Original English post quoted below:
Please note that the _NewData sub is an event that runs on the main thread. Data capturing via Asyncstream does happen on a separate thread, but the _NewData events are placed into the event queue of the main thread. Therefore, if you do a lot of processing in _NewData or any subs that are directly called from _NewData, will "block" other _NewData events from executing. If it is not necessary to process every single byte received via _NewData, then you can use _NewData to just capture and queue all the bytes received and then use a Timer to process any received data and some acceptable frequency (for example, every 250ms). Again, the goal is to complete the process in the Timer event as fast as possible in order to allow the app to process all the _NewData events in the queue.
As to signed / unsigned bytes. Unless you need to display the data, or you need to perform operations besides shifting / masking, you do not really need to convert the unsigned bytes to signed bytes. So even that conversion can be delayed as much as possible.
1709187211650 19 857F00AA08000F0000122400D2410000F807F9
1709187211682 19 857F00AA0800000000157E00D24100005C00F9
1709187211698 19 857F00AA08000F000018D800D2410000B900F9
1709187211714 19 857F00AA08000000001C3200D34100001800F9
1709187211746 19 857F00AA08000F00001F8C00D34100007500F9
1709187211762 19 857F00AA08000F000022E600D3410000D200F9
1709187211794 19 857F00AA0800000000274000D44100003200F9
1709187211810 19 857F00AA08000F0000299A00D44100008E00F9
1709187211842 19 857F00AA08000F00002CF400D4410000EB00F9
1709187211858 19 857F00AA08000000002F4E00D54100004900F9
1709187211890 19 857F00AA08000F000033A800D5410000A700F9
1709187211906 19 857F00AA0800000000360200D64100000500F9
1709187211922 19 857F00AA0800000000395C00D64100006200F9
1709187211954 19 857F00AA08000F00003DB600D6410000C000F9
1709187211970 19 857F00AA0800000000401000D74100001E00F9
1709187212147 7936
Le dernier octet est de 252 et ne change pas.
"I can decode + display the data properly if it is sent every 10 ms"
"But as soon as it is sent every 0.5 ms the smartphone freezes."
Do you need to display new data every 0.5 ms? Do you need to capture it for computational/historical reason for 0.5ms? What is the longest time that you can keep new data from displaying without compromising the display output? You have to remember, that it may not necessarily the data capturing that is freezing you phone, but you are also creating an update event for the display data every .5ms. That may be the reason the phone freezes, since the event queue is bombarded with display update events. So even if you need to capture (to store, to process, to do whatever) the data every .5 ms, I really doubt that the information needs to be displayed that quickly. At a refresh rate of 60Hz, you are looking at roughly 16ms per refresh, at 120Hz it's about 8ms. So capture your data at .5ms, but only display the most current data (or whatever algorithm you want to go by - lowest value, highest value, average value, last value, etc) every 8 - 16ms.
"and then decode it and display it in another thread."
This is where you may get yourself in trouble. Trying to access the UI from another thread will cause you're app to crash (most likely). In the end, I really don't think you need threading, you just need to rethink how you capture data and when to display that data. As previously mentioned, if you use a Timer event, you may be able to achieve success without threading (set the timer value to the minimum required refresh rate of the data to be displayed).
afficher les données convenablement si elles sont envoyées toutes les 10 ms
Google Traduction:Je pense qu'un smartphone récent de 2020 ou supérieur fonctionnerait bien.
"I think a recent smartphone from 2020 or higher would work fine."
If you are doing display updated every 0.5 ms of one or more text fields, then I think even a smarthone from 2020 or higher will have issues with processing 2000 screen update events every second.
je voudrais effectuer une mise à jour de l'affichage toutes les 20 ms, ça serait très bien.
Google Traduction:Qu'en pensez vous ?
"I'd like to update the display every 20ms, that would be fine."
Then use _NewData to buffer the incoming data. Then, using a Timer, with an internval of 20ms, read the buffers last 19 byte packet received and display the information. Clear the buffer (or save it) and then exit the timer event. See what happens.
"What do you think?"
I would do the above first before diving into threading. B4A can handle G.729 annex B encoding / decoding in B4A language without issues on some Android 6 hardware without threading. So I would first try to implement all of this without adding extra threading onto what B4A already does for you
#Region Project Attributes
#ApplicationLabel: Counter-Data's
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
'Activity module
Sub Process_Globals
Private usbserial As felUsbSerial
Private manager As UsbManager
End Sub
Sub Globals
Dim kilobuf(512) As Byte
Dim tst0, index As Int
Dim lbl0, lblunit, lbldiz, lblcent As Int = 0
Private btnConnect, Button1 As Button
Private Label1, Label2, Label3, label4, Label5, label6, label7, label8 As Label
Private EditText1 As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
manager.Initialize
End If
Activity.LoadLayout("main") ' load the layout
End Sub
Sub btnConnect_Click
If manager.GetDevices.Length = 0 Then
Label1.Text = "No USB devices."
Else
Dim device As UsbDevice = manager.GetDevices(0) 'the device
If manager.HasPermission(device) = False Then
manager.RequestPermission(device)
Else
usbserial.BUFFER_READ_SIZE = 256
usbserial.BUFFER_WRITE_SIZE = 128
usbserial.Initialize("serial", device, -1)
usbserial.BaudRate = 460800
usbserial.DataBits = usbserial.DATA_BITS_8
usbserial.Parity = usbserial.PARITY_NONE
usbserial.FlowControl = usbserial.FLOW_CONTROL_OFF
usbserial.StartReading
Label1.Text = "Connected"
End If
End If
End Sub
Private Sub serial_DataAvailable (Buffer() As Byte)
' Dim incr As Byte = 0
If Buffer.Length > 16 Then
If 252 = Bit.And(0xFF,Buffer(16)) Then
' incr = 0
index = index + 1
' For incr = 0 To 16 Step 1
' kilobuf(index+incr) = Buffer(incr)
' Next
label6.text = (index) 'tst0
If index > 170 Then
index = 0
End If
End If
End If
End Sub
Sub Activity_Resume
' For tst = 1 To 522222 Step 1
' tst0 = tst0 + 1
' Sleep (50)
' label6.text = (index) 'tst0
' Next
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Si ça marche, ça marchePensez vous que usbserial est mieux ?
Dans ce cas, même si cela fonctionne, je serais toujours réticent à mettre à jour l'interface utilisateur 2 000 fois par seconde.Maintenant quand je reçois des informations toute les 0,5 µs ça fonctione, le smartphone ne freeze plus
Maintenant quand je reçois des informations toute les 0,5 µs ça fonctione, le smartphone ne freeze plus
je serais toujours réticent à mettre à jour l'interface utilisateur 2 000 fois par seconde.
Sinon le 50hz >> f=1/t = 20ms chez les frenchiies et aux US 1/60 = 16.66ms.
Rafraichir l'interface plus vite que ça ne sert pas à grand chose.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?