Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 22:59 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : XModem Send.

Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 02:26am 11 Nov 2019
Copy link to clipboard 
Print this post

On the MM+,

Can XModem Send, file$ be incorporated in code & a file transferred while the code is running (or paused).

Can't seem to see much mention of it, just what's on page 73 of the Version 5.4 manual I'm looking at.

Second to that, has anyone heard of an xmodem client that can sit running on a PC waiting for a file to arrive.

Would assume the filename would be set a this client end as I'm aware that XModem transfers require the filename to be specified at both ends.


Thanks

Phil.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 04:42am 11 Nov 2019
Copy link to clipboard 
Print this post

XMODEM is supposed to time out if nothing is received so waiting for a file to start for more than a few seconds is not standard.
Rather than XMODEM, I use normal PRINT with a simple checksum for each line. I use the same checksum as XMODEM.

Coupled with the line numbering system, you will have the same  error checking as xmodem but easier to implement. You could use DOS MMBasic on the PC end.


PS, Hope you are safe from the fires up there.

Jim
VK7JH
MMedit   MMBasic Help
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1584
Posted: 07:14am 11 Nov 2019
Copy link to clipboard 
Print this post

There is an XMODEM CRC routine in the library but if you are not going to use the XMODEM protocol you could just as easily use the MODBUS CRC with TassyJim's suggested method. I know you have both been involved with that for the MODBUS energy meter. It is also in the library courtesy of TassyJim.

Bill
Keep safe. Live long and prosper.
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 08:51pm 11 Nov 2019
Copy link to clipboard 
Print this post

I suppose ultimately what I'm looking for is a solution to move a log file to a PC routinely.

Maybe this is a situation where a rPi could be the solution.
I'd assume that MMbasic could run it's code as normal there and periodically the underlying OS could handle the transfer of logfiles to a SAMBA share.

At present my logfiles are written at 15 minute intervals, so would just need a Crone job to copy them routinely.

Phil.
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 514
Posted: 07:46pm 12 Nov 2019
Copy link to clipboard 
Print this post

You could have a script/bat reading com port and before the xmodem is to send the
 file have mmbasic send "sending" then the script/bat would let xmodem do its part
 and  then go back to waiting for "sending".
Edited 2019-11-13 05:48 by Quazee137
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1584
Posted: 12:26am 13 Nov 2019
Copy link to clipboard 
Print this post

I think a combination of TassyJim's and Quazee137's suggestions would be easy to implement:

Use MMBasic DOS to monitor a comms port on the PC, wait til the Micromite transmits a message that says "I'm about to send a file", then do the transfer as TassyJim described. Strip off the line numbers and CRCs, reassemble the file and save it on the PC.

Bill
Keep safe. Live long and prosper.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 05:10am 13 Nov 2019
Copy link to clipboard 
Print this post

If you have a RPi running 24/7 anyway, you could also run a bash script every 15 minutes to quiz the 'mite and get the current data before it gets logged.

The bash script then saves the data to a log file with the current date.
That is how I log my internet data usage by reading my modem stats page and scraping it for the data.

I then run a Windows program to display the saved data by retrieving it with ftp from the RPi

Jim
VK7JH
MMedit   MMBasic Help
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 07:36pm 13 Nov 2019
Copy link to clipboard 
Print this post

  TassyJim said  If you have a RPi running 24/7 anyway, you could also run a bash script every 15 minutes to quiz the 'mite and get the current data before it gets logged.


You've lost me a bit there Jim.

I was thinking along the lines on have the log files sitting in a Samba share so they'd be visible to the Win PC's.

In that case the transfer could then be initiated from the Win end periodically to grab the entire logfile.

About 5 Meg each at this point.

Other thing I don't know at this point is how the pI version of MMbasic treats the SD card.

The OS owns it basically, so is there a storage_emulated type of path similar to on Android phones?

Phil
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 514
Posted: 09:34am 19 Nov 2019
Copy link to clipboard 
Print this post

Though I'd put a few things I've been playing here so others can play too.

getlog.sh

#!/bin/bash
# to get data from mite can use any of mites com ports
# exits when it gets and EOF
# usage
# /bin/bash getlog.sh filename com baud
#  !!! caution !!! raw no error checking
# ex /bin/bash getlog.sh mydata.log USB2 38400

stty -F /dev/tty$2 $3
echo "Getting $1 from Mite on tty$2 at $3 baud"

while read line; do
    if [ "$line" != "EOF" ]; then
         echo "$line" >> $1
    else
         break
    fi
done < /dev/tty$2



getlog2.sh

#!/bin/bash
# test reading file from mite to a log file
# can be a one shot read "EOF" or on going and ^C to break out.
# !!! caution !!! raw no error checking
#  mostly playing with things that can be done.
#
# /bin/bash getlog2.sh com baud
#log file name is year+month+day+hour+minute
# ex  /bin/bash getlog2.sh USB2 38400

file=$(date +"%Y%m%d.%H%M").log

echo saving to $file from $1 at $2 baud

stty -F /dev/tty$1 $2
while read line; do
    if [ "$line" != "EOF" ]; then
         echo "$line" >> $file
    else
         break
    fi
done < /dev/tty$1

# here you can do error checking and then send a file copy anywhere.



xrecv.sh

#!/bin/bash
# to get a program from mite that coud be running
# need to make sure not to have a connection to consule
# as this acts as you would in saving a program.
# while in file manager (nemo) in work folder I open a term
# and type in the following
# /bin/bash xrecv.sh file2save port  (ttyACMx ttyUSBx)
# this is raw and experimental
# ex /bin/bash xrecv.sh mymmbasic.bas ttyUSB4

DEV=/dev/$2

echo $'\cc' "xmodem s" > $DEV  # get control then xmodem s
sleep 2                        # wait a bit
rx $1 > $DEV < $DEV            # receive the file viva xmodem
sleep 2
echo "run" $'\n' > $DEV        # go back to runnig pgm in mite
sleep 2
tr < $1 -d '\000' > "tmp"      # clean up any trailing nuls
mv tmp $1                      # save tmp file to named file



xsend.sh

#!/bin/bash
# to load a program into a mite
# need to make sure not to have a connection to consule
# as this acts as you would in loading a program.
# while in file manager at working folder (nemo) I open a term
# and type in the following
# /bin/bash xsend.sh file2send port (ttyACMx ttyUSBx)
# this is raw and experimental
#ex /bin/bash xsend.sh testing.bas ttyAMC2

DEV=/dev/$2
echo $'\cc' "xmodem r" > $DEV  #stop running pgm then issue xmodem r
sleep 2                        #wait a bit
sx $1 > $DEV < $DEV            #send file viva xmodem
sleep 2                        #wait a bit
echo "run" $'\n' > $DEV        #run the uploaded pgm



and here I just started looking at all the tools to play with

fun.sh

#!/bin/bash
#this isn't compleat just started playing with bits found viva google.
#reminds me of some old dos batch files I did.
#even has that look LOL
#warning whiptail can drive you nuts in how it handles the in/out of things

foobar=$(whiptail --inputbox "Enter some text" 10 30 3>&1 1>&2 2>&3)

echo $foobar press enter
read $key

read usblink < <(
   declare -a array=()
   while read p dsc;do
       array+=($p "$dsc")
     done < <(ls -1 /dev/ttyUSB*)
   whiptail --menu 'Select USB device' 20 25 12 "${array[@]}" 2>&1 >/dev/tty
)

echo using $usblink
declare -a array=( 300 "" 2400 "" 4800 "" 9600 "" 19200 "" 38400 "" 57600 "" 115200 "")
usbbaud=$(whiptail --menu 'Select Baud' 20 40 12 "${array[@]}" 3>&1 1>&2 2>&3)

echo $usbbaud at array going to next
read $key

usbbaud=$(whiptail --menu 'Select Baud' 20 50 12  150 "" 2400 "" 4800 "" 9600 "" 19200 "" 38400 "" 57600 "" 115200 "" 3>&1 1>&2 2>&3)
echo using $usblink at $usbbaud on to radiolist
read $key

whiptailout=$(whiptail --title "Comm setup" --radiolist  "Choose your baudrate" 20 35 8 2400 "" off 4800 "" off 9600 "" off 19200 "" off 38400 "" on 57600 "" off 115200 "" off 3>&1 1>&2 2>&3)

echo using $usblink at $whiptailout



these are just a few of the musings I tinker with when taking a break from board work.

main thing on back burner is to have a gui menu for flashing,
uploading and downloading code to mites.

I made a bat tool years ago that did my 8741/42/48/49. Using with just a few key strokes to select tools in a 4 by 3 menu boxie looking thing. but it saved me a
lot of time no need to remember the setup for each to use and when programing.

here's hoping others can have FUN TOO

Quazee
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024