--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/PYZ5iZ2iRqk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a7d412c7-fd36-4464-87d9-0754c2047edd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8749CFC0-0257-4B40-84D4-68D694232556%40gmail.com.
Here is some additional information.
It is maybe more than you need to know
I will refer to the 2 sides of the USB link as the Android and the Dongle.
The Dongle is an embedded system with a PIC24 that has builtin USB capability. The Android application is used to configure the embedded application that runs on the PIC and collect information from it.
Both sides of the USB connection – Android and Dongle are set to speed of 9600
Under many cases the Android App sends a command to the Dongle and the Dongle responds quickly. These work with no problems. The amount of data transmitted is 3 to 10 bytes.
The problems occur when larger amounts of information are sent back and forth. These are configuration files and are in JSON format. They are between 400 and 2500 bytes in length. These files are sent in both direction. There does not appear to be an issue when the file are sent from the Android to the Dongle.
The Android sends a command that means “send me your config”, and then issues a readinto for the max amount of data it might get back.
Dongle spends some time collecting this information, during that time it sends some “progress indicators” back to the Android. The time between each progress indicator is Less that the timeout period but greater than the inter character gap at 9600 baud. I am approximating the time to send 1 character at 9600 baud is 1 millisecond. The delay between progress indicators is about 0-2 seconds and the time out set at 3-5 seconds. Then when all the data is collected by the dongle it is sent back as a character stream. The config data is in a binary table on the dongle and the program steps through the data item by item genetating a JSON formatted item and sending it. For example if one item was temperature with a value of 21 The dongle generates a line that says in ASCII
“Temperature” : 21 \n\r
And sends it . Essentially keyword value pair. This happens faster or close to the inter character gap at 9600 baud. None of data is lost
Then there is a second case where the there are multiple value items for the data item and look like this,
"Step 4": [0,1,90,"J",110,10,70,2],\n\r
In generating this line in ASCII there are 8 binary to ASCII numeric conversions so this kind of line takes longer to generate that the simpler line. I do not know how much longer. There are about 20 lines like this and data is always lost on some of the lines. I think that the time to generate this line is longer than the inter character gap at 9600 baud.
Details of a specific case
Original situation (works on windows and linux)
Do a
buff = bytearry(2500)
count = readinto(buff) – expecting just under 2k with a buffer size of 2500.
This returns a count of 34 and stops during the preliminary “progress indicators”
The amount expected was 2020
The second test is splitting the above into 2 separate readinto
buff1 = bytearray(1020)
count1 = readinto(buff1)
buff2 = bytearray(1020)
count1 = readinto(buff2)
there is no delay between the 2 pairs of instruction.
In this case count1 = 1020 and all 36 of the preliminary progress indicators are read plus JASON data. In this part of the JSON data there are no multivalued items and no data is lost.
Then count2 = 930 , I was expecting 1000 and 70 characters were missing, scattered though out the data . The last data item in the JSON stream is a single value item and was present.
Conclusion – two slight different kinds of error
First case – when the inter character gap is greater than 9600 baud and the block read is very large, perhaps bigger than the DEFAULT_READ_BUFFER_SIZE ? then the read times out soon on one of the inter character gaps
Second case – when the inter character gap is greater than 9600 baud and the block read is smaller than the DEFAULT_READ_BUFFER_SIZE ? then one block is read OK
But when the second block is read some char again with a probably more big inter character gaps than the first block is read until the end but there are characters missing from the middle of the block.
Question – about how the USB CDC protocol works – when you set the speed to 9600 does it really run at 9600 or is that there to control the speed con the serial side coming out of the USB and is something that is used by the USB to serial converter ?
Question Does my Android tablet – a Lenovo TB-8504F , Android 8.1.0 RAM 2GB , ROM 16GB have enough horsepower hardware and software to handle this data rate . Should do because for example internet access via WiFi and other datatransfers vis USB seem good. – The is more over head running python .
Question in looking at the serial4a code I noticed that the hardware read , i.e. _read() has a time out of 1 millisecond, about the same as the time for one character ? is this relevant?
Roger
Results of testing with the delay on _read.
High level – My code did not work. What happened initially is that it would not get past the “progress indicators that precede the main data transmission. I ‘fixed’ this by changing the frequency that they were issued. In the standard pyserial this can adjusted with the intercharacter gap, but I have never had to do this. I did not try using this with the Android. Then when transmitting the main blocks of data some was lost, this was the same as happened before the delay was put on the _read. In my case this seemed worse than before. Some was lost in a smaller data block of about 500 bytes that previously never lost data. So I do not think it is solved yet.
Even higher level comment. Quan’s comment about engineers wanting to user serial communication to talk to embedded equipment, some specialized equipment and do data capture is very valid. The way pyserial works on Windows and Linux does this quite well. It provides quite a number of options and is very forgiving. Basically my app – sends a command that might get 2 to 3K of data back. I know this is going to take 2-5 seconds . I don’t know exactly how much data nor it format nor exactly how long it will take. My app uses port.readinto() combined with a port. Timeout() that says this and it works. It does not mind if the data flow is slightly irregular in rate , exactly how many or how long and no data is lost.
Where we are at this point is that if the data comes at a slightly irregular rate, it times out and does not seem to recover. And when the data stream is flowing it drops characters. It does work consistently with smaller data blocks, approximately up to 500 characters when the data flow is regular.
These days people expect to do many things with their phone or tablet. These devices are not well equipped to connect to some external devices. In doing something new from scratch on both sides of the connection probably the best way to go is Bluetooth or similar. But there are lots of serial devices we have to communicate with.
In the interests of full disclosure – I have been involved in IT since the 1960s, I worked for startups and been the CIO of a large company. I am retired. I have written code either for work or other activites all of that time and still do some development. I have some systems , communications, applications and embedded software experience. I’m more comfortable in C than other languages but some I do these days is in Python/Kivy for portability. I’ve worked with Microchip MCU as a hobby activity for over 20 years. I’m ok with Windows and Linux but not so familiar with the insides of Android.
Roger