通过netduino plus 2上的串行端口读取数据 [英] reading data through a serial port on netduino plus 2
问题描述
using System.IO.Ports;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace barcode_scanner
{
public class Program
{
public static InputPort bsr = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled);
public static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
public static void Main()
{
SerialPort mySerialPort = new SerialPort("COM1");
mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
}
public static void DataReceivedHandler( object sender, SerialDataReceivedEventArgs e)
{
led.Write(true);
Thread.Sleep(1000);
led.Write(false);
Thread.Sleep(Timeout.Infinite);
}
我正在使用上面的代码通过一个通过分线板连接到我的netduino plus 2的串行端口(RS232到TTL转换器-
I'm using the above code to receive data through a serial port connected to my netduino plus 2 via a breakout board (RS232 to TTL converter- http://www.embeddedmarket.com/products/RS232-to-TTL-Converter/). The data i want to receive is from a barcode scanner whose output is a RS232 female, so i use a RS232 male to male cable and then use the above mentioned breakout board to connect to netduino plus 2. Upon use of the above code led doesnot blink. All i want to do is blink the led when data is read from barcode scanner i.e., when the barcode scanner scans a barcode. Please help me resolve this. Thanks in advance.
ms
推荐答案
Hi 我正在将您的问题移到适当的论坛上,以便获得更好的答复.
I am moving your question to appropriate forum for better responses.
这篇关于通过netduino plus 2上的串行端口读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!