开发者

How to detect incoming connections in my modem

开发者 https://www.devze.com 2023-03-01 06:20 出处:网络
I need to detect when someone is connected to my computer. I have an incoming connection enabled, and need to k开发者_JAVA百科now when a user is connected. Preferably from a script in CSharpGenerally,

I need to detect when someone is connected to my computer. I have an incoming connection enabled, and need to k开发者_JAVA百科now when a user is connected. Preferably from a script in CSharp


Generally, regardless of language, the approach is to open a serial port to talk to the modem. For .NET, you might want to refer to System.IO.Ports.SerialPort. The connection parameters (baud rate, data bits, stop bits, parity, flow control) depends on the device in question. Try 57600 or the fastest speed of your serial port, 8 databits, 1 stop bit, no parity and hardware flow control; that's what's typically used.

Hayes compatible modems spend "RING" notifications (plan text) over a serial port when someone is dialling. You'd send an "AT A" to the modem to anwer the call (or the modem may be configured for auto answer). When a connection is established, a "CONNECT XXX" is sent from the modem, where XXX is the connection details. For a summary of Hayes commands, see this Wikipedia link. (It also describes details such as command/data mode that you'll probably need to go into, if you want to program communications over a modem connection.)


Attach a DataReceived event to the serial port you have opened Look at the SerialPort documentation on how to open the port and attach handlers. you need to know the port speed and stop, start bits, parity, etc. Try speed of 9600 (bps), parity.none, no handshaking, 1 stop and start bits... best thing to do is leave everything at the default and just do new SerialPort("COM5") or whatever your com port is so you leave things at their default values.

Keep putting the received data into a buffer and keep scanning that buffer for "RING".

your serial port will literally receive the word "ring" when your modem is ringing. so you've gotta keep scanning for it.

Also, the reason why I say put your data in a buffer is because sometimes it arrives out of sequence. or you might want to do a readLine so it reads till the /r (carriage return) that indicates one complete response

0

精彩评论

暂无评论...
验证码 换一张
取 消