Click here to Skip to main content
15,899,313 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to print the property values of an object to a file/console ? Pin
AtaChris22-Apr-24 21:23
AtaChris22-Apr-24 21:23 
GeneralRe: How to print the property values of an object to a file/console ? Pin
Pete O'Hanlon22-Apr-24 22:44
mvePete O'Hanlon22-Apr-24 22:44 
GeneralRe: How to print the property values of an object to a file/console ? Pin
Dave Kreskowiak23-Apr-24 4:10
mveDave Kreskowiak23-Apr-24 4:10 
QuestionHow to identify Key Combinations ? Pin
AtaChris15-Apr-24 6:26
AtaChris15-Apr-24 6:26 
AnswerRe: How to identify Key Combinations ? Pin
Dave Kreskowiak15-Apr-24 6:35
mveDave Kreskowiak15-Apr-24 6:35 
QuestionHow to send property values via eventhandler ? Pin
AtaChris7-Apr-24 7:41
AtaChris7-Apr-24 7:41 
AnswerRe: How to send property values via eventhandler ? Pin
OriginalGriff7-Apr-24 20:23
mveOriginalGriff7-Apr-24 20:23 
GeneralRe: How to send property values via eventhandler ? Pin
AtaChris15-Apr-24 6:46
AtaChris15-Apr-24 6:46 
GeneralRe: How to send property values via eventhandler ? Pin
OriginalGriff15-Apr-24 19:09
mveOriginalGriff15-Apr-24 19:09 
QuestionRead information from serial port in Mathlab format Pin
Victor Gonzalez 20245-Apr-24 9:43
Victor Gonzalez 20245-Apr-24 9:43 
AnswerRe: Read information from serial port in Mathlab format Pin
Richard Andrew x645-Apr-24 11:01
professionalRichard Andrew x645-Apr-24 11:01 
GeneralRe: Read information from serial port in Mathlab format Pin
Victor Gonzalez 20245-Apr-24 12:26
Victor Gonzalez 20245-Apr-24 12:26 
AnswerRe: Read information from serial port in Mathlab format Pin
jschell5-Apr-24 12:20
jschell5-Apr-24 12:20 
GeneralRe: Read information from serial port in Mathlab format Pin
Victor Gonzalez 20245-Apr-24 12:28
Victor Gonzalez 20245-Apr-24 12:28 
GeneralRe: Read information from serial port in Mathlab format Pin
Richard MacCutchan5-Apr-24 22:44
mveRichard MacCutchan5-Apr-24 22:44 
GeneralRe: Read information from serial port in Mathlab format Pin
Victor Gonzalez 20245-Apr-24 23:22
Victor Gonzalez 20245-Apr-24 23:22 
GeneralRe: Read information from serial port in Mathlab format Pin
Richard MacCutchan5-Apr-24 23:41
mveRichard MacCutchan5-Apr-24 23:41 
GeneralRe: Read information from serial port in Mathlab format Pin
Luc Pattyn6-Apr-24 8:16
sitebuilderLuc Pattyn6-Apr-24 8:16 
GeneralRe: Read information from serial port in Mathlab format Pin
Victor Gonzalez 20247-Apr-24 1:12
Victor Gonzalez 20247-Apr-24 1:12 
Hello all,

Yes periodicaly the data sended is 21 byte, but some times send 63 or 42 bytes.
I think that I found the solution and now I can red the data in decimanl and later I transofrm to "X".

Now I have another problem. When I start the program with out break point for debug, when I read the information i write to the screen, but this write not found, but if I put a break point and debug the progam, yes is writing the messages in the screen.

this is my code.

using System;
using System.IO.Ports;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;

class PortDataReceived
{

    public static void Main()
    {

        SerialPort mySerialPort = new SerialPort("COM3");

        mySerialPort.BaudRate = 56000;
        mySerialPort.Parity = Parity.None;
        mySerialPort.StopBits = StopBits.One;
        mySerialPort.DataBits = 8;
        mySerialPort.Handshake = Handshake.None;
        mySerialPort.RtsEnable = true;

        mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

        mySerialPort.Open();

        Console.WriteLine("Press any key to continue...");
        Console.WriteLine();
        Console.ReadKey();
        mySerialPort.Close();
    }

    private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
    {

        
        SerialPort sp = (SerialPort)sender;

        
        int count = sp.BytesToRead;
        int count2 = 0;
        byte[] data = new byte[count];
        sp.Read(data, 0, data.Length);

        switch (data.Length)
        {

            case 63:
                Console.WriteLine("inicio carrera o  pause off");
                if (data[7].ToString("X").Equals("0") && data[8].ToString("X").Equals("A6"))
                {
                    Console.WriteLine("pause off");

                }
                else
                {
                    if (data[7].ToString("X").Equals("3E") && data[8].ToString("X").Equals("A1"))
                    {
                        Console.WriteLine("carrera go!");
                    }
                }
                break;
            
            case 21:
               //Console.WriteLine("vuelta o pause on o stop carrera manual");
                if (data[7].ToString("X").Equals("1B") && data[8].ToString("X").Equals("A9"))
                {
                    Console.WriteLine("contador vuelta y tiempo");
                    
                }
                else
                {
                    if (data[7].ToString("X").Equals("0") && data[8].ToString("X").Equals("A5"))
                    {
                        Console.WriteLine("pause on");
                    }
                    else
                    {
                        if (data[7].ToString("X").Equals("0") && data[8].ToString("X").Equals("A7"))
                            Console.WriteLine("stop forzado");
                    }
                }
                break ;


            case 42:
                Console.WriteLine(" fin carril");
                break ;
             
        }
        sp.DiscardInBuffer();

        /*string[] tablehex = new string[data.Length];
        
        for (int i = 0; i < count; i++)
        {
            tablehex[i] = data[i].;
           //tablehex[i] = hexvalue;

        }
                 
            //   Console.WriteLine(hexvalue.ToString());

            // Console.WriteLine(tablehex[count2].ToString());

        leertabla(tablehex);*/


    }

GeneralRe: Read information from serial port in Mathlab format Pin
Luc Pattyn7-Apr-24 1:52
sitebuilderLuc Pattyn7-Apr-24 1:52 
GeneralRe: Read information from serial port in Mathlab format Pin
Victor Gonzalez 20247-Apr-24 6:04
Victor Gonzalez 20247-Apr-24 6:04 
GeneralRe: Read information from serial port in Mathlab format Pin
Luc Pattyn7-Apr-24 8:13
sitebuilderLuc Pattyn7-Apr-24 8:13 
GeneralRe: Read information from serial port in Mathlab format Pin
Victor Gonzalez 20247-Apr-24 9:53
Victor Gonzalez 20247-Apr-24 9:53 
GeneralRe: Read information from serial port in Mathlab format Pin
Luc Pattyn7-Apr-24 11:04
sitebuilderLuc Pattyn7-Apr-24 11:04 
GeneralRe: Read information from serial port in Mathlab format Pin
Victor Gonzalez 20247-Apr-24 22:42
Victor Gonzalez 20247-Apr-24 22:42 

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.