today I came across something that actually scared me when it happened.
I was reading out a file as an Byte-Array and printed each byte out converted as a char like the following:
byte[] bytes = System.IO.File.ReadAllBytes(fileName);
foreach(byte bt in bytes)
{
Console.Write((char)bt + " ");
}
The thing is now, that printing the converted values out to Console actually made a sound in my headset and my general audio-output..
When I then clicked into the console to stop the execution, after a few seconds there was a Windows-Notification-Sound like when you get an update or something like that.
My question now is why this is happening?
Also note that I tested the File.ReadAllBytes using a mp4-file first and then with a .zip. With a plain .txt-file it doesnt seem to work.
Also I am using Windows 10.
Thanks to the comments I was able to figure out that a beeping-character was actually called out, which caused Windows 10 to do basically infinite beeping-sounds.
I checked for the Hex-Value of 0x07 now before emitting the sound, and it turned out that, after setting a breakpoint, it actually is in the byte-array and when printed it made the sound.
Thanks everyone, I am not cursed after all ;) :)
PS:
I used the german Wiki-Page to get the hex-value:
https://de.wikipedia.org/wiki/Steuerzeichen
On the English one I couldnt find it
Related
I'm currently running a small loop in g-code that has to wait for a common variable to change values. With Program Buffering ON, my g-code program does not see changes to the variables!
What is the best way to turn Program Buffering OFF while I am in this g-code loop?
If I manually set Program Buffering (NC Optional Parameter Bit No.2 Bit 7 to "DOES NOT". Then my loop behaves appropriately and the controller properly checks the value of the common variable each loop.
NLOOP G04 F1
IF[VC890 EQ 0] GOTO NRTS
GOTO NLOOP
NRTS RTS
Very straight forward loop. Maybe it needs to be more complex.
Perhaps if it was longer the buffer wouldn't matter?
I expect my customer's will want Program Buffering turned on.
Can I turn it off temporarily with the THINC API?
Because if it works, this would be great:
public void SetNCOptionalParameterBit(
int intBitIndex,
int intBitNo,
OnOffStateEnum enValue);
If this function will let me set param bit no 2 bit 7 on and off then this would probably be a valid work around.
Okuma.CMDATAPI.DataAPI.COptionalParameter myCOPtionalParameter;
myCOptionalParameter = new Okuma.CMDATAPI.DataAPI.COptionalParameter();
myCOPtionalParameter.SetNCOptionalParameterBit(2, 7,
Okuma.CMDATAPI.Enumerations.OnOffStateEnum.On);
What about M331 to prevent read ahead? (I won’t be at a control for a few days to verify usage, I’m holding my newborn and it’s 4am right now but I think it can go either on the line where you read variable on or the line before.)
NLOOP G04 F1 M331 (buffering prohibit)
IF[VC890 EQ 0] GOTO NRTS
GOTO NLOOP
NRTS RTS
The SetNCOptionalParameterBit() function is capable of setting NO. 2, BIT 7.
However, depending on what version of API you have, the THINC API test application might fail to do so. I confirmed there is a bug in the test app for API 1.17.2.0. And it was fixed by the time 1.18.0.0 was released.
So just be aware of that. Even if your machine has an older API such as 1.17.2.0, you should still be able to write code that uses this function successfully. Just ignore the test app results.
The best solution for my scenario was saving the current value of NC Optional Parameter 2 into a common variable, then changing it to Does Not buffer then running my code, then putting it back to whatever it was before.
in Gcode:
VC892 = VOPRB[2] (save current NC Optional Parameter bit 2 value)
VOPRB[2] = [VOPRB[2] OR 128] (bit magic to flip bit 7 to a 1 if its not)
(insert code to be run without buffering)
VOPRB[2] = VC892 (put back saved NC Optional Parameter bit 2 value)
I'm currently working in C# in visual studio 2010. I am working on console applications and was wondering if anyone knew a way to have Console.WriteLines appear on the console individually without key strokes? E.g. text that appears line by line. I've looked around quite a bit and can't seem to find a way to do it without using standard command lines rather than C#.
Thanks in advance.
For each string you want on its own line, write that string to the console.
string a = "hello";
string b = "world";
Console.WriteLine(a);
Console.WriteLine(b);
Try to put
Console.ReadKey()
between your line outputs. This will wait for any key to be pressed after every line.
Example:
Console.Write("Press any key to continue ...");
Console.ReadKey(true);
Console.WriteLine("DONE!")
This will print "Press any key to continue ..." then wait for any keystroke and add "DONE!" to the end of the line.
Thanks to everyone who replied, sorry it look my a long time to get back to this, I've been extremely busy. Sorry that my question was poorly phrased. What I was attempting to do was create an image with console.WriteLine();
I found that the way to do this was with system threading to create a delay between lines.
Ok I'll try and explain the problem although it's going to be a bit hard.
I'm trying to parse some information from a certain page containing coordinates.
and the copy paste give you something like this:
Distance Position
5.8 (77|-2)
6.3 (76|-1)
7.8 (76|6)
9.2 (91|3)
9.5 (79|10)
12.2 (80|13)
15 (82|-14)
15 (81|16)
now the problem that I have is that between the "(" and the number there is an unidentified char, if you press on the right arrow key it won't move but if you press few times then it will move.
I haven't encounter this thing anywhere, and the website is in php if that helps.
also if that helps when I copy paste the information in here the char disappear and I can move freely through the text.
Please help me with this problem since it's causing my software to malfunction since I'm trying to parse the coordinates into an int and because of that char it won't let me, it'll give me a format exception.
While viewing in UTF-8, I see nothing, while changing the encoding to ANSI, I am left with:
5.8 ‎â€(â€â€77‬‬|â€-â€2‬‬)‬‎
6.3 ‎â€(â€â€76‬‬|â€-â€1‬‬)‬‎
7.8 ‎â€(â€â€76‬‬|â€â€6‬‬)‬‎
9.2 ‎â€(â€â€91‬‬|â€â€3‬‬)‬‎
9.5 ‎â€(â€â€79‬‬|â€â€10‬‬)‬‎
12.2 ‎â€(â€â€80‬‬|â€â€13‬‬)‬‎
15 ‎â€(â€â€82‬‬|â€-â€14‬‬)‬‎
15 ‎â€(â€â€81‬‬|â€â€16‬‬)‬‎
You seem to have used the Left-to-right mark (‎â€), and the encoding was swapped once or twice.
You could clean it, because it's from a website. My first guess would be that your browser settings are not correct (wrong encoding set).
You can still try cleaning it.
Code:
Regex rgx = new Regex("[^a-zA-Z0-9_\n %\[\]\.\(\)%&-]");
data = rgx.Replace(data, "");
I've been trying to figure out the mystical realm of MIDI parsing, and I'm having no luck. All I'm trying to do is get the note value (60 = C4, 72 = C5, etc), in order of when they occur.
My code is as follows. All it does is very simply open a file as a byte array and read everything out as hex:
byte[] MIDI = File.ReadAllBytes("TestMIDI.mid");
foreach (var element in MIDI) {
string b = Convert.ToString(element,16);
Debug.WriteLine(b);
}
All TestMIDI.mid contains is one note on C5. Here's a hex dump of it. Using this info, I'm trying to find the simple hex value for Note On (0x9, or just 9 in the dump), but there aren't any. I can find a few 72's, but there are 3, which doesn't make any sense to me (note on, note off, then what?).
This is my first attempt at parsing MIDI as a file and using hex dumps (are they even called that?), so I'm sorry if I'm heading in the complete wrong direction. All I need is to get the note that plays, and in what order. I don't need timing or anything fancy at all. The reason behind this, if it matters - is to then generate new code in a different language to be played out of a speaker, very similar to the beep command on *nix. Because of this, I don't want to use any frameworks that 1) I didn't program, and really didn't learn anything and 2) do far more than what I need, making the framework heavier than the actual code by me.
Accepted answer is not a solution for the problem. It will not work in common case. I'll provide several cases where this code either will not work or will fail. Order of these cases corresponds their probability - most probable cases go first.
False positives. MIDI files contain a lot of data structures where you can find a byte with the value 144. And these structures are not Note On events. For real MIDI files you'll get bunch of "notes" that are not notes but random values within the file.
Channels other than 0. Most of the modern MIDI files contain several track chunks. Each one holds events for the specific MIDI channel (from 0 to 15). 144 (or 90 in hex) represents a Note On event for the channel 0. So you are going to miss a lot of Note On events for other channels.
Running status. MIDI files actively use concept of running status. This technique allows don't store status bytes of consecutive events of the same type. It means that status byte 144 can be written only once for the first Note On event and you will not find it further in the file.
144 is the last byte in a file. MIDI file can end with this value. For example if a custom chunk is the last chunk in the file or track chunk doesn't end with End of Track event (which is corruption according to MIDI file specification but possible scenario in real world). In this case you' ll get IndexOutOfRangeException on MIDI[i+1].
Thus, you should never search for specific value to find some semantic data structure in a MIDI file. You must use one of the .NET libraries available on the Internet. For example, with the DryWetMIDI you can use this code:
IEnumerable<Note> notes = MidiFile.Read(filePath)
.GetNotes();
To do this right, you'll need at least some semblance of a MIDI parser. Searching through 0x9 events is a good start, but 0x9 is also a Note-Off event if the velocity field is 0. 0x9 can also be present inside other events (meta events, MPQN events, delta times, etc), so you'll get false positives. So, you need something that actually knows the MIDI file format to do this accurately.
Look for a library, write your own, or port an open-source one. Mine is in Java if you want to look.
I have tried all sorts of soloutions, such as
http://bloggingabout.net/blogs/rick/archive/2005/05/10/3830.aspx
and
http://www.codeproject.com/KB/GDI-plus/NGif.aspx
but none of them seem to work correctly. NGif was okay, but the resultant gif was corrupt (white pixels on first frame). And I couldn't get Rick van den Bosch's code to work at all. I'd just like some code that I could include, and have a function CreateAnimatedGif that takes a list of images, the delay and whether to loop, and returns an Image (or a string with the filename it's written to).
But no matter what, I can't get anything to work.
http://midimick.com/magicknet/
http://midimick.com/magicknet/magickDoc.html