Python calls Moxa PCOMM Lite to send files through the serial port Ymodem protocol

  • 2020-04-02 13:54:49
  • OfStack

This article illustrates how python calls Moxa PCOMM Lite to send files through the serial port Ymodem protocol. The program is written in python 2.7. The main contents are as follows:

After a long search, Moxa PCOMM Lite was found. Calling pcomm.dll makes it easy to transfer files via Xmodem, Ymodem, Zmodem and other protocols in the serial port without having to duplicate the wheel.

PCOMM Lite 1.6 suitable for Windows 7 system, as a DLL file can use any support call DLL programming languages such as vc + +, VB, Qt, and so on writing applications, here (link: http://xiazai.jb51.net/201408/tools/setup_pcommlite_1.6 (jb51.net). Rar)

Here is the python code on the sending side:


#encoding=utf-8

from ctypes import *

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

port = 2 #  Specify a serial port COM2

dll.sio_open(port)

dll.sio_ioctl(port, 15, 0x00 | 0x03 | 0x00) # 57600,  No check, 8 Bit data bit, 1 A stop bit 

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)

Related articles: