2.14.4 Serial Communication Format
PLC can using NC_COMMAND_SERIALLINK to set serial communication format, which plc.ncCommand.flag to be set to NC_COMMAND_SERIALLINK; plc.ncCommand.attr needs to be set to SERIALLINK_ATTR_SET_BAUDRATE.
- Example: M69 to set the serial transmission format, the NC will finish set to 1.
void plcRun(Status &sts, PlcBlock &plc)
{
...
if( plc.mCode.flag ) {
switch( plc.mCode.data ) {
case 69:
// finish setting
if( plc.ncCommand.flag == NC_COMMAND_SERIALLINK && plc.ncCommand.finish ) {
plc.ncCommand.flag = 0;
plc.mCode.finish = 1;
} else if( plc.ncCommand.flag == 0 ) { // ncCommand is zero NC allow set data
if( plc.mhAttr&PLC_MH_ATTR_0 )// if M code has H code, H code is baudrate
plc.ncCommand.data.x = plc.mhCode0;
else
plc.ncCommand.data.x = 9600;
plc.ncCommand.data.y = 0; // no parity
plc.ncCommand.data.z = 1; // 1 stop bits
plc.ncCommand.data.a = 8; // 8 data bits
plc.ncCommand.flag = NC_COMMAND_SERIALLINK;
plc.ncCommand.attr = SERIALLINK_ATTR_SET_BAUDRATE;
}
break;
}
}
...
}
- Transmission format Description:
1. Variable: plc.ncCommand.data.x
Transmission format: Baud rate
Value: 1200, 2400, 4800, 9600, 19200, 38400, 76800, 115200
2. Variable: plc.ncCommand.data.y
Transmission format: Parity check
Value: 0 (none), 1 (odd), 2 (even), 3 (mark), 4 (space)
3. Variable: plc.ncCommand.data.z
Transmission format: Stop bits
Value: 1, 2
4. Variable: plc.ncCommand.data.a
Transmission format: Data bits
Value: 7, 8