fishguy6564 / USB-Botbase

Sys-botbase by olliz0r with usb support.
GNU General Public License v3.0
55 stars 16 forks source link

Large number in peek #1

Open easyworld opened 4 years ago

easyworld commented 4 years ago

I modified example_PokemonSwSh_SurpriseTrade.py and try this peek 0x4293D8B0 10320 to get all pokemon in boxes, but it failed, Python says index out of range. I checked code from global_in.read(size, timeout=0), it doesn't have enough size of data. Is there any limitations of the size in peek operation? The original sys-botbase can support this peek 0x4293D8B0 10320 correctly.

fishguy6564 commented 4 years ago

This issue is due to the maximum transfer size being 4080 bytes that is present when communicating via USB. This is an issue that I have ran into very recently, so I have not uploaded a solution publicly, although, one exists. It has not been uploaded publicly yet as I am still working on the next update for USB-Botbase. I will release the updated read method which should solve this issue for now at least.

easyworld commented 4 years ago

The new python script doesn't work if the peek size parameter is larger than 478. After I change the 4080 to 478 in the new scirpt, it works when size is less or equal than 536. If peek size is greater than 536, python says:

Traceback (most recent call last):
  File "./example_PokemonSwSh_SurpriseTrade.py", line 120, in <module>
    main()
  File "./example_PokemonSwSh_SurpriseTrade.py", line 117, in main
    pokemonBytes = readData()
  File "./example_PokemonSwSh_SurpriseTrade.py", line 56, in readData
    x = global_in.read(chunkSize, timeout=0).tobytes()
  File "MyPython3Path\lib\site-packages\usb\core.py", line 402, in read
    return self.device.read(self, size_or_buffer, timeout)
  File "MyPython3Path\lib\site-packages\usb\core.py", line 983, in read
    ret = fn(
  File "MyPython3Path\lib\site-packages\usb\backend\libusb0.py", line 537, in bulk_read
    return self.__read(_lib.usb_bulk_read,
  File "MyPython3Path\lib\site-packages\usb\backend\libusb0.py", line 622, in __read
    ret = int(_check(fn(
  File "MyPython3Path\lib\site-packages\usb\backend\libusb0.py", line 431, in _check
    raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_reap_async] reaping request failed, win error: \xc1\xac\xb5\xbd\xcf\xb5\xcd\xb3\xc9\xcf\xb5\xc4\xc9\xe8\xb1\xb8\xc3\xbb\xd3\xd0\xb7\xa2\xbb\xd3\xd7\xf7\xd3\xc3\xa1\xa3\r\n\n'

The last error string is Chinese which means "The device connected to the system is not functioning."

And my main function is like this:

def main():
    attemptConnection()
    sendCommand("click Y")
    time.sleep(2)
    sendCommand("click B")
    time.sleep(2)
    sendCommand("peek 0x4293D8B0 537")
    pokemonBytes = readData()
    print (pokemonBytes)

My switch system version is 10.0.3|AMS 0.12.0|E