open file in simulation mode

Dario
2006-07-04
2011-03-24
  • Dario

    Dario - 2006-07-04

    Hi Developers,

    For testing purposes I need to open a file while my application is running in using .

    The file is in the same folder of the project *.pro but always returns 0.

    Is it possible to open a file or I need to be connect on a real target?

    Best regards

    Daeio

     
  • Erik Böhm

    Erik Böhm - 2006-07-06

    Hi

    Sorry, but the SysFileLib functions do not work in Simulation mode.

    Best regards

    Erik

     
  • ventas3

    ventas3 - 2011-03-09

    Hi,
    i would wanna know if you can show me some e.g. for syslibfile.. i understand that not work on online mode... wherever, i wanna be sure about how to use it because i need create a file for store a value from a variable. and a need writte the value into a .txt... thanks.. can you help me? i'm sorry for my english.

     
  • Anonymous - 2011-03-10

    Originally created by: Mikhail Shvetsov

    If i understood you correctly, the examples below can help you. But this example is on Russia, but you can use Google-translate, or look at code. It's pretty understandable. There are too much explanations, but you need part below line "*" after fig 3.
    http://forum-ru.3s-software.com/viewtop ... 1584#p1584 m

     
  • Erik Böhm

    Erik Böhm - 2011-03-10

    Hi
    Did you read the CoDeSys documentation to SysLibFile ?
    Everything you need is described there.

    Erik

     
  • ventas3

    ventas3 - 2011-03-10

    excuse me but, if i use OPC server it's not easier? the example in russ is so good!. but, does not work...

     
  • Erik Böhm

    Erik Böhm - 2011-03-11

    What do you want ?
    Write into a .txt, or use OPC ?
    Thats 2 different things...
    Writing in a file is very easy.

    Erik

     
  • ventas3

    ventas3 - 2011-03-11

    I really want to get the value from a global variable of codesys, then to safe that values into a .txt file; but i don't know if using OPC would be easier for that, that was my question about OPC. but, please if you can help me to make that, i will be thankful.

     
  • Erik Böhm

    Erik Böhm - 2011-03-11

    Try this:

    FUNCTION_BLOCK WriteValueToFile_FB
    VAR_INPUT
    strFileName: STRING(255);
    strDataBuffer: STRING(255);
    END_VAR
    VAR_OUTPUT
    bDone: BOOL;
    bError: BOOL;
    wErrorID: WORD;
    END_VAR
    VAR
    dwBytesWritten: DWORD;
    dwFileWrite: DWORD := 0;
    END_VAR


    dwFileWrite := SysFileOpen(FileName:=strFileName, Mode:='a');

    IF dwFileWrite = 0 THEN (error: file couldn't be opened )
    bError := TRUE;
    wErrorID := 1;
    RETURN;
    END_IF

    dwBytesWritten := SysFileWrite(File:=dwFileWrite, Buffer:=ADR(strDataBuffer), Size:=LEN(strDataBuffer));

    IF dwBytesWritten = LEN(strDataBuffer) THEN
    bDone := TRUE;
    SysFileClose(dwFileWrite);
    dwFileWrite := 0;
    ELSE
    bDone := FALSE;
    SysFileClose(dwFileWrite);
    dwFileWrite := 0;
    END_IF

     
  • ventas3

    ventas3 - 2011-03-11

    Thanks for your code. I wonder if the error is due to the way I'm stating the name of the file, because I am stating this: strFileName: STRING (255): = 'c: / data / mylog.txt', the results from strDataBuffer is 0 I think it can be because I'm in simulation mode and I understand that you can have conflicts, have you any idea how to see the results? The PLC I'm using is a MFD4-5-XRC-30. If only work connected with the PC or does will lack the MMC?

    strFileName: STRING (255): = 'c: / data / mylog.txt';
    

    the results are:

    IMG: Dibujok.JPG

    IMG: Dibujo.JPG

     
  • Erik Böhm

    Erik Böhm - 2011-03-14

    Hi
    As usual, SysLibs do not work in Simulation mode.
    There is no Hardware selected, so there are no SysLibs...

    Erik

     
  • Anonymous - 2011-03-14

    Originally created by: Mikhail Shvetsov

    ventas3 hat geschrieben:
    excuse me but, if i use OPC server it's not easier? the example in russ is so good!. but, does not work...

    All examples were checked out many times by a lot of peoples. Just believe me, i know it:) Theres a lot of peculiarities which isn't showed on figures but explained in text, and you probably miss them. But you can ask me about problem with it.I'll reply.

    i attached very simple project (special for you from Russia with love ). This one is written for PLCWinNT. Start the program and change "Start" variable to TRUE.
    It write the string WriteBuffer into file on drive "D" (you should fix it if you don't have drive D) and read it to string ReadBuffer.

    It works well

    WriteReadFile.pro [32.43 KiB]

     
  • ventas3

    ventas3 - 2011-03-14

    [quote= It works well [/quote]

    Muchisimas Gracias a todos!... Thank you very much for your help...! I discovered that the problem I had was when the file name. Should be done according to the specified path when you enter the command files..! ie OpenFile1: = SysFileOpen ('\ disk_sys \ project \ File1', 'r ');

     
  • Anonymous - 2011-03-16

    Originally created by: Mikhail Shvetsov

    ventas3 hat geschrieben:
    Muchisimas Gracias a todos!... Thank you very much for your help...!..

    Да всегда пожалуйста - it means - You are always welcome!

     
  • ventas3

    ventas3 - 2011-03-24

    Mikhail Shvetsov hat geschrieben:
    If i understood you correctly....

    Hello my friend. I've a question, i hope you can help me please, in advance apologize the inconvenience...
    i try to connecting my PLC easyHMI MFD4 to a sensor with a Ethernet interface but, i'm using syslibsocket library, not possible.. can you help me to do? first i connect my plc with a java application make for me, the program java it's fine. i can do connect, but i can not write or read data from PLC. if i can to do that, i can do it between PLC and Sensor... Thank you!.

    Servidor means SERVER, CONECTAR: connect, esperando conexion: waiting for connection, conexion 1 recibida de: connection 1 recieve from

    IMG: Dibujo.JPG

     

Log in to post a comment.