向 RS232 发送电压

发布于 2024-10-20 12:38:51 字数 116 浏览 1 评论 0原文

我知道我们可以使用 3 号引脚将数据作为 RS232 的输出发送。但我只是想知道是否有另一种方法可以在短时间内仅向RS232发送5v电压?我只希望 5v 触发 PIC 微控制器执行某些操作。

先感谢您。

I know that we can use pin no.3 to send the data as a output in RS232. But I am just wondering that there is another way to send only the voltage 5v to the RS232 in a short period? I just want that 5v to trigger a PIC Microcontroller to do something.

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

隔纱相望 2024-10-27 12:38:51

您可以使用 SerialPort 类的 DTREnable(数据终端就绪)属性向相应的引脚施加正电压。这可用于向 MCU 发送信号。

类似于……

serialPort.DtrEnable = true; //High
currentThread.Sleep(1000);
serialPort.DtrEnable = false; //Low
currentThread.Sleep(1000);

但是! 电压可能不兼容,因为 RS232 1/0 的工作电压为 -25 至 25 伏。您可能需要一个内联驱动器/接收器(例如 MAX232 芯片)来在 MCU 和计算机之间运行,或者根据您的技能水平,您可以构建一个接收器电路。

You could use the DTREnable (Data Terminal Ready) property of the SerialPort class to apply a positive voltage to those respective pins. This could be used to signal an MCU.

Something along the lines of...

serialPort.DtrEnable = true; //High
currentThread.Sleep(1000);
serialPort.DtrEnable = false; //Low
currentThread.Sleep(1000);

However! the voltage is likely to be incompatible as RS232 operates -25 to 25 volts for 1/0's. You will likely need an inline driver/receiver such as a MAX232 chip to operate between the MCU and computer, or dependant on your skill level you could build a receiver circuit.

丶视觉 2024-10-27 12:38:51

您可以使用 RTS 或 DTR,只要不在 PIC 端使用它们进行流量控制即可

you can use RTS or DTR as long as you aren't using them on the PIC side for flow control

∞琼窗梦回ˉ 2024-10-27 12:38:51

带TTL接口的PIC单片机使用逻辑如下:
逻辑1 == 5伏。
逻辑0 == 0伏。

具有RS232接口的计算机使用逻辑如下:
逻辑 1 == -3 伏直到 -25 伏。
逻辑0 == 0直到25伏。

为了将设备TTL逻辑连接到RS232逻辑,可以使用MAX232 IC。 MAX232 会将您的 TTL 逻辑转换为 RS232 逻辑。

另一种选择 - 更便宜且简单,使用 TRANSISTOR 将 TTL 逻辑转换为 RS232 逻辑,反之亦然,请查看 http://www.kmitl.ac.th/~kswichit/ap275/ap275.htm 了解详细信息。

如果需要无需硬件握手发送数据,只需引脚2(RX)引脚3(TX)引脚5(GND) )。如果需要握手,请添加引脚 7(RTS)引脚 8(CTS)
发送数据如下:

serialPort1.Open();
serialPort1.Write("your data in here");

接收数据如下:

public Form1()
{
    InitializeComponent();
    this.serialPort1.DataReceived += new SerialDataReceivedEventHandler(this.serialPort1_DataReceived);
    serialPort1.Open();
}

void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    int i = 0;
    string[] DataReceived; 

    while (serialPort1.BytesToRead > 0) 
    {
        DataReceived[i] = Convert.ToByte(serialPort1.ReadByte()); // data already in here
        i++;         

        if (i == int.MaxValue-1)
          i = 0;            
    }
    // Parsing your data in here
}

如果只需要切换输出,使用pin 4 (DTR) OR pint 7(RTS)。
serialPort1.DtrEnable = true;serialPort1.RtsEnable = true;

PIC Microcontroller with TTL interface used logic as follows:
Logic 1 == 5 volt.
Logic 0 == 0 volt.

Computer with RS232 interface used logic as follows:
Logic 1 == -3 volt until -25 volt.
Logic 0 == 0 until 25 volt.

For connecting device TTL logic to RS232 logic can used MAX232 IC. MAX232 will translate your TTL logic to RS232 Logic.

Another options - cheaper and simple, used TRANSISTOR for convert TTL logic to RS232 logic vice versa, look at http://www.kmitl.ac.th/~kswichit/ap275/ap275.htm for details.

If need send data without hardware handshaking, only need pin 2 (RX), pin 3(TX), pin 5(GND). If need handshaking, add pin 7(RTS) AND pin 8(CTS).
Transmitte data as follows:

serialPort1.Open();
serialPort1.Write("your data in here");

Receive data as dollows:

public Form1()
{
    InitializeComponent();
    this.serialPort1.DataReceived += new SerialDataReceivedEventHandler(this.serialPort1_DataReceived);
    serialPort1.Open();
}

void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    int i = 0;
    string[] DataReceived; 

    while (serialPort1.BytesToRead > 0) 
    {
        DataReceived[i] = Convert.ToByte(serialPort1.ReadByte()); // data already in here
        i++;         

        if (i == int.MaxValue-1)
          i = 0;            
    }
    // Parsing your data in here
}

If just need toggle output, used pin 4 (DTR) OR pint 7(RTS).
serialPort1.DtrEnable = true;ORserialPort1.RtsEnable = true;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文