简体   繁体   English

在线程C#中使用SerialPort命令

[英]Use SerialPort commands in a Thread C#

I have a thread, and I want to send some command with Serial Port. 我有一个线程,我想使用串行端口发送一些命令。 How Can I do this? 我怎样才能做到这一点?

Thread execProcess = new Thread(eProcess);

static bool isRunning = false;

static void eProcess()
{
    while(true)
    {
        if(isRunning)
        {
            sendCmd(cmd); //cmd is a string
        }
    }
}

void sendCmd(string cmd)
{
   serialPort.WriteLine(cmd);
}

How can I do this? 我怎样才能做到这一点?

I don't know, were are your information about .NET threads from. 我不知道,这是您有关.NET线程的信息。 See here: 看这里:

Thread class 线程类

SerialPort class SerialPort类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM