Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VB.NET
Good Morning guys, I wonder if anyone knows how to work with automation system? I found this
example on the net http://www.codeworks.it/net/VBNetRs232.htm[^]
 
Just can not capture the event Spinning Electronic Turnstile? Can someone pass me a solution?
Posted 15-Feb-13 1:49am
Edited 15-Feb-13 4:19am
v2
Comments
Thyago Analista at 15-Feb-13 7:56am
   
I found another example in C # I found it easier to work with and has the same characteristics, except that you can not capture the event swivel ratchet electronics.
 
https://docs.google.com/file/d/0BwoCzDQ2EvFBYkdGTTFRcUhUTnc/edit?usp=sharing
Jegan Thiyagesan at 15-Feb-13 10:22am
   
Hi
I've a lot of automation work, what is your actual problem? can you post your code?
 
Regards
Jegan
Thyago Analista at 15-Feb-13 11:06am
   
My problem is trying to find out when the received electronic turnstile spinning so I can catch, tenhos these examples here that the internet worked, but I do not know which part I see to capture the event swivel ratchet, understand?
 
Code Serial Porta
https://docs.google.com/file/d/0BwoCzDQ2EvFBcy1nck1ZV0IxSDQ/edit?usp=sharing
Thyago Analista at 15-Feb-13 11:22am
   
Here disponibilizei the source code of my view there:
 
https://docs.google.com/file/d/0BwoCzDQ2EvFBcy1nck1ZV0IxSDQ/edit?usp=sharing
Jegan Thiyagesan at 18-Feb-13 4:37am
   
Hi
These codes are for just opening the serial port and setting its properties. There is no code that contains your command protocol. All serial interfaces has some form of command protocol. You need to get hold of the command protocol that applies to your turnstile or use an available hyperTerminal (http://www.der-hammer.info/terminal/) to reverse engineer the command protocol from you turnstile.
 
Regards
Jegan
Thyago Analista at 18-Feb-13 8:33am
   
Solve. Through my code
 
https://docs.google.com/file/d/0BwoCzDQ2EvFBYkdGTTFRcUhUTnc/edit?usp=sharing
 
I had to take over control in RLSD PIN (CD) which is where the capture event turns the ratchet ... thanks ...
Jegan Thiyagesan at 18-Feb-13 9:23am
   
Well done!
Carrier Detection is normally done between micro controllers, not on PC, so I assumed you will be using a command, rather than receive line signal.
 
Jegan

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi
Here is a serial port handler code:
 
// Author: Jegan Thiyagesan
// Date: 12/02/2013

using System;
using System.IO.Ports;
 
namespace PortHandler
{
        /// <summary>
    /// Port handler that handles receiving and sending data over serial port.
        /// </summary>
    public class PortHandler
    {
        private const string Delimiter = "\r";
        private const string Rx = "Rx << ";
        private const string Tx = "Tx >> ";
 
        private string m_data;
        private SerialPort m_serialPort;
 
        /// <summary>
        /// Data received event handler
        /// </summary>
        public event EventHandler<EventArgs<string>> DataReceived;
        /// <summary>
        /// Data send event handler
        /// </summary>
        public event EventHandler<EventArgs<string>> DataSend;
 
        /// <summary>
        /// Error message event handler
        /// </summary>
        public event EventHandler<EventArgs<string>> ErrorMessage;
 
        /// <summary>
        /// Initiate data received event
        /// </summary>
        /// <param name="dataReceived"></param>
        public void OnDataReceived(string dataReceived)
        {
            var handler = DataReceived;
            if (handler != null)
            {
                handler(this, new EventArgs<string>(dataReceived));
            }
        }
        /// <summary>
        /// Initiate data send event
        /// </summary>
        /// <param name="dataSend"></param>
        public void OnDataSend(string dataSend)
        {
            var handler = DataSend;
            if (handler != null)
            {
                handler(this, new EventArgs<string>(dataSend));
            }
        }
 
        /// <summary>
        /// Initiate error message event.
        /// </summary>
        /// <param name="errorMessage"></param>
        public void OnErrorMessage(string errorMessage)
        {
            var handler = ErrorMessage;
            if (handler != null)
            {
                handler(this, new EventArgs<string>(errorMessage));
            }
        }
 
        /// <summary>
        /// return collections of available ports
        /// </summary>
        public string[] Ports
        {
            get
            {
                return SerialPort.GetPortNames();
            }
        }
 
        /// <summary>
        /// check is port open
        /// </summary>
        public bool IsPortOpen
        {
            get
            {
                return (m_serialPort != null && m_serialPort.IsOpen);
            }
        }
 
        /// <summary>
        /// basic constructor
        /// </summary>
        public PortHandler()
        {
        }
 
        /// <summary>
        /// Disconnect port
        /// </summary>
        public void DisconnectPort()
        {
            if (m_serialPort != null)
            {
                CloseSerialPort();
            }
        }
 
        /// <summary>
        /// Connect port
        /// </summary>
        /// <param name="portName"></param>
        /// <param name="baudRate"></param>
        public bool ConnectPort(string portName, int baudRate)
        {
            if (m_serialPort == null)
            {
                m_serialPort = new SerialPort
                                   {
                                       PortName = portName,
                                       BaudRate = baudRate,
                                       Parity = Parity.None,
                                       StopBits = StopBits.One,
                                       DataBits = 8,
                                       Handshake = Handshake.None,
                                       ReadTimeout = 500 //500 ms
                                   };
 
            }
            else
            {
                CloseSerialPort();
                m_serialPort.PortName = portName;
                m_serialPort.BaudRate = baudRate;
            }
            OpenSerialPort();
            return IsPortOpen;
        }
 
        /// <summary>
        /// Send data over port
        /// </summary>
        /// <param name="data"></param>
        public void SendData(string data)
        {
            if ((m_serialPort != null) && m_serialPort.IsOpen)
            {
                m_serialPort.DiscardOutBuffer();
                m_serialPort.Write(data + Delimiter);
                OnDataSend(Tx + data + Delimiter);
            }
        }
 
        private void OpenSerialPort()
        {
            try
            {
                m_serialPort.DataReceived += SerialPortDataReceived;
                m_serialPort.Open();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message + ex.StackTrace);
            }
        }
 
        private void CloseSerialPort()
        {
            if (m_serialPort.IsOpen)
            {
                m_serialPort.DataReceived -= SerialPortDataReceived;
                m_serialPort.Close();
            }
        }
 
        private void SerialPortDataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            var serialPort = (SerialPort)sender;
            var data = serialPort.ReadExisting();
            ProcessData(data);
        }
 
        private void ProcessData(string data)
        {
            Console.Out.WriteLine(data + "\r");
        }
    }
}
 

I hope this help you.
 
Regards
Jegan
  Permalink  
Comments
Thyago Analista at 15-Feb-13 11:09am
   
Jegan Thanks,
In your code where I know that the electronic turnstile rotation when did you move to catch me again? In part there? This is my doubt capture the electron spin ratchet ...
Jegan Thiyagesan at 18-Feb-13 3:55am
   
Hi
I didn't quite understand your questions.
In serial communication like this, all operations are done through commands, and you must have a sets of command protocol to operate the turnstile that you are working on.
 
The code above will open the com port and send and receive messages. When the message is received, it will notify you via received event. It is up to you to process the received message according to the command protocol.

I hope this helps.
 
Regards
Jegan
Thyago Analista at 18-Feb-13 8:31am
   
Okay

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,745
1 OriginalGriff 6,696
2 CPallini 5,315
3 George Jonsson 3,599
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100