473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Serialport: Need help please

Hi,

I am reading the output of a microcontroller through the serial port to show a value on a textbox and to draw a meter accordingly. I have written the datarecieved function which works OK as it follows.

Expand|Select|Wrap|Line Numbers
  1. void sp_datarecieved(object sender, SerialDataReceivedEventArgs e)
  2.         {
  3.           data = sp.ReadLine(); 
  4.           temp = Convert.ToDouble(data);
  5.           if (data != null)
  6.             {
  7.                 for (int i = 0; i < 5000; i++)
  8.                 {
  9.                     CrossThreadOperation.Invoke(txtTemp, delegate { txtTemp.Text = Convert.ToString(data.Trim()); });
  10.                 }
  11.                 }
  12.                     }
  13.  
  14.  
  15.  

For the graphics I have written the following.

Expand|Select|Wrap|Line Numbers
  1. private void temp_sen_Paint(object sender, PaintEventArgs e)
  2.         {
  3.             angle = 6.0 * temp;
  4.             radian = (Math.PI * angle/ 180);
  5.             x = Convert.ToInt32(192 - 162* Math.Cos(radian));
  6.             y = Convert.ToInt32(202 - 162*Math.Sin(radian));
  7.             Image img = Image.FromFile("C:\\mohammad\\p\\tem_sen\\temp_sen_serial\\drawing\\meter.JPG");
  8.             e.Graphics.DrawImage(img, 0, 0);
  9.             e.Graphics.DrawLine(mypen, x, y, 192, 202);
  10.         }
  11.  
The problem is when I check the value in 'angle = 6.0 * temp;' using a break point I can see 'temp' = 23 for example but I get 0.0 in 'angle' and that why the fraphics doesn't work as I want it to work.

I don't know what the problem is.

I would really be glad if someone can help me here.

Thanks in advance.
Nov 11 '10 #1
1 1259
You can try blocking object (lock object temp)... See here http://msdn.microsoft.com/en-us/library/c5kehkcz.aspx
Nov 12 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ron | last post by:
I can't figue out whats wrong. I am a newbie to sql, however i'm totally lost. i get this error. "Microsoft OLE DB Provider for ODBC Drivers error '80004005' Data source name not found and no...
2
by: Beau Gould | last post by:
JOB: Telecommute Python Programmer - IMMEDIATE NEED Please see www.superiorss.com/jobs.htm -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.362 / Virus...
0
by: Joshua Moore | last post by:
I'm trying to convert from a lot of invoked code to c# 2.0 SerialPort code. I can't find a way to set fOutxCtsFlow to true (maybe CTSEnable?) and fRtsControl = RTS_CONTROL_HANDSHAKE (RtsEnable?). ...
3
by: Eric | last post by:
Hi, In my application for PDA I use the serialport class to send data to a navigation computer of VDO Dayton. Everything works fine as long as it is connected to the nav-computer. When the...
2
by: Eric | last post by:
I'm trying to send a text message via my cell phone using the .net 2.0 SerialPort object. The command to send a text message requires a newline "\n" and a ctrl-z command to be entered. I've tried...
4
by: John | last post by:
I am using C# 2005 and System.IO.Ports. private void SendData() { SerialPort m_Com; m_Com = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.Two); m_Com.NewLine = "\r"; m_Com.Open();...
13
by: Jean Paul Mertens | last post by:
Hello, Someone can tell me why I dont get serial port events in a Service, I created a separate Thread to open the port but no events are coming up (the same happens when I use the timer...
2
by: Jay | last post by:
Extracted from the C# example in http://msdn2.microsoft.com/en-us/library/s14dyf47.aspx... public static void Main() { string name; string message; StringComparer stringComparer =...
3
by: Adriano | last post by:
Hello, I'm developing an application in VB.NET 2005 that communicates with a device through RS232, and need to send the following sequence of hexadecimal data to the device: 0xFF, 0x01, 0xC3,...
2
by: egress | last post by:
Forgive me for stupid questions for I am new to serial IO programming. I am developing an app that will need to communicate with a device via RS232 protocol using a standard 9 pin serial cable. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.