惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
C
Cyber Attacks, Cyber Crime and Cyber Security
A
Arctic Wolf
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Troy Hunt's Blog
小众软件
小众软件
L
LangChain Blog
Schneier on Security
Schneier on Security
D
DataBreaches.Net
爱范儿
爱范儿
P
Proofpoint News Feed
博客园 - 聂微东
M
MIT News - Artificial intelligence
Hacker News: Ask HN
Hacker News: Ask HN
T
Tailwind CSS Blog
Vercel News
Vercel News
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
Jina AI
Jina AI
阮一峰的网络日志
阮一峰的网络日志
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
月光博客
月光博客
Spread Privacy
Spread Privacy
C
Cisco Blogs
S
Securelist
量子位
S
Security @ Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tenable Blog
WordPress大学
WordPress大学
T
The Exploit Database - CXSecurity.com
宝玉的分享
宝玉的分享
C
Cybersecurity and Infrastructure Security Agency CISA
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
MongoDB | Blog
MongoDB | Blog
C
CERT Recently Published Vulnerability Notes
Help Net Security
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
B
Blog RSS Feed
博客园_首页
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org

博客园 - BigRain

小学生学习汉字,汉字抓取 c# regex regextools cache 访问频率的思考 python 百度cpc点击 20130118SQL记录 PPT辅助工具 检查外链的方法 webService启用cookie的另一种方法 百度调价HttpWebRequest 装饰者模式 第一个android程序闪亮登场 SQL 的一些批量插入和修改 职责链模式的运用 State Pattern 程序人生 利用枚举进行状态的设计 singleton模式 在软件开发中的运用 我对当前项目的一些看法 闲话闲说——关于异常
SerialPort实现modem的来电显示
BigRain · 2009-01-11 · via 博客园 - BigRain

一个朋友接了个case,但是却临时有事要出差,所以就把部分的功能叫我来做。以前一直注重于web编程,对于串口编程还是比较陌生的,还好网上的文章不少。当然比较好的文章,有直接帮助的文章还是要数cnblogs里面的文章。把这写到博客里便于以后自己查阅,希望也能够帮到需要帮助的人。
这里主要是讲用serailPort来实现modem的来电显示。
来电显示要依赖于具体的modem,不同的modem,可能AT指令不一样,所以需要定义一个接口,将应用程序与硬件的耦合进行解耦。

Code
这个接口定义了open,close方法,还有是否支持AT指令,是否支持来电显示,还有一个响铃事件。RingEventArgs里面包含了来电的电话号码。
在写这个IModem的实现类时,使用的是笔记本的modem,也不知道是什么型号的,就直接用modem来命名。

Code

上面就是端口的配置,不同的modem可能配置不同,需要根据实际的modem进行设置。

Code
这是一些方法和属性的实现。需要注意的是在发出指令后,最好能将线程堵塞一段时间,以保证有硬件足够的时间来响应,保证能够接收到完整的回复信息。这里的System.Threading.Thread.Sleep(500);就是这个目的。

Code
Ring响铃事件实际上是根据DataReceived接收到的数据进行处理,比如判断是否是来电,截取来电的号码,然后事件冒泡,触发Ring事件。不同的modem返回回来的值肯能是不一样的。上面的正则表达是可能需要再次更改。(网上查到的是 = 号的左右有空格,可是我调试的那个modem却没有)

SerialPort 是.net 2.0才出现的。如果是.net 1.1的话可能需要使用MSCOMM