Serial communication Beckhoff CX2030

Akram Louati

Level-1
Beiträge
5
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hi,
I'm a new user of the Beckhoff plc. I'm trying to communicate with a device using the serial communication by sending a string. I'm using the library tc2.SerialCom and twincat 3. I created a function block as follows:
Code:
FUNCTION_BLOCK FB_SerialCom
VAR_IN_OUT
 TxBuffer : ComBuffer;
END_VAR
VAR
  Send_String :Sendstring;
END_VAR
VAR_OUTPUT
  bSendBusy : BOOL;
  eSendErrorID : ComError_t;
END_VAR
Code:
 Send_String(
 SendString := '%R1Q,9027:1.0,1.0,0,1,0\r\n\n',
 TXbuffer := TxBuffer,
 Busy => bSendBusy,
 Error => eSendErrorID);

and I did the the Background communication in the main program as follows:
Code:
PROGRAM MAIN
VAR
 stIn_PcCom AT %I* : PcComInData; (* linked to the port in the TwinCAT System Manager *)
 stOut_PcCom AT %Q* : PcComOutData; (* linked to the port in the TwinCAT System Manager *)
 TxBufferPcCom : ComBuffer;
 RxBufferPcCom : ComBuffer;
 
   (* background communication with the PC COM port device *)
    fbPcComCtrl       : SerialLineControl;
    bPcComCtrlError   : BOOL;
    ePcComCtrlErrorID : ComError_t;
END_VAR

Code:
fbPcComCtrl(
    Mode      := SERIALLINEMODE_PC_COM_PORT, 
    pComIn    := ADR(stIn_PcCom), 
    pComOut   := ADR(stOut_PcCom), 
    SizeComIn := SIZEOF(stIn_PcCom), 
    Error     => bPcComCtrlError, 
    ErrorID   => ePcComCtrlErrorID, 
    TxBuffer  := TxBufferPcCom, 
    RxBuffer  := RxBufferPcCom );

The parameter Busy is false but nothing is coming to the device. What could be the reason for that?
Thank you in advance.
 
Zuletzt bearbeitet:
At the outputs of the device in the IO node you don't see any changes?
In your example there is no instance created of your FB FB_SerialCom and the FB isn't called, where is this done?
 
Zuviel Werbung?
-> Hier kostenlos registrieren
This was my first fault. now I called
FB_SerialCom in the main. The parameter Busy stays always TRUE and the Error is : COMERROR_TXBUFFOVERRUN. I don't see any changes in the output.
 
Hier is the PROGRAM MAIN now:
Code:
PROGRAM MAIN
VAR
  stIn_PcCom AT %I* : PcComInData; (* linked to the port in the TwinCAT System Manager *)
  stOut_PcCom AT %Q* : PcComOutData; (* linked to the port in the TwinCAT System Manager *)
  TxBufferPcCom : ComBuffer;
  RxBufferPcCom : ComBuffer;
 
  Serial:FB_SerialCom;

   (* background communication with the PC COM port device *)
    fbPcComCtrl       : SerialLineControl;
    bPcComCtrlError   : BOOL;
    ePcComCtrlErrorID : ComError_t;
END_VAR

Code:
fbPcComCtrl(
    Mode      := SERIALLINEMODE_PC_COM_PORT, 
    pComIn    := ADR(stIn_PcCom), 
    pComOut   := ADR(stOut_PcCom), 
    SizeComIn := SIZEOF(stIn_PcCom), 
    Error     => bPcComCtrlError, 
    ErrorID   => ePcComCtrlErrorID, 
    TxBuffer  := TxBufferPcCom, 
    RxBuffer  := RxBufferPcCom );
 
 Serial(TxBuffer:=TxBufferPcCom);
 
Zurück
Oben