Click here to Skip to main content
15,920,438 members
Home / Discussions / C#
   

C#

 
QuestionExceptions and out parameters Pin
mringholm9-Mar-09 13:00
mringholm9-Mar-09 13:00 
AnswerRe: Exceptions and out parameters Pin
Christian Graus9-Mar-09 14:07
protectorChristian Graus9-Mar-09 14:07 
GeneralRe: Exceptions and out parameters Pin
mringholm10-Mar-09 5:26
mringholm10-Mar-09 5:26 
AnswerRe: Exceptions and out parameters Pin
Luc Pattyn9-Mar-09 14:55
sitebuilderLuc Pattyn9-Mar-09 14:55 
GeneralRe: Exceptions and out parameters Pin
mringholm10-Mar-09 5:23
mringholm10-Mar-09 5:23 
AnswerRe: Exceptions and out parameters Pin
Luc Pattyn10-Mar-09 6:00
sitebuilderLuc Pattyn10-Mar-09 6:00 
QuestionIXMLHTTPRequest Pin
tsahiB9-Mar-09 12:25
tsahiB9-Mar-09 12:25 
QuestionSerialport speed unstable C# Visual Studio 2008 Pin
jondaeh9-Mar-09 10:18
jondaeh9-Mar-09 10:18 
Hi!

I am writing a small application which shall communicate with a picaxe microship through the serialport. I have got the communication up and running using the SerialPort class, but got a little disappointed due to the speed.

The picaxe is connected to a potentiometer. The picaxe then reads the value and sends it as one byte(0 - 255)at a given frequency through the serialport to my computer. Then a textbox shows the value.

The problem is that the update speed seems to vary(it seems in the textbox). Sometimes it's pretty much realtime, other times it has up to 2 seconds lag. When it's good it may be good for a long time, a minute or so, and the same if it's slow. I don't know if this can be blamed at Windows(XP), or my programming, or if it's nothing to do with it.

I have heard(read) that the SerialPort class in .NET isn't exactly fast, but honestly, it's just one byte! I have tried many different frequencys for sending the byte at the PICAXE, from 4 times a second to a thousand, but it's like the port is slow.

I have read something about using one thread to scan the port in addition to the one that serves the Window itself, but with the eventhandler for datarecieved I believe this shouldn't be necessary.


I will paste some of my code below, and I will appreciate if someone gives me some feedback.

Thanks you for your time Smile | :) !

Jon, Norway.

The code:

//The fields and constructor omitted. Constructor instantiating the serialport object and
//runs  initializePort().

public void initializePort()
        {
            serialPort.PortName = "COM5";
            serialPort.BaudRate = 4800;
            serialPort.DataBits = 8;
            serialPort.ReadTimeout = 1000;
            serialPort.DataReceived += new SerialDataReceivedEventHandler(readPic); //Adds the //eventhandler

            serialPort.Open(); 
            serialPort.DtrEnable = true;  
        }

        public void readPic(object sender, SerialDataReceivedEventArgs e)
        {

            
                int fromPic = serialPort.ReadByte();
                String line = Convert.ToString(fromPic);
                
                if (display.InvokeRequired)
                {
                    display.Invoke(new MethodInvoker(delegate() { setDispText(line); }));
                }
                else
                {
                    display.Text = line;
                
               }
            
        }

        public void setDispText(String s)
        {
            display.Text = s;
        }

AnswerRe: Serialport speed unstable C# Visual Studio 2008 Pin
Dan Neely9-Mar-09 11:01
Dan Neely9-Mar-09 11:01 
AnswerRe: Serialport speed unstable C# Visual Studio 2008 Pin
Luc Pattyn9-Mar-09 11:16
sitebuilderLuc Pattyn9-Mar-09 11:16 
AnswerRe: Serialport speed unstable C# Visual Studio 2008 Pin
0x3c09-Mar-09 11:17
0x3c09-Mar-09 11:17 
AnswerRe: Serialport speed unstable C# Visual Studio 2008 Pin
Jonathan Davies10-Mar-09 1:56
Jonathan Davies10-Mar-09 1:56 
Questionhow to know who executed my application ? Pin
shabya9-Mar-09 10:11
shabya9-Mar-09 10:11 
AnswerRe: how to know who executed my application ? Pin
Jimmanuel9-Mar-09 10:36
Jimmanuel9-Mar-09 10:36 
AnswerRe: how to know who executed my application ? Pin
harold aptroot9-Mar-09 10:40
harold aptroot9-Mar-09 10:40 
GeneralRe: how to know who executed my application ? Pin
shabya10-Mar-09 12:20
shabya10-Mar-09 12:20 
AnswerRe: how to know who executed my application ? Pin
Dragonfly_Lee9-Mar-09 19:47
Dragonfly_Lee9-Mar-09 19:47 
GeneralRe: how to know who executed my application ? Pin
shabya10-Mar-09 12:21
shabya10-Mar-09 12:21 
GeneralRe: how to know who executed my application ? Pin
Dragonfly_Lee11-Mar-09 1:17
Dragonfly_Lee11-Mar-09 1:17 
Questionwhy is it not writing to screen the first line/value in the txt file this code? Pin
wwwxyz9-Mar-09 10:07
wwwxyz9-Mar-09 10:07 
AnswerRe: why is it not writing to screen the first line/value in the txt file this code? Pin
Rutvik Dave9-Mar-09 10:19
professionalRutvik Dave9-Mar-09 10:19 
GeneralRe: why is it not writing to screen the first line/value in the txt file this code? Pin
wwwxyz9-Mar-09 10:42
wwwxyz9-Mar-09 10:42 
GeneralRe: why is it not writing to screen the first line/value in the txt file this code? Pin
Rutvik Dave9-Mar-09 11:02
professionalRutvik Dave9-Mar-09 11:02 
GeneralRe: why is it not writing to screen the first line/value in the txt file this code? Pin
wwwxyz9-Mar-09 11:09
wwwxyz9-Mar-09 11:09 
GeneralRe: why is it not writing to screen the first line/value in the txt file this code? Pin
Guffa9-Mar-09 17:57
Guffa9-Mar-09 17:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.