VAR
uiComState : UINT;
xDone : BOOL;
aCom1Params : ARRAY [1..7] OF COM.PARAMETER;
aCom2Params : ARRAY [1..7] OF COM.PARAMETER;
como1 : COM.Open;
comc1 : COM.Close;
comw1 : COM.Write;
como2 : COM.Open;
comc2 : COM.Close;
comr2 : COM.Read;
sWrite : STRING := 'Test String der Länge 25!';
sRead : STRING(25);
szRead : CAA.SIZE;
xCom1OpenError : BOOL;
xCom1CloseError : BOOL;
xCom1WriteError : BOOL;
xCom2OpenError : BOOL;
xCom2CloseError : BOOL;
xCom2ReadError : BOOL;
END_VAR
CASE uiComState OF
0:
aCom1Params[1].udiParameterId := COM.CAA.Parameter_Constants.udiPort;
aCom1Params[1].udiValue := 1;
aCom1Params[2].udiParameterId := COM.CAA.Parameter_Constants.udiBaudrate;
aCom1Params[2].udiValue := 9600;
aCom1Params[3].udiParameterId := COM.CAA.Parameter_Constants.udiParity;
aCom1Params[3].udiValue := COM.PARITY.NONE;
aCom1Params[4].udiParameterId := COM.CAA.Parameter_Constants.udiStopBits;
aCom1Params[4].udiValue := COM.ONESTOPBIT;
aCom1Params[5].udiParameterId := COM.CAA.Parameter_Constants.udiTimeout;
aCom1Params[5].udiValue := 0;
aCom1Params[6].udiParameterId := COM.CAA.Parameter_Constants.udiByteSize;
aCom1Params[6].udiValue := 8;
aCom1Params[7].udiParameterId := COM.CAA.Parameter_Constants.udiBinary;
aCom1Params[7].udiValue := 0;
como1.udiListLength := SIZEOF(aCom1Params)/SIZEOF(COM.PARAMETER);
como1.pParameterList := ADR(aCom1Params);
como1.xExecute := TRUE;
como1();
IF como1.xError THEN
xCom1OpenError := TRUE;
uiComState := 1000;
END_IF
IF como1.xDone THEN
uiComState := 5;
END_IF
5:
aCom2Params[1].udiParameterId := COM.CAA.Parameter_Constants.udiPort;
aCom2Params[1].udiValue := 2;
aCom2Params[2].udiParameterId := COM.CAA.Parameter_Constants.udiBaudrate;
aCom2Params[2].udiValue := 9600;
aCom2Params[3].udiParameterId := COM.CAA.Parameter_Constants.udiParity;
aCom2Params[3].udiValue := COM.PARITY.NONE;
aCom2Params[4].udiParameterId := COM.CAA.Parameter_Constants.udiStopBits;
aCom2Params[4].udiValue := COM.ONESTOPBIT;
aCom2Params[5].udiParameterId := COM.CAA.Parameter_Constants.udiTimeout;
aCom2Params[5].udiValue := 0;
aCom2Params[6].udiParameterId := COM.CAA.Parameter_Constants.udiByteSize;
aCom2Params[6].udiValue := 8;
aCom2Params[7].udiParameterId := COM.CAA.Parameter_Constants.udiBinary;
aCom2Params[7].udiValue := 0; // false
como2.udiListLength := SIZEOF(aCom2Params)/SIZEOF(COM.PARAMETER);
como2.pParameterList := ADR(aCom2Params);
como2.xExecute := TRUE;
como2();
IF como2.xError THEN
xCom2OpenError := TRUE;
uiComState := 25;
END_IF
IF como2.xDone THEN
uiComState := 10;
END_IF
10:
comw1.hCom := como1.hCom;
comw1.pBuffer := ADR(sWrite);
comw1.szSize := 5;
comw1.xExecute := TRUE;
comw1();
IF comw1.xError THEN
xCom1WriteError := TRUE;
END_IF
IF comw1.xDone THEN
uiComState := 15;
END_IF
15:
comr2.pBuffer := ADR(sRead);
comr2.szBuffer := 25;
comr2.hCom := como2.hCom;
comr2.xExecute := TRUE;
comr2();
IF comr2.xError THEN
xCom2ReadError := TRUE;
END_IF
IF comr2.xDone OR comr2.xError THEN
IF comr2.xDone THEN
szRead := comr2.szSize;
END_IF
uiComState := 20;
END_IF
20:
comc2.hCom := como2.hCom;
comc2.xExecute := TRUE;
comc2();
IF comc2.xError THEN
xCom2CloseError := TRUE;
END_IF
IF comc2.xDone OR comc2.xError THEN
uiComState := 25;
END_IF
25:
comc1.hCom := como1.hCom;
comc1.xExecute := TRUE;
comc1();
IF comc1.xError THEN
xCom1CloseError := TRUE;
END_IF
IF comc1.xDone OR comc1.xError THEN
uiComState := 1000;
END_IF
1000:
xDone := TRUE;
ELSE
uiComState := 0;
END_CASE
Hardware handshake:
VAR
aComParams : ARRAY [1..11] OF COM.PARAMETER;
END_VAR
aComParams[1].udiParameterId := COM.CAA.Parameter_Constants.udiPort;
aComParams[1].udiValue := 1;
aComParams[2].udiParameterId := COM.CAA.Parameter_Constants.udiBaudrate;
aComParams[2].udiValue := 9600;
aComParams[3].udiParameterId := COM.CAA.Parameter_Constants.udiParity;
aComParams[3].udiValue := COM.PARITY.NONE;
aComParams[4].udiParameterId := COM.CAA.Parameter_Constants.udiStopBits;
aComParams[4].udiValue := COM.ONESTOPBIT;
aComParams[5].udiParameterId := COM.CAA.Parameter_Constants.udiTimeout;
aComParams[5].udiValue := 0;
aComParams[6].udiParameterId := COM.CAA.Parameter_Constants.udiByteSize;
aComParams[6].udiValue := 8;
aComParams[7].udiParameterId := COM.CAA.Parameter_Constants.udiBinary;
aComParams[7].udiValue := 0; // false
// Handshake Parameter
aComParams[8].udiParameterId := COM.CAA.Parameter_Constants.udiDtrControl;
aComParams[8].udiValue := 16#02; // handshake
aComParams[9].udiParameterId := COM.CAA.Parameter_Constants.udiOutxDsrFlow;
aComParams[9].udiValue := 1; // true
aComParams[10].udiParameterId := COM.CAA.Parameter_Constants.udiRtsControl;
aComParams[10].udiValue := 16#02; // handshake
aComParams[11].udiParameterId := COM.CAA.Parameter_Constants.udiOutxCtsFlow;
aComParams[11].udiValue := 1; // true
// …..
Software handshake:
VAR
aComParams : ARRAY [1..14] OF COM.PARAMETER;
END_VAR
aComParams[1].udiParameterId := COM.CAA.Parameter_Constants.udiPort;
aComParams[1].udiValue := 1;
aComParams[2].udiParameterId := COM.CAA.Parameter_Constants.udiBaudrate;
aComParams[2].udiValue := 9600;
aComParams[3].udiParameterId := COM.CAA.Parameter_Constants.udiParity;
aComParams[3].udiValue := COM.PARITY.NONE;
aComParams[4].udiParameterId := COM.CAA.Parameter_Constants.udiStopBits;
aComParams[4].udiValue := COM.ONESTOPBIT;
aComParams[5].udiParameterId := COM.CAA.Parameter_Constants.udiTimeout;
aComParams[5].udiValue := 0;
aComParams[6].udiParameterId := COM.CAA.Parameter_Constants.udiByteSize;
aComParams[6].udiValue := 8;
aComParams[7].udiParameterId := COM.CAA.Parameter_Constants.udiBinary;
aComParams[7].udiValue := 0; // false
// Handshake Parameter
aComParams[8].udiParameterId := COM.CAA.Parameter_Constants.udiInX;
aComParams[8].udiValue := 1; // true
aComParams[9].udiParameterId := COM.CAA.Parameter_Constants.udiXonChar;
aComParams[9].udiValue := 17;
aComParams[10].udiParameterId := COM.CAA.Parameter_Constants.udiXonLim;
aComParams[10].udiValue := 2048;
aComParams[11].udiParameterId := COM.CAA.Parameter_Constants.udiOutX;
aComParams[11].udiValue := 1; // true
aComParams[12].udiParameterId := COM.CAA.Parameter_Constants.udiXoffChar;
aComParams[12].udiValue := 19;
aComParams[13].udiParameterId := COM.CAA.Parameter_Constants.udiXoffLim;
aComParams[13].udiValue := 512;
aComParams[14].udiParameterId := COM.CAA.Parameter_Constants.udiTXContinueOnXoff;
aComParams[14].udiValue := 0; // false
// …..