Modbus slave source code

Y

Thread Starter

yu jian

Hello.

I'm looking for the source code (in C) of MODBUS slave protocol. My PC runs on Windows platform. Does anyone have an idea or link for that? Would you please send it to my email:[email protected]

Thanks in advance!
 
Dude, that`s pretty easy. Try to get the standard of the protocol. I did that and in a few hours worked fine. Try this:

int address, function, register, quantity

address=incomingframe[0]
function=incomingframe[1]
register=(int)(incomingframe[2]+incomingframe[3])
quantity=(int)(incomingframe[4]+incomingframe[5])

if addres==myAddress then
select case function

case 0: break;
case 1:
case 2:
//send data required by register and quantity
case 3:
case 4:
//send data required by register and quantity
case 6:
//write single register

case 15:
//write multiple coils, mask found within message

case 16:
//write multiple holdings, asi sent in incoming message

end case;
endif;

good luck.
 
Top