LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-26-2012, 10:37 PM   #1
bob800
LQ Newbie
 
Registered: Dec 2012
Posts: 4

Rep: Reputation: Disabled
Serial script in cygwin


Hello,

I've built an EEPROM programmer circuit with an Arduino microcontroller as described here: http://z80dave.blogspot.com/2011/09/...er-part-2.html. The specifics are not important, but I need a script which will accomplish the following things:

1) open a file (format is not important) containing the data in hexadecimal to be transferred
2) send 64 bytes of data, wait a few seconds, then send another 64 bytes
3) repeat step 2 until all data has been transferred

The website I linked to provides the following script:

Quote:
eeprom_send.sh
Code:
#!/bin/bash
split -C 64 ${1} ${1}.part.
for part in `ls ${1}.part.*`
do
 cat ${part} >> ${2}
 sleep 1
done
rm -f ${1}.part.*
To use it type:
Code:
./eeprom_send.sh zx81.rom /dev/ttyACM0
Since I run Windows, I tried to execute this script under Cygwin, but I received an error message:
Code:
./eeprom_send.sh: line 4: syntax error near unexpected token `$'do\r''
'/eeprom_send.sh: line 4: `do
Nonetheless, the script does split the initial file into a number of individual 64 byte portions (e.g. zx81.rom.part.'aa,zx81.rom.part.'ab, etc.) No serial data is sent, however. (I did leave the Arduino serial monitor open during the execution, as instructed by the website)

Having no linux experience, I don't really know what to do at this point. Any suggestions would be greatly appreciated!
 
Old 12-27-2012, 06:53 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
\r is a carriage return, in Windows newlines are encoded as \r\n, but in unix (and cygwin (by default)) newlines are just \n. I believe cygwin comes with the dos2unix command which will translate a file's newline encoding. Or, if you are using a text editor that isn't notepad, it can probably do the conversion too.

Also
Code:
for part in `ls ${1}.part.*`
## should be just
for part in "${1}.part."*
## Don't parse ls
 
1 members found this post helpful.
Old 12-27-2012, 11:35 AM   #3
bob800
LQ Newbie
 
Registered: Dec 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks! That solved my initial problem, but now it seems that something's wrong with the serial communication...

When I used "/dev/ttyACM0" to address the serial/COM port (as instructed by the site I linked), the script would execute properly, but nothing was happening on my Arduino. So I did a bit of research and changed "/dev/ttyACM0" to "/dev/ttyS2", which corresponds to the COM3 port on my computer.

Now, the Arduino is blinking as it should, but the EEPROM contents remain unchanged! Before I fiddle around with my Arduino sketch I want to be sure that I'm understanding the way linux manages the COM ports...
  • What does "ACM0" actually mean? How is this different than "S2"?
  • Assuming that everything works correctly, in what form is the data actually sent through the serial port? I have my Arduino sketch setup to receive literal hex characters... 'F', 'D' '2' (this works when I type strings like "AD E2 2A" into the Arduino COM monitor). For the linux script, I typed the hex values into a hex editor and saved the data as a text file... Will the hex values transfer as characters like I'm hoping?
  • The site I'm referencing mentions that the Arduino COM monitor must be open in order for the script to function correctly... however, after I changed ACM0 to S2, the script only functions when the COM monitor is closed (I get a permission denied message). How does the script know what baud rate to use?
Thanks in advance!!

Last edited by bob800; 12-27-2012 at 11:43 AM.
 
Old 12-27-2012, 06:58 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
Quote:
Originally Posted by bob800 View Post
  • Assuming that everything works correctly, in what form is the data actually sent through the serial port? I have my Arduino sketch setup to receive literal hex characters... 'F', 'D' '2' (this works when I type strings like "AD E2 2A" into the Arduino COM monitor). For the linux script, I typed the hex values into a hex editor and saved the data as a text file... Will the hex values transfer as characters like I'm hoping?
The script uses cat, so it does no interpretation of the file contents; it really depends on the hex editor. You can try running xxd or od -t c on the file to see how it's encoded. But if you want to transmit text, why not just use a text editor?

Unfortunately, I don't know anything about serial ports, so I can't help with your other questions.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cygwin issue with bash script jdwilder Other *NIX 7 09-20-2013 06:53 AM
Executable cygwin script in windows sarenace Programming 2 02-12-2012 03:14 AM
Cygwin script compilation problem (f77) wootletootle Linux - General 1 04-19-2011 01:45 PM
Cygwin and space issue in a script. angel115 Programming 4 05-22-2008 08:43 AM
Help with Cygwin shell script? corbintechboy General 1 12-26-2007 11:59 AM


All times are GMT -5. The time now is 04:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration