CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

RS232 Serial communication problems
https://forum.codesys.com/viewtopic.php?f=11&t=5466
Page 1 of 1

Author:  runar@samey.is [ Mon Oct 21, 2013 11:47 am ]
Post subject:  RS232 Serial communication problems

Hi

I am new to this forum and I am just beginning to us codesys.

I am trying to get communication between berghof EC1000 and roboteq 2130. I am using 232 serial port. I am using a program I got from the codesys store ( http://store.codesys.com/serial-com.html ). I am using Codesys v3.5 SP1 Patch 4.

My problem is that I can send one message through the serial port whit out any problems, but when I try to do it again nothing happens. Then I have to logout from the project and download it again to be able to send the messages again.

Can anybody please help me with this problem?

Author:  runar@samey.is [ Wed Oct 23, 2013 5:21 pm ]
Post subject:  Re: RS232 Serial communication problems

I have tried it with and without handshake. I have also tried it without closing the port between sending messages. Here is the code I am using.



IF xStartTest THEN

//The parameters are set for the COM Port
aCom1Params[1].udiParameterId := COM.CAA_Parameter_Constants.udiPort;
aCom1Params[1].udiValue := 1; // the correct Port should be adapted
aCom1Params[2].udiParameterId := COM.CAA_Parameter_Constants.udiBaudrate;
aCom1Params[2].udiValue := 115200;
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.STOPBIT.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;

// Handshake Paramet

//aCom1Params[8].udiParameterId := COM.udiDtrControl;
//aCom1Params[8].udiValue := 16#02; // handshake
//aCom1Params[9].udiParameterId := COM.udiOutxDsrFlow;
//aCom1Params[9].udiValue := 1; // true
//aCom1Params[10].udiParameterId := COM.udiRtsControl;
//aCom1Params[10].udiValue := 16#02; // handshake
//aCom1Params[11].udiParameterId := COM.udiOutxCtsFlow;
//aCom1Params[11].udiValue := 1; // true

// Handshake Parameter

aCom1Params[8].udiParameterId := COM.udiInX;
aCom1Params[8].udiValue := 1; // true
aCom1Params[9].udiParameterId := COM.udiXonChar;
aCom1Params[9].udiValue := 17;
aCom1Params[10].udiParameterId := COM.udiXonLim;
aCom1Params[10].udiValue := 2048;
aCom1Params[11].udiParameterId := COM.udiOutX;
aCom1Params[11].udiValue := 1; // true
aCom1Params[12].udiParameterId := COM.udiXoffChar;
aCom1Params[12].udiValue := 19;
aCom1Params[13].udiParameterId := COM.udiXoffLim;
aCom1Params[13].udiValue := 512;
aCom1Params[14].udiParameterId := COM.udiTXContinueOnXoff;
aCom1Params[14].udiValue := 0; // false




END_IF


IF xPortOpen THEN
//The first Port is opened with the given parameters
como1(xExecute := TRUE, usiListLength:=SIZEOF(aCom1Params)/SIZEOF(COM.PARAMETER),pParameterList:= ADR(aCom1Params));

IF como1.xError THEN
xCom1OpenError := TRUE;
iState := 1000;
END_IF
IF como1.xDone THEN
iState := 10;
END_IF

END_IF

IF xWrite THEN
// the write process is started for the first port
comw1(xExecute := TRUE,hCom:= como1.hCom,pBuffer:= ADR(sWrite),szSize:= SIZEOF(sWrite));

IF comw1.xError THEN
xCom1WriteError := TRUE;
END_IF

// if the writing process is completed the reading process can be started
IF comw1.xDone THEN
iState := 15;
END_IF
END_IF

IF xPortClose THEN

// The first port is closed and the used handle released
comc1(xExecute := TRUE, hCom:= como1.hCom);

IF comc1.xError THEN
xCom1CloseError := TRUE;
END_IF

IF comc1.xDone OR comc1.xError THEN
iState := 1000;
END_IF
END_IF

Author:  TimvH [ Tue Oct 29, 2013 9:09 pm ]
Post subject:  Re: RS232 Serial communication problems

You call comw1 only with execute := true.
This is the trigger to start.
To trigger it again, call the FB with execute := false at least one time in between.

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/