Python Forum
File transfer with xmodem CRC (1024) checksum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File transfer with xmodem CRC (1024) checksum
#3
Dear Larz60+,

tahnks for your quick and important suggestion.
Now, file transfer issue has been completely solved.

As I posted before, debuginfo suggested that sleeping time is changed to 1 s while processing.
Thus finally, sleep(0.001) was modified to sleep(1) in the putc definition section.
The modified code is as follows:
import serial
import time

from xmodem import XMODEM1k, NAK
from time import sleep

def readUntil(char = None):
    def serialPortReader():
        while True:
            tmp = port.read(1)
            if not tmp or (char and char == tmp):
                break
            yield tmp
    return ''.join(serialPortReader())
        
def getc(size, timeout=1):
    return port.read(size)

def putc(data, timeout=1):
    port.write(data)
    sleep(1)

port = serial.Serial(port='/dev/ttyUSB0',parity=serial.PARITY_NONE,bytesize=serial.EIGHTBITS,stopbits=serial.STOPBITS_ONE,timeout=0,xonxoff=0,rtscts=0,dsrdtr=0,baudrate=115200)

port.write(">\r\n")
time.sleep(2)
port.write("dat\r\n")
time.sleep(1)
readUntil(NAK)
buffer = open('data', 'wb')
XMODEM1k(getc, putc).recv(buffer,crc_mode = 1)
readUntil()
port.write("end\r\n")
port.close()
And let me answer your questions.
1) xmodem version
The version of xmodem is 0.4.5 which was downloaded from:
https://pypi.org/project/xmodem/
I guess it suppose to be the latest version.

2) Reason to use python2.7
As you may already notice, I have just started to use python.
Python2.7 seems to be pre-installed version for both RaspberryPi and Fedora OS which I usually use.
Thus I recognized that python2.x series is major stream instead of python3.x series.

3) Error traceback
I posted debuginfo which was created by Logger module
instead of standard output on a terminal just in order to provide details including system information.
Now, the problem was sloved but I will attach verbatim error traceback in my next new post.

Again, I would appreciate your kind support.

Best regards.
Reply


Messages In This Thread
[Solved] RE: File transfer with xmodem CRC (1024) checksum - by Jhonbovi - Nov-08-2018, 08:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  File Transfer deezy 5 13,940 Feb-25-2019, 02:41 PM
Last Post: Jaylord
  file transfer with sockets sinister88 1 6,480 Nov-11-2017, 03:29 PM
Last Post: heiner55
  Pickle a file over a socket in 1024 segments HybridAK 7 12,995 Aug-08-2017, 06:54 AM
Last Post: HybridAK

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020