开发者

How to handle incoming control characters in a custom terminal?

开发者 https://www.devze.com 2023-04-08 04:48 出处:网络
For my project I needed to create a custom terminal-like window and connect to a Cisco router through console port. So I inherited a TextBox and created a custom control in WPF. And I thought it would

For my project I needed to create a custom terminal-like window and connect to a Cisco router through console port. So I inherited a TextBox and created a custom control in WPF. And I thought it would be enough; just to add some code to implement extra features I wanted. I'm sending one character at a time and wait for responses. But then I saw that my custom terminal does not handle special characters, those basic like \n sure are recognized but all the others not. I have written responses to a text file and I see i got quite a lot of those special ones but I don't know how should I react. Maybe someone knows or have found some links with info about how to react for a specific control character? I have only found what characters are send here , but nothing else about it. I understand that for a "BS" I will delete one character before carriage but what should I do when I get "ACK" or "DC1" ? Maybe I开发者_开发技巧 should just skip them ? Any ideas?


Edit: Apart from sending one character at a time I'll get response only when I send enter or characters like ? or TAB. Then when I receive a response it's mixed with special chars to format the text like in 80x25 terminal window. And I would like just to display it like it wants, but that means I need to know how to react when I get special chars I don't need to display them, just to format normal text based on the special ones I'm also receiving. When I get BS i need to clear the character before carriage, when I get DEL I need to clear the character after carriage. And I would like to know what I need to do when I'm getting other special chars. I know I can do it the hard way and just send those to a working terminal and see what it will do but it will take a while so I wonder if someone maybe knows the answer.


Ok, I played the hard way with terminal and now I know that the only special character I need to handle is BS (of course I only tried this with Cisco routers but I just need to work on them), the only problem is that you need to create your own code to get it work and move caret on the right place based on the BS count. And better create your own variable to store caret index because TextBox CaretIndex just didn't want to work as I expected. The rest of special characters can be, as far as I know, omitted. And it works great as I wanted.

0

精彩评论

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

关注公众号