Current location - Quotes Website - Team slogan - Q series plc initial port number
Q series plc initial port number
Use? System;

Use? System. Assemble. Generics;

Use? System. Linq

Use? System. Text;

Use? System. IO. port;

Namespace? Class library 1

{

Public? Class? Category 1

{

Serial port? myPort

///? & lt summary & gt

///? Initialization port

///? The default port 1 is used here, with a rate of 9600bts and no parity.

///? & lt/summary & gt;

Invalid? InitSerialPort()

{

//? Port initialization

My port? =? New? serial port();

My port. Port name? =? ”com 1”;

My port. Podrat? =? 9600;

My port. Parity? =? Parity. None;

My port. Data bits? =? 8;

My port. Stop position? =? Stop position. None;

My port. WriteTimeout? =? 500;

//? Open the port

My port. open();

}

///? & lt summary & gt

///Send instruction

///The instructions are written according to the target platform.

///? & lt/summary & gt;

///? & ltparam? name="strCmd " >& lt/param & gt;

Invalid? SendCmd (string? strCmd)

{

What if? (myPort? ==? Empty)

{

init serial port();

}

attempt

{

My port. WriteLine(strCmd);

}

Catch? (exception? ex)

{

Throw? ex;

}

}

}

I have never used this PLC, but the principle is similar. You can control an instruction by modifying its data structure.

If you want to get feedback, please use.

My port. read(); Or my port. Read line ()

Error control and buffering can refer to the example of SerialPort of MSDN.