大家好,想請教一個問題,一開始是工作上需要寫一個GUI做硬體測試用
我選擇wxpython去完成GUI,所以現在有簡單的Function buttom。
要傳遞的命令是「一個byte的16進制0x55」以下是我撰寫的python code
def OnCommand(self, e):
port = "COM3"
band = 115200
ser = serial.Serial(port, band, timeout=1)
print(ser.name)
ser.write('0x55'.encode('utf-8'))
out = ser.read()
print(out)
以上是buttom被按下的功能
之所以會這樣撰寫,因為在python IDE下我做了一些測試
>>> a='0x55'
>>> ((a).encode('utf-8'))
b'0x55'
所以我認為會傳遞我想要的資料格式。
但是硬體的C Code宣告的接收資料的buff格式是uint8_t,
我的疑問是C的部分會不會不懂得從python傳遞的資料。
這中間的過程有在google搜尋過相關的問題,但都英文的網頁
閱讀實在有點困難,還是說應該要用到ctype如果是這樣,又是另外一個大問題啦!!
感謝閱讀到這裡的所有人