Send/receive file through serial using minicom

i have connected with my board through serial interface using minicom and i am running a bash script, which should test ethernet (ping test), USB read/write, RS232 ..

I have managed to test ethernet and USB read/write.
I test ethernet with ping.
I test USB read/write, using dd and verifying the checksum with md5.

But i am stuck with testing RS232. Could you provide me ideas as to how i can do that using minicom session. I want to test that the serial interface is working properly.

Thanks,
srik

---------- Post updated at 06:31 AM ---------- Previous update was at 06:29 AM ----------

One idea i have is to send a file using sz to the host and then check for the files authenticity. but then it wasnot possible without human intervention (since i had to press ok after receving the file in minicom using xmodem protocol)

OK, this doesn't directly answer your question, but why ping test any network connection before trying to use it? That's like checking a car for a trailer hitch before taking it to pick up a gallon of milk at 7-11 - it's completely irrelevant to what you're trying to do. Sure, a positive result tells you the car is there, but it doesn't tell you the car works. And a negative result tells you only that there's no trailer hitch - the car could still be there working just fine to boot.

Networks can be and are configured to block explorations such as pings. Hosts can be and are configured to not respond to pings. Networks can also and often are configured to block SSH or FTP sessions, so even if a ping is successful that's not proof an SSH session will connect.

If you're going to use a network-based service, just use the damn thing. A successful ping prior to trying such a service doesn't mean the service works, and a failed ping doesn't mean it won't.

thanks for the reply. I hope i understood your response properly.

I am not going to use any ethernet based service and the ping test is not intended for that purpose. The idea is to put the system under some kind of stress (ping with a number of packets, sending a number of CAN frames, etc.. ) and at the same the hardware is verified.

Do you have any idea about how i can verify the RS232? i am looking at using sz non interactively, eventhough it is mentioned that it could be used non interactively it is not mentioned how to.

Doesn't the fact that you "connect ... through serial" prove the RS232 to be working? Or am I missing something?

yes it does. but i need to load the rs232 interface in some so that the hardware is tested for maximum load

So you're able to feed a raw script into rs232?

Perhaps you could uuencode or base64 a file and make it part of your script in a here-document.

base64 -d > /tmp/$$ <<"EOF"
YXBwbGljYXRpb24vMWQtaW50ZXJsZWF2ZWQtcGFyaXR5ZmVjCmFwcGxpY2F0aW9uLzNncHAtaW1z
K3htbAphcHBsaWNhdGlvbi9DU1RBZGF0YSt4bWwKYXBwbGljYXRpb24vRURJLUNvbnNlbnQKYXBw
bGljYXRpb24vRURJLVgxMgphcHBsaWNhdGlvbi9FRElGQUNUCmFwcGxpY2F0aW9uL0gyMjQKYXBw
bGljYXRpb24vYWN0aXZlbWVzc2FnZQphcHBsaWNhdGlvbi9hbmRyZXctaW5zZXQJCQkJCQkJCQll
egphcHBsaWNhdGlvbi9hbm5vZGV4CQkJCQkJCQkJCQlhbngKYXBwbGljYXRpb24vYXBwbGVmaWxl
CmFwcGxpY2F0aW9uL2FwcGxpeHdhcmUJCQkJCQkJCQkJYXcKYXBwbGljYXRpb24vYXRvbSt4bWwJ
CQkJCQkJCQkJYXRvbQphcHBsaWNhdGlvbi9hdG9tY2F0K3htbAkJCQkJCQkJCQlhdG9tY2F0CmFw
cGxpY2F0aW9uL2F0b21kZWxldGVkK3htbAphcHBsaWNhdGlvbi9hdG9taWNtYWlsCmFwcGxpY2F0
aW9uL2F0b21zZXJ2K3htbAkJCQkJCQkJCWF0b21zcnYKYXBwbGljYXRpb24vYXRvbXN2Yyt4bWwJ
CQkJCQkJCQkJYXRvbXN2YwphcHBsaWNhdGlvbi9hdXRoLXBvbGljeSt4bWwKYXBwbGljYXRpb24v
EOF

set -- $(md5sum /tmp/$$)
rm -f /tmp/$$

if ! [ "$1" = "0e657476ea6a0024f4adadd1d105b7a4" ]
then
        echo "transfer corrupted"
        exit 1
fi

...except you could make a much bigger chunk. Feed a sufficiently large file into 'base64 < filename', and get the sum with 'md5sum filename'

hi corona, sorry for asking this, but could you explain your code. my scripting skills are limited.
base64 -d > /tmp/$$ <<"EOF" This seems to decode some data and add it to a file and appends and EOF at the end.

  1. Which data does it decode and what does $$ mean?
    set -- $(md5sum /tmp/$$)
  2. what does "set --" do to the checksum calculated?
    if ! [ "$1" = "0e..." ]
  3. $1 is ? (first argument for?)

With my limited scripting skills it is difficult for me to understand in which step a RS232 transfer is taking place

I did ask if you were sending scripts over RS-232... Please confirm or deny.

Right. <<EOF is a 'here document', allowing you to put a document inside a shell script instead of including it as an external file.

I got the contents from base64 < filename , picking /etc/mime.types as a big harmless file. I didn't post it in its entirety to save space.

Nothing important, I just fed it part of /etc/mime.types. The content isn't important, you just wanted a lot of data, right? If you change the data, you have to change the checksum of course...

$$ is the shell's PID, so more or less a convenient "unique" number. If you used the same name all the time you might bump into a pre-existing file or some such when things went wrong.

md5sum prints "checksum filename". set -- a b sets $1 to a, $2 to b. So this sets $1 to the checksum, and $2 to the bit we don't want.

$1 is what set it to with set --

The intent was for you to feed that script into the serial port, assuming the serial port has a shell running in it.

If it doesn't, you might be able to kludge it with bash < /dev/ttyS0 or what have you.

Ok Thanks Corona for explaining the parts of code in detail.

I have opened a minicom session with the target (through RS232) and trying to run the script on the target

OK, so does this script work for you?