SysComRead timeout

Carli
2008-04-13
2008-04-24
  • Carli - 2008-04-13

    Hello,

    I have problem with timeout in the "SysComRead" function.

    I send the message with COM port successfully and then I want to read the answer, but function "SysComRead" doesn't wait for setting timeout to the answer.

    How may I set this communication?

    Thank you for your help.

    Here is part of my code:

    ```

    Global variables:
       port: PORTS:=COM1;
       setting: COMSETTINGS := (Port:=COM1,
                dwBaudRate:=9600,
                byStopBits:=0,
                byParity:=0,
                dwTimeout:=5000,
                dwBufferSize:=0,
                dwScan:=0);
    Function:
       handle: DWORD;
       message: ARRAY [0..9] OF BYTE;
       handle := SysComOpen( port );     ( Open COM port )
       SysComSetSettings(dwHandle:=handle, ComSettings:=ADR(setting));     ( Setting up communication )
       SysComWrite(handle, ADR(message), 7, 5000);     ( Send message (7bytes) )
       SysComRead(handle, ADR(message), 3, 5000);     ( Read answer (3bytes) )
       SysComClose(handle);     ( Close COM port )

    ```[/code]

     
  • Carli - 2008-04-24

    Hello,

    Here is answer from CoDeSys support:

    The timeout is the time a function waits in total till it returns.

    If the function is called and no data is available then it returns immediately.

    I think you must wait until you call the read function as it seems that it takes some time till data is available.

     

Log in to post a comment.