Omron Cpm1A Hostlink Comms


Tex

Recommended Posts

Hi, I'd like to connect an Omron CPM1A PLC to DF using the serial connection, which I believe uses Hostlink protocol. Is there a DF protocol that will work with this? If not could I get an example of how to set up a custom connection please. I am fairly new at the comms side of things. Thanks.

Link to comment
Share on other sites

DAQFactory doesn't support hostlink natively.  You could use an OPC server, or contact you Omron dealer to see if there is a Modbus option for that PLC.  The Omron site didn't specify the protocols available.  Hostlink is not a particularly complicated protocol, but does require a XOR CRC so you'll have to do a little math in your script.  As for custom connections, I recommend creating a device with a NULL protocol and then using sequence script to communicate with the device.  It is much easier to debug sequences than a DAQFactory custom protocol.  Once you have it debugged you can move the script to the custom protocol if you want, but depending on your application it may not be necessary.  In general you'll want to use a combination of purge(), read()/readuntil() and write() to communicate with the port.  There are examples here on the forum.

 

Sending a command might look something like this (assuming you created a serial device called Omron with NULL protocol:

function pollOmron(id, string header, string data)

private string in
private string out

try
device.omron.purge()
device.omron.write(chr(5))
in = device.omron.read(1)
if (in == chr(5))
   // proceed:
   out = "@" + format("%02X", id) + Header + data
   out += calcFCS(out)
   out += "*" + chr(13)
   device.omron.write(out)
   in = device.omron.readUntil(13)
   // process data
endif

You'll need to create a function to calc the FCS.  Its probably something close to:

function calcFSC(string out)
   private data = asca(out)
   private result = data[0]
   for (private x = 1, x < numrows(data), x++)
      result = result # data[i]
   endfor
   return(format("%02X", result & 0xff))
   

Finally, in the part I marked process data, you'll need to write some script to process the data coming in from the device.  You can either work with it as a string, or use asca() to convert to an array of bytes.  Given that the protocol is ASCII, I'd stick with a string, using the mid() function to pull out sections, and then use strToDouble() to convert any portions to numbers.  Since the protocol uses hex throughout, you'll want to add "0x" to the string before converting.  So if you have a number in the 6th through 9th byte of the response in hex format, to convert to a number you'd do something like:

private val = strToDouble("0x" + mid(in, 5,4))

Note that I'm doing this totally off the cuff, so you might need to debug / edit my script a little to get it to work.  Once you do get it to work, please share your result here in the forum!

Link to comment
Share on other sites

Archived

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