Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

Log in or register to post/reply in the forum.

ModbusMaster Instruction

oceanographer Aug 20, 2012 05:50 PM

I'm trying to integrate a K-30 CO2 (co2meter.com) sensor into my CR1000 setup. This is a polled hexadecimal sensor. I think the instruction needs to be something like this:

Modbusmaster (Result,COM1,9600,0,4,CO2_hex,3,1,3,100,2)

Where Result and CO2_hex are both variables, but I probably have them formatted as the wrong thing.

I have the sensor's RxD and TxD wired into C1/C2 correctly. The sensor address according to the manual is FE (or 254), but 0 should just broadcast to any sensor, and since the only one connected is my K-30, it is my understanding this should work. I need to use function 04, to read input registers. Do I need to use the SerialOpen command preceeding this? What about the hexadecimal conversions for the commands? Thanks.


Sam Aug 26, 2012 05:30 PM

From the sensor ModBus guide, "addressing rules", available from co2meter.com:
"No broadcast *commands* currently implemented"

Using the first example in Appendix A for "CO2 Read Sequence", it seems to me that your ModbusMaster instruction should be

Public Result As Float
Public CO2 As Long
ModBusMaster (Result,COM1,9600,254,4,CO2,4,1,3,100,1)

This instruction will query sensor 254 on COM1 at 9600 baud using "read input registers". It is requesting input register 4, length of 1. One register is 2 bytes / 16 bits. Something that can be confusing about ModBus is "register number" vs "address". Register numbering starts at 1; i.e. they are numbered 1,2,3... Addressing starts at 0; i.e. registers are addressed 0,1,2,3... So register 4 has a start address of 3. The value you are after is in register 4 / address 3.

Want to watch it action?

Program your logger to run the ModBusMaster instruction every 20 seconds.

Public Result As Float
Public CO2 As Long
Scan (20,Sec,3,0)
ModBusMaster (Result,COM1,9600,254,4,CO2,4,1,3,100,1)

Then connect to your logger with a terminal emulator like HyperTerm or Terminal Emulator included with LN. Then hit enter a few times to get the CR1000> prompt. Then enter W. Enter 9 (for COM1). Set a timeout and ask that the traffic be display in HEX. Every 20 seconds you will see the logger send out the request. If things are connected/configured correctly you will see the sensor respond. The interaction should look like the CO2 sensor Modbus guide lays it out. Something like

T: FE 04 00 03 00 01 D5 C5
R: FE 04 02 01 90 AC D8

AdamPFR Oct 9, 2020 05:07 AM

haydenmh Dec 1, 2021 04:10 PM

This post is under review.

Log in or register to post/reply in the forum.