Python Forum
How to stop Xmodem after bin file transfer was finished
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to stop Xmodem after bin file transfer was finished
#1
hello freinds,


I am sending a BIN file successfully to my energy meter through serial port using the code in the bottom. My problem is that Xmodem doesn't stop after all 128 blocks where sent and i have no idea how to break from it and communicate again with my meter.

Please your kind help.
def sendFile():
    fileSize = os.path.getsize('104_new.BIN')
    total = math.ceil(fileSize /128) 
    ser= serialPort.serialport
    ser.flushInput()
    print (ser)

    def getc(size, timeout=0):
        gbytes = ser.read(1)
        #sleep(0.008)
        print(f'Read Byte: {gbytes}')
        return gbytes or None


    def putc(data, timeout=0):
        pbytes = ser.write(data)
        sleep(0.2)
        print(f'Put Byte: {pbytes}')
        return pbytes or None

    modem =XMODEM(getc,putc)
    f = open('104_new.BIN', "rb")
    modem.send(f,retry=50,callback=total)
    f.close()
    ser.close()
    ser.flushOutput()
    senddata_edit.insert(0,'scan\r')
this is the error code i get:

Error:
send error: expected ACK; got None Exception in thread Thread-2: Traceback (most recent call last): File "C:\Users\shay\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 926, in _bootstrap_inner self.run() File "C:\Users\shay\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "C:\PythonTerminal-master\PythonTerminal-master\mainpy2.py", line 211, in sendFile status= modem.send(f,retry=50,timeout=0) File "C:\Users\shay\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xmodem\__init__.py", line 349, in send self.putc(EOT) File "C:\PythonTerminal-master\PythonTerminal-master\mainpy2.py", line 203, in putc pbytes = ser.write(data) File "C:\Users\shay\AppData\Local\Programs\Python\Python37-32\lib\site-packages\serial\serialwin32.py", line 315, in write raise SerialException("WriteFile failed ({!r})".format(ctypes.WinError())) serial.serialutil.SerialException: WriteFile failed (OSError(9, 'The handle is invalid.', None, 6))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  file transfer via python SFTP SCP mg24 3 2,874 Sep-15-2022, 04:20 AM
Last Post: mg24
  Multithreaded file transfer from multiple volumes skoobi 2 1,104 Jul-28-2022, 07:52 AM
Last Post: skoobi
  Process finished with exit code 137 (interrupted by signal 9: SIGKILL) erdemath 2 9,384 Apr-18-2022, 08:40 PM
Last Post: erdemath
  Using .hdf5 files only once they are finished writing pyhill00 7 2,721 Nov-25-2021, 06:01 PM
Last Post: pyhill00
  How to check if a file has finished being written leocsmith 2 7,689 Apr-14-2021, 04:21 PM
Last Post: perfringo
  Progress Indicator for Xmodem 0.4.6 KenHorse 1 1,931 Jan-30-2021, 07:12 PM
Last Post: bowlofred
Question resume file transfer onran 0 1,611 Jan-27-2021, 02:16 PM
Last Post: onran
  Remote File Transfer- Error wonderboy 1 1,651 Jan-06-2021, 11:24 AM
Last Post: wonderboy
  code to read files in folders and transfer the file name, type, date created to excel Divya577 0 1,835 Dec-06-2020, 04:14 PM
Last Post: Divya577
  DNP3 file transfer with python Aussie 0 1,417 Sep-01-2020, 10:45 PM
Last Post: Aussie

Forum Jump:

User Panel Messages

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