Writing a text file into a PLC via Modbus


Recommended Posts

Hello !

I would like to know if DAQFactory allows to "write" into the modbus registers of a PLC, using a text file ( txt, csv, xls, etc) ??

I mean... clicking into a button on the DAQ Factory, automatically browse for a file,transfer it to the PLC, the file would have 2 columns, one with the modbus address and the other with the information to be written into the PLC?

I hope I

Link to comment
Share on other sites

Sure. I'm going to do this off the cuff, so post if your run into problems:

1) create your button. Select the Quick Sequence action and enter code like this to ask the user for the file:

private string filename = file.fileopendialog()  // there are parameters here if you want, see the help
if (!isempty(filename))
   global string importfilename = filename

You want to do beginseq() so the setting of the modbus registers is done in the background, otherwise DAQFactory will essentially hang while it does all the modbus queries. Note that sequences started this way don't take parameters, so I used a global variable for the filename.

2) create a sequence called importdata. Script is something like this:

// read file
private handle = file.open(importfilename,1,0,0,1)
private datain = file.readdelim(handle, -1, ",", chr(10), 0)

// set registers (assume address in col 0, value in col 1)
for (private x = 0, x < numrows(datain), x++)

That's about it. Its actually quite simple, though I didn't put any error handling in.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.