Home > Forum > Discussions on general problems > String parsing from serial port
- This topic has 2 replies, 2 participants and was last updated 1 year, 10 months ago da Stefano.
-
AuthorPost
-
May 20, 2022 at 3: 54 pm #65318StefanoParticipant
I have to interface an old press to an SCADA to monitor its operation.
The press gives me 4 clean contacts with the signals:- Cycle in progress
- Automatic operation
- Manual operation
- Stop due to alarmit also has a serial port, to which a text-only printer should be connected, which at the end of each cycle outputs a string containing about ten operating values and a new line character. So something like:
"1.33 84.9 7893 22.5 6.74 etc. etc."
"1.93 87.4 7894 23.5 6.94 etc. etc."Strings are always 80 characters long, values would appear to be right-aligned fixed-width fields.
I should acquire the digital values and make them available on a word via modbus TCP, which is quite trivial. At the same time, read the string from the serial line up to the end of line character, discard the invalid lines (when the machine calculates that it is on a new sheet, it emits the column headings and dashes), divide the fields, convert them from text to number and make them available via modbus. Maybe save the strings received on a text file for debugging.
I was thinking of using an MPS056A320.
The idea was to do a loop that reads one character at a time from the serial and appends it to a buffer. Once you reach the 80 characters, or the newline character, divide the string into X strings of dimension Yx and convert them with SysVarsscanf. If SysVarsscanf does not give errors then copy the data to the locations reachable by modbus.
The approach is a bit low-level but it feels quite robust to me.
Are there more advanced libraries that escape me?May 23, 2022 at 10: 29 am #65321Sergio BertanaAdministrator ForumI would say that it is the best solution, if you take a look at the chapter Semplice protocollo seriale in the FB documentation SysSerialPort, you already find a starting point for your application.
June 8, 2022 at 11: 28 am #65484StefanoParticipantTo debug the application it would be useful to have a web page that shows the log of the strings arrived via serial. Exactly what the system web page that shows logs does. Is there a standard way to replicate it leaning against a different text file?
-
AuthorPost
- You must be logged in to reply to this topic.