Domanda

I'm trying to transfer a file using the XMODEM protocol I saw the solution provided in this link:Please help in using xmodem protocol but in my case, the file can be sent but not with this contents, please help me...

here is my send code :

import serial
from xmodem import XMODEM
from time import sleep

s = serial.Serial(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N',     stopbits=1, timeout=None, xonxoff=0, rtscts=0)
s.open()

def getc(size, timeout=1):
    return s.read(size)
def putc(data, timeout=1):
    s.write(data)
modem = XMODEM(getc, putc)

f = open('file.txt', 'rb')
stream = f.readlines()
status = modem.send(stream, retry=8)
s.close()
stream.close()

and here is my recv code :

import serial
from xmodem import XMODEM
from time import sleep

s = serial.Serial(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=0, rtscts=0)
s.open()

def getc(size, timeout=1):
    return s.read(size)
def putc(data, timeout=1):
    s.write(data)
modem = XMODEM(getc, putc)

stream = open('file.txt', 'wb')
modem.recv(stream)
s.close()
È stato utile?

Soluzione

I think you just opened the file but never read it in your send routine.

Try this:

f = open('file.txt', 'rb')

stream = f.readlines()

Altri suggerimenti

Try this in send routine:

stream = open('file.txt', 'rb')
status = modem.send(stream, retry=8)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top