Skip to content

Topic is about serial coomunication

deepender singla

Asked Jul 9, 2011, 11:10 PM EDTSolved
Share
LinkedInX
Respected members 
 i have scs 32 serco controller and i am talking serially to it , my code is
it is not working , it doesnot show any error but also servo is not rotating plz help me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;


using System.Threading;


namespace cConsoleAppMonitorServoCompletion
{
    class Program
    {
        static SerialPort _serialPort;


        static void Main(string[] args)
        {
            try
            {
                _serialPort = new SerialPort();
                _serialPort.PortName = "COM1";
                _serialPort.Open();
                _serialPort.Write("#27 P1600 S750\r");
                Console.WriteLine("#27 P1500 S750\r");
                string output;
                output = "";
                //Example: "Q <cr>" 
                //This will return a "." if the previous move is complete, or a "+" if it is still in progress. 
                while (!(output == ".")) //loop until you get back a period 
                {
                    _serialPort.Write("Q  \r");
                    output = _serialPort.ReadExisting();
                    Console.WriteLine(output);
                    Thread.Sleep(10);
                }
                _serialPort.Close();
            }
            catch (TimeoutException) { }
        }
    }
}

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • ✓ Accepted answer0
    Perhaps you need to specify the serial port parameters before opening the port.
    ...
    _serialPort = new SerialPort(comPort, baudRate, parity, dataBits, stopBits);
    _serialPort.Handshake = Handshake.None;
    _serialPort.ReadTimeout = 500;
    _serialPort.WriteTimeout = 500;
    _serialPort.Open();
    ...
    0
  • 0
    sir i have made some changes in my c# code , i suppose previously i was not opening port correctly now i a, doing this when i use this code then serial data led once starts and dont end, basically led on board blinks when ever it recieve any data, but there is no servo movement : the new code is
    Code:
    C#
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO.Ports;
    
    using System.Threading;
    
    namespace cConsoleAppMonitorServoCompletion
    {
        class Program
        {
            static SerialPort _serialPort;
    
            static void Main(string[] args)
            {
                try
                {
                    _serialPort = new SerialPort("COM1",15200,Parity.None, 8, StopBits.One); //[color=#0080BF]this is the change[/color]
                    _serialPort.Open();
                    _serialPort.Write("#27 P1600 S750\r");
                    Console.WriteLine("#27 P1500 S750\r");
                    string output;
                    output = "";
                    //Example: "Q <cr>"
                    //This will return a "." if the previous move is complete, or a "+" if it is still in progress.
                    while (!(output == ".")) //loop until you get back a period
                    {
                        _serialPort.Write("Q  \r");
                        output = _serialPort.ReadExisting();
                        Console.WriteLine(output);
                        Thread.Sleep(10);
                    }
                    _serialPort.Close();
                }
                catch (TimeoutException) { }
            }
        }
    }



    and when i try this led blink once, but no servo movement

    Code:
    C#
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO.Ports;
    
    using System.Threading;
    
    namespace cConsoleAppMonitorServoCompletion
    {
        class Program
        {
            static SerialPort _serialPort;
    
            static void Main(string[] args)
            {
    
    
                    _serialPort = new SerialPort("COM1",15200,Parity.None, 8, StopBits.One);
                    _serialPort.Open();
                    _serialPort.Write("#27 P1600 S750\r");
                    Console.WriteLine("#27 P1500 S750\r");
                        Thread.Sleep(10);
    
                    _serialPort.Close();
    
            }
        }
    }


    help me out

    0