How to handle incoming control characters in a custom terminal? - c#

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.

Related

C# Get Specific Data from Text

I am still new to C# and its formatting in general, so I may have a hard time explaining what I'm looking for. But is there a method to read in a text file (.txt) and only pull certain lines of data, specifically when the line has more than 8 "," (commas) in the line, and ignore the rest?
Trying to capture data on a control box, and the data it sends out in debug has everything from motor position, velocity, axis, and more. But it also includes data not needed to graph into excel such as extra comments like Motor has stopped, Acknowledge, and so on. Those lines tend to only have 1-3 commas, whereas the data I'd like to extract for analysis is covered in 8+ commas for all the details given.
Thanks for any tips/advice on this or being able to point me in the right directions with the terminology I'm lacking which does what I'm looking for. I've figured out the File.ReadAllText function so far, and I think that's a good start. But not really sure which terms or functions are used to try to express the rest of what I'm needing.

What is the difference between Prompt() and SpeakAsync(String)

I have read the documentation but fail to understand what the underlying difference is between using:
Prompt prompt = new Prompt("What are you doing?");
speaker.SpeakAsync(prompt);
VS:
speaker.SpeakAsync("What are you doing?");
The reason I am asking this is because I am trying to get a response from the user and it's not just a statement, I am expecting a specific answer to a question that the speaker asks.
For example, I want speaker to say "What are you doing?" and if the user speaks into the microphone, "I'm trying to read, leave me alone.", then the voice recognition should stay quiet.
I am trying to determine how to best handle Question/Answer-based scenarios. How should I handle this, when my app is expecting a specific type of answer so that it can act on it.
There's no reason to use Prompt if it is just a simple string.
But more elaborate phrases can be built with PromptBuilder, switching voice and volume, inserting pauses and audio snippets, using Ssml markup, specifying style and pronunciation, marking paragraphs and sentences. With some further likelihood that you want to preserve that if you repeat the phrase. You'll need to use the Prompt class for that.
A Prompt object can contain plain text, text formatted with markup language, or audio files.
SpeakAsync is of type prompt.
I had to check a tts app I did a while back.

c# clipboard viewer... on firefox the event fires twice

iam trying to use the code posted here
Clipboard event C#
it does work really great, but while testing, i found out that when copying from some application as example firefox, you will get the event running twice, so if you are saving the copied text to a textfile, or writing them to a textbox in the application, the text copied from firefox will appear twice ?
anybody can help me with this problem ?
thanks a lot
Store the last input, and if the new input is the same as the last, discard ?
Try it on a "bare" system to ensure that you aren't getting an "echo" somewhere. There should only be one notification. However, if soemthing else alters the clipboard during the event, you can get two. For example, a clipboard-driven text scrubber.
You can also get multiple events if the app doing the copying does it wrong. Such as when apps open/close the clipboard for each data format (they should not, this is a bug if they do). Try copying from plain old Notepad and see if you "hear" the event twice or not.
Do you have any plug-ins runnign within FF? It sounds like you do. Try it on a "bare" system with brand-new FF and nothing else.

Receiving Invalid Data from Serial Port using SerialPort.ReadExisting()

I have written a program in .NET that listens to a particular Serial Port and processes the data that is being received. I wrote a test program using com0com (the Null-modem emulator) and my program was working fine. I even tested it with HyperTerminal and that seemed to work fine too.
However when I interfaced the software with the original device (an output received from a control system), the data received was garbled. It contained special characters. The same device when connected with Hyper Terminal produced the desired output. I changed the baud rates, parity etc but the data received was the same set of garbage characters.
I have used the DataReceived event of the SerialPort component and used the following line of code to capture data:
string data = portRecieve.ReadExisting();
Can somebody tell me where am i missing out? In the current environment, the output from the device is directly connected with a dot matrix printer which prints whatever is received on the port. The printer seems to catch what is being sent but my code couldn't.
If you ever encountered a similar scenario, Please share your findings.
Thanks
How did you set
SerialPort.DiscardNull
SerialPort.Encoding
And maybe show us an example of the special chars you are receiving.
I can think of the following reasons why the data might apperar garbled:
If there is a bad physical connection, you can sometimes just get garbage (rather than nothing at all). Try unplugging and replugging the leads - and check that you have the correct lead (e.g. do you need a nullmodem?). It looks as though you have this covered by checking in HyperTerminal.
If the baud rate, stop bits, parity are not correct - sounds like you have this one covered
You are trying to receive the data as a string. If it is not sent as plain text, or if your encoding is wrong, then it could easily appear garbage-like. Try using a binary receive and examine the raw data that you are receiving. This will tell you whether the data is just wrong or the .net conversion is screwing it up - eliminate the middle man!
It sounds to me like the device is putting the printer into some special graphics mode. If so, there is likely to be escape sequences in the data being sent to the printer, ie. character sequences starying with an escape (27, 0x1B) character.
In this case, you'll have to look at the printer manual to see what the commands do. Alternatively, you might be able to tell the device to use a simple ASCII only printer, rather than a intellifent one.

Windows clipboard CRLF/LF passing wrong for one user

We have a pair of applications. One is written in C# and uses something like:
string s = "alpha\r\nbeta\r\ngamma\r\ndelta";
// Actually there's wrapper code here to make sure this works.
System.Windows.Forms.Clipboard.SetDataObject(s, true);
To put a list of items onto the clipboard. Another application (in WinBatch) then picks up the list using a ClipGet() function. (We use the clipboard functions to give people the option of editing the list in notepad or something, without having to actually cut-and-paste every time.)
In this particular environment, we have many users on one system via Citrix. Many using these pairs of programs.
Just one user is having the problem where the line delimiters in the text are getting switched from CRLF to LF somewhere between the SetDataObject() and the CLipGet(). I could explain this in a mixed Unix/Windows environment, but there is no Unix here. No unix-y utilities anywhere near this system either. Other users on the same server, no problems at all. It's like something in Windows/Citrix is being "helpful" when we really don't want it, but just for this one guy.
Ideas?
Have you tried clearing their profile on Citrix? That seems to be the solution to many many user specific Citrix problems.
Does Environment.NewLine behave differently on Citrix environments? If so, it may give you a good option that works for all users instead of \r\n.

Categories

Resources