Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Code only appears to execute when breakpoint is set

COM port Event Handler Debug

  • Please log in to reply
No replies to this topic

#1 j2inet

j2inet

    Member

  • Members
  • PipPip
  • 11 posts

Posted 04 April 2013 - 08:10 PM

I've set up a PWM in my code that's going to be controlling a servo. 

 

PWM throttlePort2 = new PWM(PWMChannels.PWM_PIN_D11, 2000, 0.0, false);//throttlePort2.Frequency = 2000;//throttlePort2.DutyCycle = 0;throttlePort2.Start();

 

I've set up an event handler for incoming data from a COM port. Data is sent about 4 to 8 times per second depending on conditions. When that data is received I'm using it to alter the duty cycle on the PWM. 

 

double _throttlePosition;public double ThrottlePosition{    get { return _throttlePosition; }    set     {        if (value != _throttlePosition)        {            _throttlePosition = value;            if (throttlePort != null)                throttlePort.DutyCycle = _throttlePosition;        }    }}

 

When the code is running the PWM doesn't ever appear to be altered. If I set a breakpoint here and allow the code to continue immediately after the breakpoint then it executes fine. But it only seems to execute under this condition. In verifying what was going on I tried using the PWM on the onboard led and also tried with a speaker connected to the PWM pin. Both yield the same results. Is there anything I'm doing wrong?

 

I found another thread from 2 years ago about an odd behaviour (bug?) that occurs if you don't empty the read buffer (http://forums.netdui...recieved-event/). But I don't know if it is applicable given the way that I am reading from the port. 

 

void OnControlDataReceived(object sender, SerialDataReceivedEventArgs e){    while (_controlPort.BytesToRead > 0)    {        int bytesToReadCount = _controlPort.BytesToRead;        int bytesRead = _controlPort.Read(                          _receiveBuffer,                           _receiveBufferLocation,                           _controlPort.BytesToRead            );        _receiveBufferLocation += bytesRead;        CheckBufferForFlush(); //<-- some stuff happens here                                //to empty _receiveBuffer    }}

 

 







Also tagged with one or more of these keywords: COM port, Event Handler, Debug

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.