Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Two libraries for COM port. Which is better to use?

chab
2013-05-07
2021-03-11
  • chab - 2013-05-07

    For serial communication, via the COM port, several libraries are available:
    - SysCom
    - Serial Communication (includes CAA SerialCom)
    Both libraries have APIs that are similar: open, close, read and write. SysCom has some more extra functions.

    Which library is the most suitable?

    Regards,
    Edwin.

    IMG: ComPortLib_03.JPG

     
  • Strucc - 2013-05-07

    A very subjective answer:

    I prefer to use the "old" SysLibCom. Many reasons:
    - I myself develop libraries, with different solutions for assyncronousity
    - The way to provide parameters to CAA Serial library is really frustrating (you can't do that in the declaration part)
    - I don't use any very special features of the com port, I mostly run with basic settings

    The reason to use CAA or more sophisticated libraries could be:
    - Uniformity (standard behavior modell)
    - Even more platform independency

    In my case I didn't see any advantage of those (once again, I'm developing libraries), but I had problems with the standard behavior model (for example executing multiple single byte read operation within one task cycle), so I returned to the "roots"

    What I'd really like to see from 3S is a total platform independent serial (and socket) communication library. What I mean here (it's mostly for sockets) is where the Open, Connect, etc... functions return the same results, and take the same parameters on each platforms. But, nothing else fancy added to them! If I'd like to go async, then I use select... etc. It's a more common, and more documented practice, than learning a new library, and guessing what is behind....

     
  • mravlincek - 2016-09-26

    Hello!

    I'm trying to use the syslibcom library for the first time. I can sort of understand the general principle of how things work, but I am stuck at the very begging I am using ST and I cannot get past this error: "Error 4012: PLC_PRG (2): Type mismatch in parameter 'ComSettings' of 'SYSCOMSETTINGS': Cannot convert 'ComSettings' to 'POINTER TO COMSETTINGS'.

    If someone would be so kind to write a simple example in ST of how to use this library to communicate via RS232 just to listen to the port and write the data that comes through.

     
  • mravlincek - 2016-09-27

    Update: OK so it seems I have figured out a few things myself. Mostly I have problems with me beeing used to V3 and trying to work with V2 Codesys

    So I have discovered a new problem. The SysComOpen always returns 0xFFFFFFFF no matter which port I try to open for my XVS440. The code is this:

    opencomport:=TRUE;
    bread:=TRUE;
    IF opencomport=TRUE THEN
       dwcomhandle:=SysComOpen(com1);
    IF dwcomhandle=16#FFFFFFFF THEN bcomportopened:=TRUE;
    END_IF
    END_IF
    

    and it always sets the bcomportopened to TRUE? It seems that I am doing something wrong, or maybe the port isn't working? This is for RS232 right?

     
  • Anonymous - 2016-09-27

    Originally created by: KevinR

    Hello mravlincek,

    you better use the SysComOpen2 function. It gives you the opportunity to use extended settings, for example ByteSize option.
    To check if the ComPort is open, use the RTS Handle. (Invalid Handle = RTS_INVALID_HANDLE)

    Quick and dirty example:

       VAR 
          dwcomhandle : SysCom.RTS_IEC_HANDLE;
          xState : BOOL;
       END_VAR
    
    IF NOT(xState) THEN
       SysComOpen2(ADR(ComSettingsBasic), ADR(ComSettingsAdvanced), ADR(Result)); // Call the Function SysComOpen2 Only once! 
    ELSE
       ;
    END_IF
    IF dwcomhandle= SYSTYPES.RTS_INVALID_HANDLE THEN
       xState := FALSE; // still closed 
    ELSE
       xState := TRUE; // open
    END_IF
    

    Best Regards,
    Kevin

     
  • mravlincek - 2016-09-27

    Thanks for your reply. I had a feeling that this library would be better, but unfortunately the entire project is already created in Codesys V2. And as far as I can see, there is no SysComOpen2 library there (I might be wrong?)

    EDIT: But still, it is strange that I always get an error (FFFFFFFF) by just opening port COM1 (or even any other port number).

     
  • mravlincek - 2016-09-28

    An update to any future similar problems. The connection is now working, but I have a problem with the data that is recieved. The device that is sending data to the PLC, sends a string of 80 ASCII characters, but what I recieve on my PLC is only the carriage return (and if set also line feed). I guess I need more information on how to correctly set the SysComRead, I'm guessing it's a problem of dwBufferAddress and dwBytesToRead.

    If anyone knows how to set these two parameters (or maybe it's something completely different) please let me know

    EDIT: I chose a completely different library that is a lot more user-friendly and it is very easy to use the RS232 ports. The library in question is COMuser, it's a bit tricky to find online but if you know someone in automation, they can provide it to you.

     
  • spsschorsch - 2021-03-11

    Hi mravlincek

    you're referring to exactly that library COMuser, which I need for changing an old plc project. But it is not installed with my CoDeSys.
    As you said, it's tricky to find.
    Do you know a source, where I could find it?
    Or maybe you could provide me with it?
    Sadly the original engineer who could provide is not available for me....

    Regards
    Georg

     

Log in to post a comment.