| Author |
Message |
|
|
Posted: Jul 25, 2012 - 05:41 PM |
|

Joined: Jun 19, 2012
Posts: 11
|
|
i'm trying to send and receive data from/to mcu using c#
currently my code for mcu is perfectly working when i use brays' terminal, i'm receiveing(for test purposes) signature of mcu (1E 94 0B) so the code in mcu is 100% working, but if i'm trying to get signature using c# serialport i'm getting 50 01 1E. if on this forum somebody knows c# i would be appreciated if you can help me to solve this riddle.
c# code:
Code:
serialPort1.DataReceived += new SerialDataReceivedEventHandler(DataReceviedHandler);
serialPort1.PortName = "COM10";
serialPort1.BaudRate = 4800;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.DataBits = 8;
serialPort1.Handshake = Handshake.None;
try
{
serialPort1.Open();
}
catch (System.Exception)
{
MessageBox.Show("Failed to open selected port.\nIs it open in another application?\n(" + ")");
}
finally
{
// If we have successfully opened the port
if (serialPort1.IsOpen)
{
serialPort1.RtsEnable = true; // Data-terminal-ready
serialPort1.DtrEnable = true; // Request-to-send
serialPort1.ReadTimeout = 5000;
serialPort1.WriteTimeout = 5000;
}
}
private void DataReceviedHandler(object sender, SerialDataReceivedEventArgs e)
{
for (int i = 0; i < serialPort1.BytesToRead; i++)
{
Console.WriteLine("Hex:. . . {0:X}\n", serialPort1.ReadByte());
}
Thanx for any help or link |
|
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 05:42 PM |
|

Joined: Nov 02, 2009
Posts: 3239
Location: Zelenograd, Russia
|
|
| Wrong forum. |
_________________ Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 06:00 PM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
What MCU are you using and can you post the code for that. I can help debug the C# code.
Also you misspelled DataReceivedHandler in two places.
MODERATOR: Please move this to an appropriate form. |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 06:10 PM |
|

Joined: Jun 19, 2012
Posts: 11
|
|
|
larryvc wrote:
What MCU are you using and can you post the code for that. I can help debug the C# code.
Also you misspelled DataReceivedHandler in two places.
MODERATOR: Please move this to an appropriate form.
the signature i've provided is for Atmega168p, the code for mcu currently too far away from me, but i'm sure there are no problems in it because i'm getting signature from regular terminal, wrong signature values appearing only in my c# program.
i'm not sure what you meant by "...misspelled DataReceivedHandler in two places"
PS Sorry for the post in wrong forum |
|
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 06:13 PM |
|


Joined: Jan 07, 2012
Posts: 1316
Location: North of France
|
|
|
Code:
:1,$s/DataReceviedHandler/DataReceivedHandler/g
|
|
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 07:09 PM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
See dbrion0606's post for the misspelling.
I suggested that you post the mcu code so that I would be able to run the code on a chip here and try to help you debug the C# code. So when you have the opportunity post it, that is if you do want help. |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 11:03 PM |
|


Joined: Mar 27, 2002
Posts: 18757
Location: Lund, Sweden
|
|
Yes, there is a mis-spelling but it is inconsequential (the user-supplied handler could be named anything, AFAIK.) As long as it has the correct "signature" (i.e. fitting the implied delegate), it can be added to the list of handlers. E.g.
serialPort1.DataReceived += new SerialDataReceivedEventHandler(foo);
Notice that the SerialPort member name and the class name has the correct spelling. |
|
|
| |
|
|
|
|
|
Posted: Jul 26, 2012 - 12:20 AM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
I agree that it has no impact on the code, I was just pointing out that I had noticed the mispelling.
I would like to help with debugging the C# code though. I might have to write something for an AVR to play around with it. |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|