CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Making a modbus formatted packet

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Making a modbus formatted packet
PostPosted: Thu Mar 13, 2003 4:29 pm     Reply with quote

This is a way to create a modbus formatted packet of a fixed length. This function is formatted to send 4 bytes to a memmory address. This is a good way to monitor process variables over a serial port and it uses CRC16 error checking. I pickup good ideas in this forum all the time. It just feels like time to contribute something of substance.

int8 PacketBuffer[10],x,z;
int1 FlagXOR;

PacketBuffer[0] = slave_address;
PacketBuffer[1] = Function_code;
PacketBuffer[2] = Address_lo;
PacketBuffer[3] = Address_hi;
PacketBuffer[4] = data0;
PacketBuffer[5] = data1;
PacketBuffer[6] = data2;
PacketBuffer[7] = data3;
PacketBuffer[8] = 0xff; // Prepair CRC
PacketBuffer[9] = 0xff; // Prepair CRC
for ( x=0; x < 8; x++ )
{ z = PacketBuffer[x];
PacketBuffer[8] ^= z;
for ( y = 8; y > 0; y-- )
{ FlagXOR = bit_test( PacketBuffer[8], 0 );
shift_right( &PacketBuffer[8], 2, 0 );
if ( FlagXOR )
{ PacketBuffer[8]^=0x01;
PacketBuffer[9]^=0xA0;
}
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12642
Hans Wedemeyer
Guest







Re: Modbus simulator available
PostPosted: Thu Mar 13, 2003 6:09 pm     Reply with quote

I found several simulators that generate/simulate a response as if it were a slave, but never found a master simulator.

If anyone needs an small windows app to generate modbus messages and test them via RS-232.

The program allows the user to select
SLAVE ID
MESSAGE ID
enter ASCII text
Generates check sum and send the message then wait for a response.

It will find and use any RS-232 on a Windows 2000 system, should also work on XP and NT

Program captures response from slave and displays it in Plain ASCII or Hex.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12647
Guest








PostPosted: Fri Jun 03, 2005 12:05 pm     Reply with quote

GOTO www.win-tech.com and they have demos for modbus master/slave testing and development.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group