|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Writing script to control KVM via RS232
Okay Lol,
I can't think where to post it as it deals with hardware and software lol. Here is my request: I want to order a new KVM switch (http://nti1.com/srvsw-usbvst-u.html) and was wondering if I could do the following thing. I want to get two of these number pads to control the KVM via the serial port. I have a spare box, so I was wondering how I could set it up so that buy pressing 1-8 on the left keypad, my left LCD changed to input 1-8 respectivly and the right keypad changed the right LCD. I was thinking by setting up these keypads somehow and sending commands via the serial port to the KVM it could control it. HYCHM, comp and a bit more information: It says it has RS232 (read here) control over it. I want to be able to press say '5' on on of the keypads and have it switch user 1 to CPU5. the other keypad will switch user 2 to say CPU5 or whatever. I was wondering of how I could get a script that would listen for keypresses on either keypad and then send a message to the KVM telling it to do something like change outputs or whaever. Hope anyone can help me here. computer |
|
#2
|
||||
|
||||
|
Hmm this is really hard. I cant find an answer anywhere
![]() Perhaps a perl script would work? |
|
#3
|
|||
|
|||
|
Did you try firing up MiniCom on your serial port, setup 9600,8n1 and simply typing "CA"?
Also test the other baud rates told and also 7e1 with all of them. 7e1 is a common setting too. (i.e. 7bit, even parity, one stop bit) Oh, a Windows user, ... ![]() - "HyperTerm" if this still comes with your version... Use "direct connection", not a modem device. hth, M.
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#4
|
||||
|
||||
|
Well I don't acutally have it yet. I dont want to spend yodels if I cant get a keypad like this working.
The other problem, is that with two sets of keys for each number, would they mix? Perhaps you could remap one set to letters and the other to other letters and get it to work by running something sensing the keypresses. I could put windows or linux on this box so it doesn't matter too much on the OS side. HTH, computer |
|
#5
|
|||
|
|||
|
To be honest, the OS should not matter at all. I just had to take the chance for a windows rant
![]() It won't work like simulating a keyboard though. But similar: RS232 as such is a very simple protocol. Three wire is minimum (rx, tx, gnd = receive, send, ground) but usually you use 5 (+2 for hardware handshake). RS232 is not using the usual TTL levels (0V = binary "0" and 5V = binary "1") but +/-12V. Handshaking is taken care of by your OS and you only need to tell it *how* to use the port.Hardware handshake is usually done using RTS/CTS ("Request to send", "Clear to send"), i.e. one of the wires will be raised to +12V so the other end knows it is allowed to send now. It will send and then raise the other to let the recipient know it has finished sending. The line itself sends 7 or 8 bits at once with one, 1.5 (no idea how this works) or two stop bits (separators) and even, odd or no parity. Modems eg. usually use 115.200 baud (because they can compress data they need a line to your PC faster than to the other modem). 8bits, no parity. From here it is only raw data. Using a modem you send "ATDT <phone number>\n" and receive a "CONNECT\n" or "BUSY\n". I once wrote a program to remote control a sony camera, they did use a binary protocol. But as simple as: 0x01 0x?? = move left ?? units 0x02 0x?? = move right ?? units ... With the device responding 0x80 for OK and 0xFF for failure. Long talk, short conclusion: If they offer a "RS232 remote control feature" and with the stuff from above, it should be trivial to setup a remote control feature in any OS. Maybe you have to pre-program it with a standard keyboard or directly on the device, but once done you can remote-control at least the preconfigured settings. I did not read the full docs of this KVM, but looks like a quite professional piece of hardware The more professional it is, the more documentation you get from the manufacturer and on the 'net. (btw, did you google it already?)You are a php freak, right? In linux it works eg. like this: - Assuming you have setup the OS with the right baudrate and bits already done someway similar to "/sbin/setserial /dev/ttyS0 crtscts 9600,n81" Code:
<?
$cmd=$_GET['cmd']; // eg. from a form
$handle=open("/dev/ttyS0"); // COM1:
fwrite($handle, $cmd);
/* The following 2 lines are only valid if the KVM "answers" your command with "OK." or similar */
$result=fgets($handle); // read a line
if ($result!="OK") die("The command failed with message: $result");
fclose($handle);
?>
Try to get the technical docs first (the protocol used, I could not spot them on first glance). Once you have them, I can tell you if it really is as simple as I am expecting ![]() Not sure if the whole discussion is interesting to the forums here. You can PM or eMail me anytime if you want. I have done quite some projects already involving RS232 on windows as well as linux. And I can also pass you some Delphi or C code for Windows. ...M |
|
#6
|
|||
|
|||
|
Quote:
Maybe we should move this to one of our new Hardware forums? |
|
#7
|
||||
|
||||
|
Perhaps I am not sure.
I don't acutally have the KVM yet, as it was an idea. I really want to get some other hardware first but I was interested in looking into this. I could get one keypad and work out a way of deciding between the two monitors etc to switch. The only thing is how can I get the remote control program to work? I would want it to work without me doing anything on that computer (ie, switching the KVM to the control PC, then changing the KVM as that is pointless). I think keeping this open on the forum to some extent is a good idea. HTH and I'm not too much of a spoon feed wanting newbie lol ![]() computer |
|
#8
|
|||
|
|||
|
Did you see that I posted two messages?
![]() n8, M. |
|
#9
|
||||
|
||||
|
ya but your PHP will need a form. I kinda need it to be via a keypad only. perhaps a form where I enter something and press enter and it goes and completes it and returns me back to the form.
that way I could do: 1 + 5 + Enter switch LCD1 to CPU5 perhaps I don't know lol ![]() computer |
|
#10
|
|||
|
|||
|
Another example: Linux shell, using a textmode menu that can be controlled with a keypad connected to this machine:
Code:
#!/bin/sh
setserial ... (see man page)
while true; do
dialog --menu 80 25 19 "Please choose console" A "All" 1 "First" 2 "Second" 3 "Third" 2>/tmp/answer
if [ $? -ne 0 ]; then
# cancel pressed
exit;
fi
RESULT=`cat /tmp/answer`
case "$RESULT" in
A) expect "" CA OK </dev/ttyS0 > /dev/ttyS0
;;
1) expect "" C1 OK </dev/ttyS0 > /dev/ttyS0
;;
..... Add all others here too
esac
done
I haven't done much shellcode the last months, and this code is right from my mind. Probably contains some errors. ![]() ...Regard it an example HOW simple it is in linux... ![]() hth, M. |
![]() |
| Viewing: Dev Shed Forums > Other > Dev Shed Lounge > Writing script to control KVM via RS232 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|