python调用Moxa PCOMM Lite通过串口Ymodem协议实现发送文件

WBOY
Release: 2016-06-06 11:32:06
Original
2735 people have browsed it

本文实例讲述python调用Moxa PCOMM Lite通过串口Ymodem协议实现发送文件的方法,该程序采用python 2.7编写。主要内容如下:

经过长期搜寻,终于找到了Moxa PCOMM Lite。调用PCOMM.DLL可以非常方便的通过串口的Xmodem、Ymodem、Zmodem等协议传输文件,而无需重复制造轮子。

PCOMM Lite 1.6适用于win7等系统,做为dll文件可以采用任何支持调用dll的编程语言例如VC++、VB、Qt等等编写应用程序,点此本站下载

以下是发送端的python代码:

#encoding=utf-8

from ctypes import *

dll = windll.LoadLibrary("PCOMM.DLL")

port = 2 # 指定串口COM2

dll.sio_open(port)

dll.sio_ioctl(port, 15, 0x00 | 0x03 | 0x00) # 57600, 无校验,8位数据位,1位停止位

def cb(xmitlen, buflen, pbuf, flen):
  print xmitlen, flen,
  print 
  return xmitlen

CALLBACK = WINFUNCTYPE(c_int, c_long, c_int, POINTER(c_char), c_long)

ccb = CALLBACK(cb)

dll.sio_FtYmodemTx(port, "e:\test.jpg", ccb, 0)

dll.sio_close(port)
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template