简体   繁体   English

如何检测调制解调器中的传入连接

[英]How to detect incoming connections in my modem

I need to detect when someone is connected to my computer.我需要检测何时有人连接到我的计算机。 I have an incoming connection enabled, and need to know when a user is connected.我启用了传入连接,并且需要知道用户何时连接。 Preferably from a script in CSharp最好来自 CSharp 中的脚本

Generally, regardless of language, the approach is to open a serial port to talk to the modem.一般来说,不管是什么语言,方法都是打开一个串口和modem对话。 For .NET, you might want to refer to System.IO.Ports.SerialPort .对于 .NET,您可能需要参考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;试试57600或者你的串口最快的速度,8个数据位,1个停止位,无奇偶校验和硬件流控; that's what's typically used.这就是通常使用的。

Hayes compatible modems spend "RING" notifications (plan text) over a serial port when someone is dialling.当有人拨号时,Hayes 兼容调制解调器通过串行端口发送“RING”通知(计划文本)。 You'd send an "AT A" to the modem to anwer the call (or the modem may be configured for auto answer).您将向调制解调器发送“AT A”以应答呼叫(或者调制解调器可能配置为自动应答)。 When a connection is established, a "CONNECT XXX" is sent from the modem, where XXX is the connection details.建立连接后,调制解调器会发送“CONNECT XXX”,其中 XXX 是连接详细信息。 For a summary of Hayes commands, see this Wikipedia link .有关 Hayes 命令的摘要,请参阅此 Wikipedia 链接 (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.) (它还描述了诸如命令/数据模式之类的细节,如果您想通过调制解调器连接编程通信,您可能需要将 go 放入其中。)

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.将 DataReceived 事件附加到您打开的串行端口查看有关如何打开端口和附加处理程序的 SerialPort 文档。 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.您需要知道端口速度和停止、起始位、奇偶校验等。尝试 9600 (bps) 的速度、parity.none、无握手、1 个停止和起始位...最好的办法是将所有内容保留为默认值并且只需执行 new SerialPort("COM5") 或任何您的 com 端口,这样您就可以将其保留为默认值。

Keep putting the received data into a buffer and keep scanning that buffer for "RING".继续将接收到的数据放入缓冲区并继续扫描该缓冲区以查找“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或者你可能想要做一个 readLine 所以它读取到 /r (回车)表示一个完整的响应

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM