Any suggestion on the best way to build a serial port script? - scripting

I need to configure daily dozens of devices through serial port. The config is at it follows:
Wait for boot (i.e. a specific line appears).
Enter a sequence of commands.
Do a 'print' to check everything is right.
Move to next device.
It doesn't seem complicated, and I really need to automate it. I'm not an expert programmer, but I find my ways.
What can you suggest me to get started? Where should I look on? In particular, any great API out there that would do the dirty job for me? I'm using Windows, but I could get Linux too if really needed.
The one language that I've studied is C. But I'm open to something new as long as it can be done fast.
Thank you in advance.

That looks like a task for expect:
#!/usr/bin/expect
set timeout 20
spawn "terminal-program"
expect "a specific line"
send "sequence_of_commands"
expect "prompt >"
send "print"
and put that in a bash-loop.

Related

Is it possible to test the CAN loopback mode without using oscilloscope?

I am working on the CAN on LPC1857 microcontroller. This is the first time I am working on the CAN driver.
I am right now testing the loopback mode in CAN. I have successfully transmitted the message. This I know because of the values in the status register. But now I need to verify whether I have received the same message at the receiver end. Since I do not have any oscilloscope with me, I wanted to know whether it is possible to check the output at the receiver end using software. I am using LPCxpresso IDE for the coding purpose. If yes, can you please give me a brief idea about how it is done?
Any help is appreciated.
Thanks,
Pavan.

How to edit telnet form programmatically?

I'm not even sure whether I've framed this question correctly. Let me explain my situation.
I have an Application hosted in a OpenVMS environment which is being accessed via Telnet. I'm in need to programmatically accomplish certain tasks.
So far I could send and receive messages using a C# Telnet Client. I am able to execute tasks by sending commands and receiving responses. But for one task, I have to edit a Form to change some information. The command looks like below
>modify page <page_no>
As soon as I enter the above command, the entire terminal gets loaded with this Form, I have to use page-down to go through the fields, press enter to edit the text and use Ctrl-Z to save it.
I'm not sure how to accomplish this task programmatically.
I'm not familiar with telnet or VxWorks. I'm not sure the above is a feature of Telnet or OpenVMS. Kindly help.
This should be easy to figure out thanks to the clear text of telnet :D It shouldn't matter what platform your target is running. All you have to remember is that special keys like ctrl-z or page down, are just chars in the data stream. Ctrl-z is typically 0x1a, and I am not sure what page down is off the top of my head, but here is how you can figure it out:
Get wireshark http://www.wireshark.org/ and install it if you don't already have it.
Start wireshark up and capture all traffic on your NIC that will carry the connection to the target.
Start a normal telnet session to the target and issue all of the commands (including the page downs and the ctrl-z).
Stop wireshark capture and then filter out everything except telnet communication between you and the target.
Look at the data that was sent to issue the ctrl-z, and page downs.
Put those chars in your telnet stream when you are ready to issue those commands.
Easy.

how to get a physical printer status before printing job is sent?

I have a rather unusual problem. I am using xpdfprint binary for the print job from my application. But if the user has a "directly print to the printer" setting enabled and by mistake if the printer is not available (power failure or cord not plugged in) then the application hangs. It seems to be a standard behaviour since in my machine other windows applications also behave the same way. Problem is, in this case the printer timeout is not happening, neither it returns an error. It is waiting on the synchronous call to finish the printing. Is there anyway I can handle this situation? I am forced to find a solution because of a demanding customer. If by some means I get the physical printer status before the printing job is sent, I could solve this problem to an extent. Mine is a windows application and the coding is largely done in C#. If anybody has a win32 sample code please share with me.
Thanks in advance for any kind of help.
If the printer isn't connected then don't have a print menu item enabled, with a message.
Then, you just check every so often on the status.
You may find this of interest to check the status:
http://www.codeproject.com/KB/printing/printeroffline.aspx

Socket programming and telnet with VB.net

I'm writing a GUI-based app in VB.net that talks to a LambdaMOO server via telnet, sends commands to display the object hierarchy, then parses the output and creates a visual representation of the object hierarchy.
So my question is: is there some kind of "telnet client" class for .NET to simplify the sending and receiving of data, or do I have to write my own using the socket API?
Does Mono have something like this?
Barring an easy solution, does anyone have a good tutorial they can point to for telnet client programming in VB.net?
Ok, I had a similar issue and ignoring all security complications and the like, wanted to TELNET from a VB initiated connection to a remote device and do stuff. I concur that the whole negotiation process is a hellish thing to do but once you've worked it out it's actually pretty simple to implement. I decided not to stop because I kept reading things that said it couldn't be done when it clearly can be done if you can write and read 1's and 0's into/from a network stream.
The code in the link below will initiate the connection and get you through to actually exchanging clear text information over TELNET. Given the example of sending a username and password combo shows how to read and write to the connection.
Big tips - initially have a nice big textbox or something to trap everything that comes into the buffer (variable returndata). This will help you diagnose problems. Also check on my blog there how to do this without the textbox blinking like a flashing thing. Once you've done all that and you know your script is reliable, trun off any screen updates and it will whizz through rather than take an age.
Apologies for the really dirty code and the crappy website layout.
http://myhead-online.blogspot.com/2009/05/vb-net2008-express-telnet-to-sun.html
The telnet protocol is basically just the usual TCP protocol, with a bunch of optional stuff that you probably won't need to implement. So you'd open a socket and start sending and receiving data with the socket stream interface.
Give it a try with the regular socket API, you'll probably find that it's quite straightforward.
just a suggestion. you may try to program your vb application to execute an existing telnet application in batch mode.
here is the link for your reference. refer to 7.3 Using Plink in batch files and scripts. Hope it helps.
You can grab one of any number of libraries to use. Here's one library:
LINK
For others try googling something along the lines of: library telnet mud .NET
Lastly, there are any number of opensource MUD/MOO/MUSH projects open at any time who are willing the share ideas and looking for people to help with projects.
I had my trials with telnet. You've to use tools like wireshark in conjuntion to figure out what commands needs to be initiated. I did find communicating with my unix box quite a challenge. For one thing you must know your telnet instructions. You might find it difficult to determined the state of the application - whether it is logged in or not innately. You'd have to formulate your own logic for it.
Another thing you'd have to do is parse the bytes returned by telnet into commands or instruction data i.e. you have to know if the bytes received is an instruction or some other thing it is trying to send you. Here is a ref that would come in handy.
First I suggest you start using the wireshark tool and get the communications send to and fro manually as well as via application.
From the LambdaMOO end of things, if you have wizard access or are friends with someone who does, you can have the MOO give you the data over another protocol that you might be able to work with more readily, such as HTTP. All you need is an object on the MOO with a do_login_command() set to handle requests, and then use the listen() builtin to get that object to listen on a given port. As long as a protocol doesn't require anything complex SSL, it's fairly easy to code up on the MOO end. So that might be worthwhile if VB.net has easier handling for HTTP etc.

Changing another Process Locale

From my own "key logger like" process I figured out that another process Locale is wrong (i.e. by sniffing few keys, I figured out that the foreground process Locale should be something while it is set to another). What's the best way to do this?
I'd use setLocale from within that process to change it, and notify the process about this with some form of IPC like:
signals
sockets
pipes
from the process who knows
You didn't specify operating system or anything, but in Linux this is quite hard unless the target process is willing to help (i.e. there's some IPC mechanism available where you can ask the process to do it for you)
What you can do is to attach to the process, like a debugger or strace does, and the call the appropriate system call (like setlocale())
The result on the target process is of course undetermined since it probably doesn't expect to get its locale changed under its feet :)