Thanks for all the help, I updated my code and while it made operation of the servo more reliable it still has a few issues. The servo doesn't move every time a button is pushed, sometimes it does, sometimes it taks 3-4 pushes before it goes. Other times the board needs a reset or even a power cycle. I am going to get a RS232 female to male adapter tomorrow so I can try and get my other PC with a built in serial port to run it. My timer class is set to 100, is this correct? Its so close to working correctly however I am planing on realtime applications so I need it to run perfectly 100% of the time. I have included my new code just incase I have made any obvious mistakes. Thanks once again for all your guys help.
using System;
using
namespace
{
InitializeComponent();
InitSerializerComponents();
s_.StartCommunication();
}
s_.PumpEvents();
panServo.Position = -80;
panServo.Position = 80;
panServo.Position = 0;
#region
#endregion
s_ =
s_.PortName =
s_.BaudRate = 19200;
panServo =
panServo.ServoMotorId =
Your source code looks correct now, although your serializer (s_) and ServoMotorController (panServo) don't have to be static, since they're class members.
A period of 100 is fine for just controlling servo motors, as the Serializer.PumpEvents() is used to fire outstanding events for sensor readings. Since there are no sensors, you don't have to worry about a fast loop invoking PumpEvents().
This app should work perfectly. Can you put a Console.WriteLine("XXX Button Click"); in the button event handlers, so you can verify that the handler is indeed getting invoked every time you press it?
Let us know what you find out regarding this app working on your PC w/ the serial port.
Okay, I just wrote a quick app to mimic what you are doing, and button & servo response works just fine for me.
Here's the source:
public partial class Form1 : Form
private Serializer _s;
private ServoMotorController _servo1;
public Form1()
_s = new Serializer();
_s.PortName = "COM11";
_s.BaudRate = 19200;
_servo1 = new ServoMotorController(_s);
_servo1.ServoMotorId = ServoMotorId.ServoMotor2;
_s.CommunicationStarted += new SerializerEventHandler(_s_CommunicationStarted);
_s.StartCommunication();
void _s_CommunicationStarted(Serializer sender)
Console.WriteLine("Communications Started");
timer1.Enabled = true;
_servo1.Position = 0;
private void LeftButton_Click(object sender, EventArgs e)
_servo1.Position = -99;
Console.WriteLine("Left");
private void CenterButton_Click(object sender, EventArgs e)
Console.WriteLine("Center");
private void RightButton_Click(object sender, EventArgs e)
_servo1.Position = 100;
Console.WriteLine("Right");
private void timer1_Tick(object sender, EventArgs e)
_s.PumpEvents();
Thanks for the test App Jason, very much appreciated! I copied the debug .exe of my application over to my older desktop PC that has a built in serial communication port. After resoldering my null modem cable into a straight communications cable I finally got it to work perfectly. This leads me to the conclusion that it has to be my USB to serial port adapter. (Part # 3902B568) I googled it and found others having similar problems with this model on:
http://www.lynxmotion.net/viewtopic.php?t=2781&sid=b83e01ef744d1ddb59d8297575ff68d9
I think for the time being I will have to develop applications on my laptop then test them on my desktop. I tried changing the transmit buffer to 1 and 3 down from 16 but this did not help any. This adapter does work well with hyperterminal however, just not with Visual Studio applications. I will do a bit more research to see if there are any better USB to serial port adapters or if there is anyway to fix my one. I will repost if I have any luck. What model USB to Serial works for you guys??