Read Data by Identifier as an unformatted raw content dump? · Issue #152 · pylessard/python

您所在的位置:网站首页 python0o Read Data by Identifier as an unformatted raw content dump? · Issue #152 · pylessard/python

Read Data by Identifier as an unformatted raw content dump? · Issue #152 · pylessard/python

#Read Data by Identifier as an unformatted raw content dump? · Issue #152 · pylessard/python| 来源: 网络整理| 查看: 265

Another approach, maybe more suited for your use case, would be to not use the client object and interract directly with the service level and the connection (since you seem to want to process the data outside of python).

This example should be useful to you.

Since you want to craft a request but not interpret the resposne (which the client does), you could do something like :

request = services.ReadDataByIdentifier.make_request(0x1234, my_didconfig) my_connection.send(request) response = my_connection.wait_frame(timeout=1, exception=False) if response: print("Gotten data : %s" % response.data)

In the above example, didconfig is the same config used by the client. The didconfig is not necessary to craft the request, it is just validated to fail early instead of sending a request and waiting for a response to then fail. I should have made that parameter optional.. you can put any valid configuration that won't affect the request.

You could even be more clever and use the client send_request method. All client method does the same thing. It calls : service.make_request, client.send_request, service.interpret_response + do some sanity checks. Meaning, something like that would work.

request = services.ReadDataByIdentifier.make_request(0x1234, my_didconfig) try: response = client.send_request(request) print("Gotten data : %s" % response.data) except TimeoutException as e: print("No response") except NegativeResponseException as e: print("server said no. Payload : " + str(e.response.data)) except InvalidResponseException as e: print("Server is drunk. Payload: " + str(e.response.data)) except UnexpectedResponseException: # Only happen if you use the client methods. `send_request` will never raise this. pass

You may have notice the usage of the exception. I wanted to show it to you because you use none in your above code. :) The client raises exception. You can disable them with the configuration, bu you still need to check yourself if the response is valid/negative/unexpected. The response will only be None if you use SuppressPositiveResponse.

TimeoutException cannot be disabled in the client.

Ok, that's enough. Have fun



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3