View previous topic :: View next topic |
Author |
Message |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Making a modbus formatted packet |
Posted: Thu Mar 13, 2003 4:29 pm |
|
|
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 |
Posted: Thu Mar 13, 2003 6:09 pm |
|
|
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
|
|
Posted: Fri Jun 03, 2005 12:05 pm |
|
|
GOTO www.win-tech.com and they have demos for modbus master/slave testing and development. |
|
|
|