本文采用python 2.7編寫。
經過長期搜尋,終于找到了Moxa PCOMM Lite。調用PCOMM.DLL可以非常方便的通過串口的Xmodem、Ymodem、Zmodem等協議傳輸文件,而無需重復制造輪子。
PCOMM Lite 1.6適用于Win7等系統,做為dll文件可以采用任何支持調用dll的編程語言例如VC++、VB、Qt等等編寫應用程序,下載地址為
http://www.moxa.com/drivers/pcommlite/win2k/setup_pcommlite_1.6_12041917.zip
以下是發送端的python代碼
1 #encoding=utf-8 2 3 from ctypes import * 4 5 dll = windll.LoadLibrary("PCOMM.DLL") 6 7 port = 2 # 指定串口COM2 8 9 dll.sio_open(port)10 11 dll.sio_ioctl(port, 15, 0x00 | 0x03 | 0x00) # 57600, 無校驗,8位數據位,1位停止位12 13 def cb(xmitlen, buflen, pbuf, flen):14 PRint xmitlen, flen,15 print 16 return xmitlen17 18 CALLBACK = WINFUNCTYPE(c_int, c_long, c_int, POINTER(c_char), c_long)19 20 ccb = CALLBACK(cb)21 22 dll.sio_FtYmodemTx(port, "e:/test.jpg", ccb, 0)23 24 dll.sio_close(port)
新聞熱點
疑難解答