USB RS232 adapter

Dear ctrlX Community!

 

We would like to connect several Keyence scanner to ctrlX Core via USB RS232 adapter.

I successfully sent and received data in node-RED (with /dev/ttyUSB0 path), but we need to use this solution in PLC runtime.

I tried to open the serial port with SysCom library without any success.

Is there any possibility to handle the USB RS232 adapter in the PLC environment?

 

Thanks in advance!

 

Best reply by TheCodeCaptain

Hi 8run0tti,

we implemented the support from version 1.16 on.

Find here some example code.

PROGRAM PLC_PRG
VAR	
	result		:	Syscom.RTS_IEC_RESULT;
	handle		:	Syscom.RTS_IEC_HANDLE;
	settings	:	Syscom.SysComSettings;
	bDone		:	BOOL;
	arByte		:	ARRAY[0..99]	OF	BYTE;
	udiReturn	:	UDINT;
	iState		:	INT	:=	0;
END_VAR

 

settings.sPort		:=	SYS_COMPORT1;
settings.ulBaudrate	:=	SYS_BR_4800;
settings.byParity	:=	SYS_NOPARITY;
settings.byStopBits	:=	SYS_ONESTOPBIT;

CASE iState OF

0:
	IF NOT bDone THEN
		handle := Syscom.SysComOpen2(
						pSettings:= ADR(settings),
						pSettingsEx:= 0,
						pResult:= ADR(result));
		bDone := TRUE;
		iState:= 10;
	END_IF

10:
	udiReturn := Syscom.SysComRead(
		hCom:= handle, 
		pbyBuffer:= ADR(arByte), 
		ulSize:= SIZEOF(arByte), 
		ulTimeout:= 0, 
		pResult:= ADR(result));
	
END_CASE
View original
7 replies