开发者

Writing through serial port

below you can see my program output.While my device begin to boot, through serial port I send serialport1.write("\n"); and i topped the autoboot. then I must send three commands with serialport1.write command. if the thread sleeps before the command the commands are executed but i see the result after the commands done. I mean if i get slept the thread 1 sec before the commands, for 3 commands i see the result in richtextbox after 3 seconds.开发者_如何学C Why? Is there any other good way to executing the commands? my code is below.

THE CODE:

_data = _serialPort.ReadExisting();
if (_data.StartsWith("Hit"))
{
    Thread.Sleep(1000);
    _serialPort.Write("\n");
    Thread.Sleep(200);
    _serialPort.Write("set moviargs...\n");
    Thread.Sleep(200);
    _serialPort.Write("saveenv\n");
    Thread.Sleep(200);
    _serialPort.Write("boot\n");
}

THE OUTPUT:

Hit any key to stop autoboot: 3 2 1 0

SMDKV210 # set moviargs "setenv bootargs console=ttySAC2,115200 smsc95xx.macaddr=00:09:DF:90:00:03"

SMDKV210 # saveenv

Saving Environment to SMDK bootable device...

done

SMDKV210 # boot


You're UI won't update in Thread.Sleep.

Add some Application.DoEvents step before each 'Sleep' call to update the UI. (or run the code talking to the serial port on a background thread)

The Application.DoEvents call should handle 'waiting' events like screenupdate but will also try and start button clicks. You'd have to add a mechanism to disable button clicks(just disable the buttons).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜