|
I realized that at the starting , my code works well. I mean all 16 bytes of data are correct and in correct sequence. But when it performs 2nd operation , only the sequence is changing. The values are correct. I think emptying buffer after each operation would be appropriate. I can use DiscardInBuffer() method but can you suggest me other effective solution if you know ?
|
|
|
|
|
There is a problem here, which is likely to be that you don't really understand serial ports that well.
When a character arrives on a serial port, you will get a DataReceived event - that doesn't mean that 16 bytes are immediately available: serial ports are slow, and it is very likely that the event will be handled when there is only one character actually available. So trying to read 16 bytes every time the event gets signalled is not likely to do exactly what you want...
And if you read the documentation, the DataReceived event handler is never executed on the UI thread - so adding data to controls is a very, very bad idea.
Instead, consider reading the available bytes into the array and appending them, and then checking to see if you have them all. If you do, then your main process thread can work on the data, rather than the DateReceived thread.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I used SerialPort object from toolbox instead of identify in code, it works correctly now. Thanks for your help
|
|
|
|
|
<button id="asss" onclick="getspeack('hello manh tuyen')">noi thu</button>
<script type="text/javascript">
function getspeack(textvoid)
{
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
msg.voice = voices[10]; // Note: some voices don't support altering params
msg.voiceURI = 'native';
msg.volume = 1; // 0 to 1
msg.rate = 1; // 0.1 to 10
msg.pitch = 2; //0 to 2
msg.text = textvoid;
msg.lang = 'en-US';
speechSynthesis.speak(msg);
}
</script>
|
|
|
|
|
And?
What does it do that you didn't expect, or not do that you did?
Remember that we can't see your screen, access your HDD, or read your mind.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
That's JavaScript, not C#. Please take the question to a more appropriate forum.
|
|
|
|
|
That my friend seems more like a JavaScript code, so trying to write the C# code in it won't work at all.
If you really want to write the application, then please, wasting no time at all go to this documentation[^].
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Hi,
I am outputting log style info into a multiline textbox. I have the vertical and horizontal scrollbar property enabled. At runtime when data is added to the multiline textbox, I can see the scrollbars but they cannot be moved.
Do I need to do something more to make them actually work?
Thanks,
Rob
|
|
|
|
|
The scrollbars should work once there is more text in the textbox than it can show, when the application is running and the textbox'Enabled property is set to "true".
A disadvantage will be the speed of adding stuff to the textbox; consider using a listbox once you encounter that problem.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I found that the textbox Enabled property was set to false. I set it to true and now the scrollbars work properly. I just assumed that it was enabled by default. I thought that was true for all controls but you have changed my mind!
Thank you!
|
|
|
|
|
robwm1 wrote: I just assumed that it was enabled by default It is
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I must have changed it at some point. This is my first C# project and I have done a lot of experimentation. Just need to remember to undo any changes I make that don't give the results I am looking for so everything remains in its default state.
I am my own job security...
|
|
|
|
|
Are you using a code-repository like SourceSafe where you can easily undo all changes?
I usually copy the complete project to a RAM-disk for experiments
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
My code is stored within Team Foundation Server so I could roll back if needed. That's a great idea with the ram drive although using disk storage, if you have the space available, might work as well. Either way, I have been making changes as I progress to learn the language and IDE better without making copies. Probably not the best idea but I don't plan to code this way in the long term.
|
|
|
|
|
I have a problem with my script:
Public partial class Form_Process : Form
{
Static Object[ , , ] normW = null;
Private void process(){
for(int i=0; i<3; i++){
normalW[i] = Normali;
}
}
}
Error: Wrong number of indices inside []; expected 3
I hope anyone can help me for my error script above.
I'm sorry for my bad english. Thank you.
modified 9-Jan-15 16:46pm.
|
|
|
|
|
There are a number of problems, including that you never instantiate the array.
First off, why an array? Rather than a Tuple or a List?
Are you actually trying to make an array of three two-dimensional arrays?
Try
Object[,][] normalW = new Object[,][ 3 ] ;
(Untested)
(That ain't working.)
|
|
|
|
|
Yes, i wanna try to use 3 dimensional array, just for learning.
I also used a List. Thank's a lot.
|
|
|
|
|
Is normW the same as normalW? If yes, then you declared it as a 3 dimensional variable.
If you solve it, you'll get the same error on Normali if that is indeed a 2 dimensional variable.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes i'm sorry. Thank you. NormW is same as NormalW. I try to save the Normali[i, j] (2 dimensional) in NormW[z, i, j] (3 dimensional)
|
|
|
|
|
Sample 3-dimensional Array initialization:
int[,,] d3ary = new int[3, 4, 5];
for (int i = 0; i < d3ary.GetUpperBound(0); i++)
{
for (int j = 0; j < d3ary.GetUpperBound(1); j++)
{
for (int k = 0; k < d3ary.GetUpperBound(2); k++)
{
d3ary[i, j, k] =
}
}
}
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
Yes, you're right. I used the code like yours. But i used d3ary.GetLength(0). Is that same with d3ary.GetUpperBound(0)?
|
|
|
|
|
In C#, for all practical purposes, it is legitimate to consider the value returned by 'GetUpperBound to be the same as the value returned by GetLength. Normally in C#: Array.GetLowerBound(#n) will return zero.
It is possible, though unusual, to have Arrays in C# whose lower bounds are not zero; for example: you might inter-operate with Excel and get an Array whose indexes are one-based. Or you can create such strange arrays by using the Array.CreateInstance(Type, Int32[], Int32[]) overload of Array.CreateInstance.
Here's a one-based array of string of length #5:
Array oneBasedArray = Array.CreateInstance(typeof(string), new int[] { 5 }, new int[] { 1 });
oneBasedArray.SetValue("hello", 1); And:
> ? oneBasedArray.GetUpperBound(0)
5
> ? oneBasedArray.GetLength(0)
5
> ? oneBasedArray.GetLowerBound(0)
1 I suggest you engage with non-zero based Arrays as you need to in the course of inter-op with COM, or whatever.
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
Ok, I got the point. So, GetUpperBound and GetLowerBound are more flexible than using GetLength, aren't they?
They're used as we need.
Thank you BillWoodruff.
|
|
|
|
|
If you're going to use GetUpperBound , then your loop condition needs to be <= rather than < .
GetUpperBound returns the last index for the dimension, not the length.
int[,,] d3ary = new int[3, 4, 5];
Console.WriteLine("{0}, {1}, {2}", d3ary.GetUpperBound(0), d3ary.GetUpperBound(1), d3ary.GetUpperBound(2));
Console.WriteLine("{0}, {1}, {2}", d3ary.GetLength(0), d3ary.GetLength(1), d3ary.GetLength(2));
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
When you declare a three dimensional array, you are saying that each row, column and zaxis-whatever-it-is-called is the same size:
object[,,] ar3d = new object[2,3,4]; But that isn't necessarily the case with the code you show - we have no guarantee that each of the 2D arrays loaded into Normali is the same each time. And if we aren't sure, nor is the compiler!
So when you try to assign a new 2D array to a row, it complains because a 3D array is not made up of arrays of references to arrays of references to objects - it is in fact a flat linear space of objects which is interpreted as a 3D array.
Probably, what you are trying to do is construct a jagged array:
object[][,] normW = new object[3][,];
for (int i = 0; i < normW.Length; i++)
{
object[,] normali = MyProcess(i);
normW[i] = normali;
} Where it doesn't matter what the dimensions of the array you generate in your processing are.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|