Hello,
I created a working MySQL database connector using AsTCP and some homemade libraries in C.
The reason for creating this was to avoid having to run the python script on the PC with the database. The python connector only supports 1 PLC at a time and is another thing you have to make sure is running when you start the PC/server. I’ve tested this and got it fully functioning, but it looks like I may never get to use it as my employer wants to go a different direction for the project that I developed it for.
To run it, you just need to create a task with all of the files included, declare variables of the UNI_MYSQL_PUB_typ type and UNI_MYSQL_typ type, then run the init function (not in the _INIT as it may need more than 1 scan to complete), call the configuration functions to setup the login for the database, set a timeout, then cyclically call the Cycle function. This task will be responsible for handling queries generated by other tasks and managing the connection.
Tasks outside of the one running the connection may use the public query function to get/send data to/from the database. The task will need a simple state machine in which the first state is calling the query function with a pointer to the public datatype, passes a string for the name of the semaphore holder (can be anything, just to keep track of who/what is using the database connection), a query string (same as you would enter in MySQL workbench), and a pointer to a variable of UNI_MYSQL_RETURN_DATA_typ type. This will be where the array of STRINGs returned from a SELECT statement will go. After executing the query, move to the next state where it’ll wait for the return data and then you can parse it out however you’d like.
That is a very simple explanation, but if anybody has any questions, I’d be happy to answer them.
I haven’t seen anybody else share anything like it so I thought I would. If anybody wants to try it out or has a practical application for it and wants me to send them an example let me know!