0

I want to retrieve/get file from serial port on Windows 7 machine via python2.7. I'm trying to do it with xmodem, but unsuccessfully. In the other words, I have connected the Linux router to my PC with a Serial cable and I want to retrieve a file by serial port. And I like to do it in script if possible.

import serial
from xmodem import XMODEM

def getc(size, timeout=1):
    return port.read(size)

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

modem = XMODEM(getc, putc)

port = "COM5"
ser = serial.Serial(port, 38400)
x = ser.write('echo "d" >> /tmp/d')


stream = open('/tmp/d', 'wb')
modem.recv(stream)

ser.close()

Where have I made a mistake?

I´m new in Python..

Exception is:

    Traceback (most recent call last):
  File "C:/Users/tester/Desktop/ITSP/conn_com.py", line 18, in <module>
    stream = open('/tmp/d', 'wb')
IOError: [Errno 2] No such file or directory: '/tmp/d'
Carlos E. Ferro
  • 930
  • 10
  • 21
tester125
  • 21
  • 7
  • Can you clarify - are you running this script on the windows side or the linux side? On windows - /tmp/d may not be a valid path. – Danny Staple Aug 17 '16 at 11:50
  • He's running on windows (see source file name in traceback), so indeed, `/tmp/d` isn't a valid path. – spectras Aug 17 '16 at 11:50
  • The "echo" is putting stuff into a file on the linux end (presumably running on a shell there). The other bit looks like it's opening a local file at the windows end to write to - so should be the name for that on the windows box. There also more up there that wont work - the putc/getc definitions may need to use ser, not port to work. – Danny Staple Aug 17 '16 at 11:53
  • 1. On the windows side, I need to receive file /tmp/d from serial console connected to linux – tester125 Aug 17 '16 at 11:56
  • I want to receive as I wrote the file : /tmp/d from linux via serial to windows – tester125 Aug 17 '16 at 12:11

0 Answers0