LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Minicom Script, Hex, Expect (https://www.linuxquestions.org/questions/linux-networking-3/minicom-script-hex-expect-4175531039/)

JonasWepel 01-14-2015 02:22 PM

Minicom Script, Hex, Expect
 
I'm trying to write a script to run in minicom for communicating across an RS485 connection. So far, I can see the trafic across the connection which is in the 8n1 format at 9600 baud. I'd like my script to read the incoming data and when certain data are seen, send data back across the connection. A sample of the type of script I'm trying to use is as follows:

Code:

expect  {
  "\x10\x03"  send  "\x10\x02\r"
}

I've tried a few other variations of the this script, but essentially as soon as I run my code, the minicom output goes from a clear, patterned, and readable stream, to garbled boxes and characters (Once I enter ctrl-c to end my script, the legible data stream returns). My needs are simple so I thought using expect and send would suffice, but I'm struggling with either the syntax or perhaps the limitations of the software. I'd appreciate any advice on scripting with minicom, if you have any. If you think this is impossible with minicom that would be good to know as well as I can move on to another means of accomplishing my goal (python, C).

ferrari 01-14-2015 06:15 PM

I'm not sure that you can send hex values like that with 'send'

From
Code:

man runscript
Quote:

OVERVIEW OF KEYWORDS
send <string>
<string> is sent to the modem. It is followed by a '\r'. <string> can be:
- regular text, e.g. 'send hello'
- text enclosed in quotes, e.g. 'send "hello world"'

Within <string> the following sequences are recognized:
\n - newline
\r - carriage return
\a - bell
\b - backspace
\c - don't send the default '\r'.
\f - formfeed
\^ - the ^ character
\o - send character o (o is an octal number)

JonasWepel 01-17-2015 03:30 PM

Ignore send for now
 
For now let's ignore the sending of hex values, as I can't get the expect command to function properly. I'm trying something similar to the following:

Code:

expect  {
  "\x10\x03"  print  "TEST\n\r"
}
exit

This still leads to garbled output from minicom as soon as I run my script. "TEST" is never pritned and the neat, legible pattern of numbers turns to random boxes and characters. Is there are better syntax for reading the incoming data stream through the expect command?

ferrari 01-17-2015 04:14 PM

Maybe minicom is getting in the way. Anyway, I wonder if the following might be useful to you

http://en.wikibooks.org/wiki/Serial_...l_Command_Line

veerain 01-17-2015 10:54 PM

Useful link.

I also had this problem but I instead went for python, pyserial and wrote a python script.

JonasWepel 01-19-2015 07:03 PM

Thanks for the feedback, all. Veerian, any chance I could take a look at your Python script?


All times are GMT -5. The time now is 12:44 PM.