0

I am trying to send a file via serial port. I tried sending picocom commands in a bash script. However the device writes out a menu of options. When it gets to the file transfer step - it writes out 'C' until a file is sent, after which it does the handshake and proceeds with the transfer. With the script I am not able to send the keystrokes 'C-a' and 'C-s' to get the '*** file:' prompt of picocom. I can do it manually. I even tried a combination of bash and python and pyautogui for the keystrokes, bash echo command to send the hex version of the keystrokes. I even tried sending 'sz' commands through the script and stty. All of these attempts were unsuccessful.

So I switched to python, and tried the xmodem library in python. I am supposed to use ymodem. I thought the 'YMODEM batch transmission session' in the library would do the job. The modem.send command always errors out with the file not being sent.

Read Byte: b'C'
Put Byte: 133
Read Byte: b'C'
send error: expected ACK; got b'C' for block 1
Put Byte: 133
Read Byte: b'C'
send error: expected ACK; got b'C' for block 1

How can i get around this?

Archie
  • 153
  • 9
  • What is the device? Does it expect to use a protocol, or does it just expect a blast of bytes? You can't use YMODEM unless the other end wants YMODEM. How does the device know when you're done? – Tim Roberts May 18 '22 at 19:35
  • In the code I am able to detect when the device is ready for a file transfer. In answer to your question, it expects YMODEM. – Archie May 18 '22 at 19:38
  • You should be able to automate `picocom` correctly using [`expect`](https://man7.org/linux/man-pages/man1/expect.1.html). – larsks May 18 '22 at 19:55
  • I don't understand the 133. "C" is the signal for a YMODEM (or XMODEM-CRC) transfer, but the library should be responding with a header with the file name, which starts 01 00 FF. – Tim Roberts May 18 '22 at 19:56
  • @larsks : I tried 'expect'. But it gets stuck at the point where the keystrokes C-a and C-s need to be sent. – Archie May 18 '22 at 20:14
  • @TimRoberts : the file transfer does not get initiated. I was told that it expected YMODEM. Based on your comment if I were to treat is as XMODEM-CRC how would one proceed? – Archie May 18 '22 at 20:14
  • The library ought to be able to figure that out. Who is sending the 133 (0x85)? That's not a valid start value. – Tim Roberts May 18 '22 at 20:44
  • @TimRoberts I used this as reference: https://python-forum.io/thread-22699.html – Archie May 18 '22 at 21:13
  • OK, in that case `ser.write` returns the number of bytes that were written, which is reasonable. This all looks OK. Are you flushing all of the input before you start? – Tim Roberts May 18 '22 at 21:23
  • @timroberts - I wasn't flushing the input buffer before. I added that in and also changed the modem call from XMODEM to XMODEM1K (in case the expectation was for XMODEM-CRC). But the result is the same. – Archie May 19 '22 at 11:35

1 Answers1

0

Finally ended up using a combination of python and bash - python for serial communication and for parsing the file names of the binaries, and, bash stty and sb commands for transferring the binaries.

Archie
  • 153
  • 9