C
C
Collin2016-12-23 13:45:28
Microcontrollers
Collin, 2016-12-23 13:45:28

What data comes to the device through the COM port if "1" is sent?

The question is next. We have the simplest device included in the USB port (USB to RS-232 converter)
84102914ed41445f85249bcf0e0f9f03.jpg.
Task:
Send a unit to it so that the light bulb blinks.
The program code is the following:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            serialPort1.WriteLine("1");
        }
        private void button2_Click(object sender, EventArgs e)
        {
            serialPort1.WriteLine("0");
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            string[] myPort;
            myPort = System.IO.Ports.SerialPort.GetPortNames();
            comboBox1.Items.AddRange(myPort);
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (serialPort1.IsOpen == true)
            serialPort1.Close();
        }
        private void button3_Click(object sender, EventArgs e)
        {
            serialPort1.BaudRate = 9600;
            serialPort1.PortName = comboBox1.Text.ToString();
            if (serialPort1.IsOpen == false)
                serialPort1.Open();
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            serialPort1.PortName = comboBox1.Text.ToString();
        }

    }
}

I decided to use an oscilloscope to see what exactly we get at the output:
6b3539d3bc2042aab6a606e3ba9de0fc.jpg
And here is the question itself:
In what encoding (in what bit depth) do we receive a signal through the COM port via RS-232. Because the oscillogram is not clear. At first I thought it was 31 in HEX, but it doesn't seem like it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mercury13, 2016-12-23
@Collin

Before us is such a construction
0 . 1000 . 1100 . one . 0 . 0101 . 0000 . 1
Each byte starts with start bit 0 and ends with stop bit 1. Transmitted starting from the least significant bit.
Total two bytes, 31+0A, or "1" + LineFeed.

R
Rou1997, 2016-12-23
@Rou1997

serialPort1.WriteLine("1");

Do you think this is a unit? This is a string with the character '1', and since WriteLine, in addition to this character, there is also a second character - '\n' (line break), to call it a "unit" you need to have very superficial knowledge in programming and electronics, such people then write WPF applications with system requirements like those of "top" games, they write a calculator that "eats" 100 MB of RAM and, accordingly, runs on a laptop in 5 seconds and sometimes takes up the same amount of space on the disk, I see no point in talking about signal encoding, send you need bytes manually composed of bits, then we’ll talk, in general there are different encodings, it’s not always “bit 0 = no pulse, bit 1 = pulse present”, often one bit is transmitted in two pulses in order not to confuse 0 with the absence of any data in general

A
aol-nnov, 2016-12-23
@aol-nnov

where is the light bulb? on the pins of the com port? directly??
even if you omit the question of tension.
9600 baud you won't notice how she blinks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question