WIP modbus write
This commit is contained in:
		@@ -65,7 +65,7 @@ int8_t modbus_copy_reply_to_buffer(uint8_t *buffer, uint8_t *msg_len, modbus_tra
 | 
			
		||||
	if (transaction->function_code | MODBUS_ERROR_FLAG) {
 | 
			
		||||
		/* sending error reply */
 | 
			
		||||
		buffer[2] = transaction->exception.exception_code;
 | 
			
		||||
	}
 | 
			
		||||
	} else {
 | 
			
		||||
		switch (transaction->function_code) {
 | 
			
		||||
			case MODBUS_READ_HOLDING_REGISTERS:
 | 
			
		||||
			case MODBUS_READ_INPUT_REGISTERS:
 | 
			
		||||
@@ -79,6 +79,14 @@ int8_t modbus_copy_reply_to_buffer(uint8_t *buffer, uint8_t *msg_len, modbus_tra
 | 
			
		||||
					buffer[4 + 2*i] = transaction->buffer16b[i] & 0xff;
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
			case MODBUS_WRITE_SINGLE_REGISTER:
 | 
			
		||||
				buffer[2] = (uint8_t) (transaction->register_address >> 8);
 | 
			
		||||
				buffer[3] = (uint8_t) transaction->register_address;
 | 
			
		||||
				buffer[4] = (uint8_t) (transaction->holding_registers[0] >> 8);
 | 
			
		||||
				buffer[5] = (uint8_t) transaction->holding_registers[0];
 | 
			
		||||
				*msg_len = 8;
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	crc16 = modbus_CRC16(buffer, *msg_len - 2); /* last two bytes is the checksum itself */
 | 
			
		||||
	buffer[*msg_len - 2] = crc16 & 0xff;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user