通过串口同步C#应用程序和设备

发布于 2024-10-14 15:08:31 字数 524 浏览 2 评论 0原文

我开发了ac#应用程序,它通过串口读取设备。我实现了写入但不正确。现在我的场景是通过串口自动格式化设备。首先,当设备等待时,我必须发送一个按键(当我在 Richtextbox 中看到“按任意键停止自动启动”时)。我怎样才能做到这一点?当我在 Richtextbox 中收到命中消息时,我通过写入串行端口 (serialport1.write("xxxx\r\n")) 来实现此目的,但我认为闲置 Richtextbox 不是一个好主意。你能建议任何其他方式吗?

我的重要问题是让我们考虑一下处理命中消息并停止自动引导。现在我们必须向设备发送命令进行格式化。例如,第一个是 fdisk 命令,第二个是 ext3format,第三个是 fatformat。将这些命令发送到设备时需要一些时间。我如何同步我的命令和设备,因为当我尝试这样做时遇到了一些问题。问题是我必须在发送第一个命令并且设备完成其工作后发送其他命令。我只能使用 Richtextbox,并根据输出尝试发送以下命令。你能建议任何其他方式吗?我是否必须允许 Richtextbox 输出,是否有其他方法可以了解设备在发送命令后完成其工作?

谢谢

I developed a c# application which is read the device through serial port. I achieve write to it but not properly. Now my sceneraio is the formatting the device through serial port automatically. First of all i have to send a keypress when the device wait for it(when i see in the richtextbox "hit any key to stop autoboot"). How can I do that? I achieve this with writing to the serial port (serialport1.write("xxxx\r\n")) when i get the hit message in the richtextbox but i think it is not a good idea to fallow the richtextbox. Can you suggest any other way?

My important question is let's think about we handle the hit message and stop autobooting. Now we have to send commands to the device for formating. For example first one is fdisk command, second one is ext3format and third one is fatformat. These commands takes time when you send these to the device. how can i sync my commands and the device, because when i trying to do that i got some problems. The problem is i have to send other command after the first command sent and device finished its job. I can only fallow the richtextbox and according to the output i m trying to send the fallowing commands. Can you suggest any other way? Do i have to fallow richtextbox outputs, is there any other way to understand the device finishes its job after sending commands?

THANK YOU

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

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

发布评论

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

评论(1

行至春深 2024-10-21 15:08:31

显然,您正在通过串行端口连接(telnet?)使用远程控制台进入设备,并且该设备正在使用 Linux。所以基本上你是在程序中模拟用户输入和输出。

首先,您需要识别设备逐字节发送的输出。不要关注“richtextbox”,您仅使用它来显示从设备获得的内容。

您需要处理传入的串行数据并查找您识别的数据模式(例如,格式命令的结果代码、命令提示符再次可见时发送的文本等)。

当它说“按任意键”时,您需要通过设备识别的串行端口发送一个字符。

您还需要知道设备期望您使用哪种终端模式仿真(google this),因为这会影响您应如何格式化发送到设备的代码以及应如何解释从设备接收到的字符。

您想要做的事情很简单,基本上您正在为设备编写一个自动远程终端,但它确实需要您进行一些阅读,并且不再关注文本框显示的内容,而是开始关注进出的数据字节您的设备。

Apparently, you are using a remote console into the device via a serial port connection (telnet?), and the device is using linux. so basically you are simulating user input and output in your program.

You need to recognize the output the device is sending byte by byte, first of all. Do not focus on the "richtextbox", you are only using that to display what you get from the device.

You need to process the serial data as it comes in and look for patterns of data that you recognize (for example, the result code from the format command, the text sent over when the command prompt is visible again, etc).

When it says "hit any key", you need to send a character over the serial port that the device recognizes.

you also need to know which terminal mode emulation (google this) the device is expecting you to use, because this affects how you should format codes sent to the device and how you should interpret characters you receive from it.

What you want to do is straightforward, basically you are writing an automated remote terminal for the device, but it does require some reading on your part, and stop focusing on what a textbox displays and start focusing on the data bytes going into and out of your device.

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