//Dev2との接続 private void button8_Click(object sender, EventArgs e) { button7.Enabled = true; button8.Enabled = false; Task task2 = Task.Factory.StartNew(() => { try { serialPort2send = new SerialPortProcessor { PortName = "COM5", BaudRate = 9600, Parity = Parity.None, DataBits = 8, StopBits = StopBits.One }; serialPort2send.DataReceived += DataReceivedCallback2; serialPort2send.Start(); Boxprint("シリアルポート(COM5)の接続に成功しました"); } catch (IOException er) { if (er.Source != null) { Boxprint("シリアルポート(COM10)との接続に失敗しました"); Boxprint("IOException source:" + er.Source); } } try { serialPort2receive = new SerialPortProcessor { PortName = "COM6", BaudRate = 9600, Parity = Parity.None, DataBits = 8, StopBits = StopBits.One }; serialPort2receive.DataReceived += DataReceivedCallback2; serialPort2receive.Start(); Boxprint("シリアルポート(COM6)の接続に成功しました"); } catch (IOException er) { if (er.Source != null) { Boxprint("シリアルポート(COM11)との接続に失敗しました"); Boxprint("IOException source:" + er.Source); } } }); }
public static void ReceiveWork(object target) { SerialPortProcessor my = target as SerialPortProcessor; my.ReceiveData(); }