Answer the question
In order to leave comments, you need to log in
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)
.
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();
}
}
}
Answer the question
In order to leave comments, you need to log in
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.
serialPort1.WriteLine("1");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question