Vai al contenuto

How to write a file by using a simple serial connection

Home Forum Controllori SlimLine e Netsyst (LogicLab) How to write a file by using a simple serial connection

Stai visualizzando 2 post - dal 1 a 2 (di 2 totali)
  • Autore
    Post
  • #35291
    Kostas
    Partecipante

    I’m using a program that operates on a csv file on Storage memory. At the moment I’m using a SlimLine CPU module with ethernet, and I write the file by using an FTP access to the module. I’m thinking to use a SlimLine Lite CPU module and to do this I need to write the file by using a serial connection.

    My idea is to read the serial port until a special character is received, for example “^”, and then open the local file in write mode and write on it everything is received until another special character like “$”. I am trying to implement it but I have some questions:

    1: If I have a buffer for incoming data, is it preserved through each running loop of the function block ?
    2: Since I don’t know the required length of the buffer, how can I enlarge it when I get more data ?
    3: When I try to write the data to the file, is there a possibility of a conflict with the other function block that reads the file ? How can I prevent it ? Is there some kind of locking mechanism ?

    Is it possible to have an example program that executes something like my needs ?

    #37462
    Sergio Bertana
    Amministratore del forum

    Premised that is simpliest to use the FTP connection to operate over the files, anyway your idea could be a good solution if you need only to write the file, copying it from a PC. A CSV file can be edited by a standard text editor and this allow to add the “^” character at the begin and “$” character at the end of CSV data. Then some simple terminal emulation programs (Ie Toolly), allow to send the file over the serial line. About your questions.

    SlimLine has a 256 bytes buffer the serial line incoming characters (One buffer for each serial port). So the received characters are automatically stored on it and preserved through the running loop. The program has to check if some characters are arrived and transfer them from the incoming buffer to the file. The buffer capability is enough to give time at the program to transfer the characters without the risk of loosing some of them.

    There’s no locking mechanism on the file, when the program rewrites the file with the new data incoming from the serial line, all the others operations on the same file must be stopped.

    I’ve developed a simple program that meet your needs (Program print, Source code).

Stai visualizzando 2 post - dal 1 a 2 (di 2 totali)
  • Devi essere connesso per rispondere a questo topic.