11

I'm trying to send files over a COM port, but failed every time.

First, I configure a serial on each machine like this:

MODE COMx:115200,N,8

where x is the COM port number.

After this I'm trying to do:

COPY file.zip COM1: /B

and the reverse on the receiving PC.

In most cases I've gotten a broken archive. But last tries gave me nothing at all - first PC says that the file was sent, but the second is just waiting for data. Is there somebody who knows how to solve this?

Martin Valgur
  • 5,793
  • 1
  • 33
  • 45
Alex
  • 136
  • 1
  • 1
  • 9
  • Has this ever worked using this serial cable? Are you sure that you have a properly configured serial cable? – lit Apr 06 '16 at 12:27
  • Cable works well, checked by sending with c# SerialPort class. And yes - i did this before - file was transfered well, but this works only with text files. Maybe binary copy flag will help with other files. – Alex Apr 06 '16 at 12:49
  • Did you send non-text through the C## exercise? Of course, if the binary data includes a Control-Z (0x1A), then it would probably terminate the transfer. – lit Apr 06 '16 at 14:30
  • You didn't mention what command you run on the receiving PC. COPY COM1: file.zip /B does not work. Receiver should enable IRQ on interrupt controller and on USART, receive data by interrupt handler, store them on disk. OS shell does not provide all theese chores. – vitsoft Apr 06 '16 at 15:53

2 Answers2

16

This works for me to send a binary file to an Arduino :

mode COM21 BAUD=115200 PARITY=n DATA=8
copy yourfile.txt \\.\COM21

Notice the \\.\ which is mandatory for port numbers >= 10, and can be used too for port numbers 1-9.

Stephan
  • 53,940
  • 10
  • 58
  • 91
Ben
  • 1,548
  • 1
  • 11
  • 12
  • 1
    How would you copy that file in /home/ directory of COM21? – Sedmaister Jan 04 '19 at 20:55
  • I'm not sure to understand your question because the serial protocol (rs-232) used for COM ports only defines how to send and receive bytes to/from a serial device, it doesn't define anything about a file system (in particular it doesn't define a home directory). Most serial devices, for example a serial mouse or a serial modem don't have any file system. You can find more information about rs-232 here : https://en.wikipedia.org/wiki/RS-232#Sp%C3%A9cification – Ben Jan 04 '19 at 21:26
  • Thanks @Ben, let me clarify my question: Is it possible to transfer files into a linux file system (such as ext2) over COM port? If yes, how would the command look like from windows shell? – Sedmaister Jan 07 '19 at 18:01
  • 5
    The short answer would be no, the RS-232 protocol is very low level : send bytes, receive bytes, without any interpretation. Linux wouldn't even know when is the start and the end of the file transmitted, or its file name. But what you're looking for is probably Kermit ( https://en.wikipedia.org/wiki/Kermit_(protocol) ) or Zmodem. There are softwares that implement it for Windows and for Linux, with this it should be possible to transfer files over a serial line. There's an howto here : https://andym3.wordpress.com/mini-howto-linux-windows-serial-file-transfer/ – Ben Jan 17 '19 at 19:14
  • where does the file arrives on the destination then ? @Ben Windows is telling me the transfer has been successful but I can't find the file on the destination... – Maskim Apr 22 '21 at 07:27
  • 1
    It depends on your destination, the serial protocol just sends the bytes of the file to the COM port. For example you can send a file to a serial mouse, which will not do anything with this information, and will not save it as a file (and you will however see that the transfer was successful because there's no check at all in the protocol). But if you send it to another Windows computer, where a specific software is "listening" to that specific serial port, then you can recover the file and save it where you want. An example of such a software is Kermit : https://kermitproject.org/k95.html – Ben Apr 22 '21 at 07:50
3

You need to specify /B for binary file after the .zip file (or whatever else it is) as well as at the end of the command line. e.g. COPY ABinary.File /B COM1 /B otherwise it will stop at the first non-text ASCII character.

Try using Hyperterminal at the receiving end and Transfer > Capture Text

Martin Valgur
  • 5,793
  • 1
  • 33
  • 45
James
  • 31
  • 1