|
Have you tried using the DataReceived event from the System.IO.Ports.SerialPort?
|
|
|
|
|
Thanks for the reply.
I am trying that now. But It will create an event when each data received- means for each byte. But I need to act only when 20 bytes are received.
So read the buffer on each event, append it to a user array, and check for the end of packet-- is this the suitable and possible method?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
|
|
|
|
|
MSDN says
"The DataReceived event is not guaranteed to be raised for every byte received. Use the BytesToRead property to determine how much data is left to be read in the buffer."
What does this mean? If the event is not guaranteed how can we get the complete and correct string coming through serial port?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
|
|
|
|
|
I think I have found some clue.
To get a particular number of bytes we can set the receive threshold as ..say 20. Then receive event will be triggered when serial port receives 20bytes.
Unlike in Micro controllers windows cannot give events (Interrupts ) guaranteed for every byte received. I have tried by making a device connected to serial port which sends some lengthy strings. If I send bytes with a few 10s of milliseconds gap from the embedded device, I am getting an event for every byte. But if I send a continuous data stream with no delay in between, events are triggered at no uniform intervals. sometimes 8 bytes sometimes 40 bytes. even if receive threshold is set to 1 byte.
So what I found as the best method is make receive threshold as 1 byte, on receive event use BytesToRead method to get all bytes received so far and append it to a string. also on every event clear a timer count to 0. When the packet ends the timer count will not gets cleared in time so that it will climb up and creates a user event.(working on that)on the event can check for a EOF to confirm a valid packet.
Why this complex machine cannot give a timely event while a small Microcontroller can do it in correct time?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
|
|
|
|
|
|
How can i count the number of characters used out of provided in a text box.I mean when a user enters some text in a text box provided how can i show he has used x out of y characters with each keystroke in real time?Can anyone provide code in C#?Thanks
|
|
|
|
|
Set the MaxLength property of your textbox to some value (like 200), then in the TextChanged event of the textbox you can write some information into a label if you like:
private void textBox1_TextChanged(object sender, EventArgs e)
{
label1.Text = string.Format("You use {0} out of {1} characters", textBox1.Text.Length, textBox1.MaxLength);
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Please tell me the link for learning the mobile programming
|
|
|
|
|
try to search in google
there are a lot of good results on a few first pages...
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Hi,
I want to trigger an event every time I type something in a textbox using Onchange events.
The code im using is
IHTMLElementCollection elcol1 = doc.getElementsByTagName("input");
foreach (IHTMLInputTextElement iel in elcol1)
{
HTMLInputElementClass ee = iel as HTMLInputElementClass;
if (ee.value!= null && ee.IHTMLInputElement_type.Equals("text"))
{
ee.HTMLInputTextElementEvents2_Event_onChange += new HTMLInputTextElementEvents2_onChangeEventHandler(ee_HTMLInputTextElementEvents2_Event_onchange);
}
}
For every text element it enters into the "if" block but the "ee_HTMLInputTextElementEvents2_Event_onchange" function is not called. How can i trigger the event? Please help!
|
|
|
|
|
Hi, I am trying to use the third party VideoCog componet with C# and I need to copy a image frame? Videocog drops the frame into an rgb array in memory and I can then fast process the pixels using pointers.
How can I create another copy of the frame from memory so that I can also access that via another pointer?
Thanks...
1.
private void videoCogControl1_FrameReady(double SampleTime, IntPtr pBuffer,
2.
int BufferSize, int Width, int Height)
3.
{
4.
unsafe
5.
{
6.
byte* p = (byte*)(void*)pBuffer;
7.
int nWidth = Width * 3;
8.
for (int y = 0; y < Height; y++)
9.
{
10.
for (int x = 0; x < nWidth; x++)
11.
{
12.
p[0] = (byte)(255 - p[0]);
13.
p++;
14.
}
15.
}
16.
}
17.
}
|
|
|
|
|
Have you tried the Marshal.Copy[^] method from the interop namespace?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks for the reply, I am very new to C# and I am just working off the Videocog tutorials, do you have an example of how Marshal.Copy works?
|
|
|
|
|
|
Thanks, I got it to work, but there must be an faster/easyer way to copy a block of memory?
This is what I did to get it to work with Marshal.ReadByte, it gives me p2 which I can use on the copied image:
byte[] bytes = new byte[BufferSize];
for (int i = 0; i < BufferSize; i++)
bytes[i] = Marshal.ReadByte(pBuffer, i);
fixed (byte* pTmp = bytes)
{
System.IntPtr pBuffer2 = new IntPtr((void*)pTmp);
byte* p2 = (byte*)(void*)pBuffer2;
}
|
|
|
|
|
Use Marshal.Copy instead of Marshal.ReadByte . Now you are making a method call for every byte that you copy, that is bound to be slow.
Why are you converting the pointer to an IntPtr value, then back to a pointer? Just copy the pointer:
fixed (byte* pTmp = bytes) {
byte* p2 = pTmp;
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks, I tried to use Marshal.Copy but I could not get it to work, could you please show how to implement it?
Cheers,
|
|
|
|
|
Have you tried the C++ forum?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi, I found a very quick method in the end using RtlMoveMemory:
[DllImport("kernel32")]
public static extern void RtlMoveMemory(IntPtr dest, IntPtr src, int len);
System.IntPtr pBuffer2 = Marshal.AllocHGlobal(BufferSize);
RtlMoveMemory(pBuffer2, pBuffer, BufferSize);
byte* p2 = (byte*)(void*)pBuffer2;
Marshal.FreeHGlobal(pBuffer2);
Thanks, for the help and hope this helps some one else.
|
|
|
|
|
hi
i want to send mail using C# but i cant
this is my code:
MailAddress from = new MailAddress("negin_sarkhosh22@yahoo.com", ":: safir187.com ::");
MailAddress to = new MailAddress("sara_sarakhanom22@yahoo.com", ":: tnz187 ::");
MailMessage message = new MailMessage(from, to);
message.Subject = "Safir187.com is updated!";
message.IsBodyHtml = true;
message.Priority = MailPriority.High;
message.Body = "wedqwe";
SmtpClient client = new SmtpClient("localhost");
client.Send(message);
please tell me my mistake
thanks
|
|
|
|
|
What does "cant" really mean? Does the code compile? What happens when you run it? Do you get an error message?
Does the server have an active SMTP service?
Does your ISP allow sending mails through their system? This is sometimes disallowed to prevent spamming. In that case you have to use the SMTP server that they provide.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Why do people vote this as an unhelpful answer? I'll vote this one as helpful for justice.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I think the OP voted it down because it wasn't the answer HE was looking for.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Yeah, seems to be pretty common these days
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Yeah, over in the ASP.NET forum somebody vote me down just because I told them to get a book or two on programming in ASP.NET since they were a beginner asking an incredibly trivial question.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|