|  |  | @ -18,7 +18,6 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "mqtt.h" |  |  |  | #include "mqtt.h" | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "modbus.h" |  |  |  | #include "modbus.h" | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "modbus-master.h" |  |  |  | #include "modbus-master.h" | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "modbus_io_slave.h" |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "util/delay.h" |  |  |  | #include "util/delay.h" | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -136,6 +135,71 @@ void send_values(void){ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | void modbus_set_Output(uint8_t slave_adr, uint8_t nr, uint8_t state) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   switch (state) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     case BLINK: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //ioHelperSetBit(outStatesBlinking,  nr,  ON);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         writeCoil(slave_adr,100+nr,1); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         wait_write(10); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //case TOGGLE:
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //  ioHelperSetBit(outStatesBlinking,  nr,  OFF);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //  if (ioHelperReadBit(outStates, nr)) {
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //    ioHelperSetBit(outStates,  nr,  OFF);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //  } else {
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //    ioHelperSetBit(outStates,  nr,  ON);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //  }
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //  break;
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     case ON: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       //ioHelperSetBit(outStates,  nr,  ON);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       //ioHelperSetBit(outStatesBlinking,  nr,  OFF);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         writeCoil(slave_adr,nr,1); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         wait_write(10); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     case OFF: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         writeCoil(slave_adr,nr,0); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         wait_write(10); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       //ioHelperSetBit(outStates,  nr,  OFF);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       //ioHelperSetBit(outStatesBlinking,  nr,  OFF);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | uint8_t modbus_read_Input(uint8_t nr, uint8_t type) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   uint8_t state = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   switch (type) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     case LEVEL: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       state = ioHelperReadBit(inStates, nr); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     case EDGE: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       state = ioHelperReadBit(inStatesBothEdges, nr); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       ioHelperSetBit(inStatesBothEdges,  nr,  0); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     case RISING: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       state = ioHelperReadBit(inStatesRisingEdge, nr); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       ioHelperSetBit(inStatesRisingEdge,  nr,  0); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     case FALLING: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       state = ioHelperReadBit(inStatesFallingEdge, nr); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       ioHelperSetBit(inStatesFallingEdge,  nr,  0); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   //reset edges after being read once
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   // if (state) {
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   //   if (type == EDGE)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   //     ioHelperSetBit(inStatesBothEdges,  nr,  OFF);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   //   if (type == RISING)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   //     ioHelperSetBit(inStatesRisingEdge,  nr,  OFF);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   //   if (type == FALLING)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   //     ioHelperSetBit(inStatesFallingEdge,  nr,  OFF);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   // }
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   return state; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | int main(){ |  |  |  | int main(){ | 
			
		
	
		
		
			
				
					
					|  |  |  |     // INIT MCU
 |  |  |  |     // INIT MCU
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     avr_init(); |  |  |  |     avr_init(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -196,7 +260,6 @@ int main(){ | 
			
		
	
		
		
			
				
					
					|  |  |  |     uint32_t timer_blink_outs = millis(); |  |  |  |     uint32_t timer_blink_outs = millis(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     uint32_t timer_send_uptime = millis(); |  |  |  |     uint32_t timer_send_uptime = millis(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     uint32_t timer_send_info = millis(); |  |  |  |     uint32_t timer_send_info = millis(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     uint32_t timer_read_slave = millis(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     //printf("anlage: %x\n\r", read_Input(IN_ANLAGE_EIN_INV, LEVEL));
 |  |  |  |     //printf("anlage: %x\n\r", read_Input(IN_ANLAGE_EIN_INV, LEVEL));
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -219,34 +282,20 @@ int main(){ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             do_kraftsensor(); |  |  |  |             do_kraftsensor(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | #if PLC_MQTT_ENABLED |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             char msg[64]; |  |  |  |             char msg[64]; | 
			
		
	
		
		
			
				
					
					|  |  |  |             sprintf(msg, "%d", kraftsensor_value); |  |  |  |             sprintf(msg, "%d", kraftsensor_value); | 
			
		
	
		
		
			
				
					
					|  |  |  |             mqtt_pub(&mqtt_client, "/Filamentanlage/01_Extruder/kraft", msg, strlen(msg)); |  |  |  |             mqtt_pub(&mqtt_client, "/Filamentanlage/01_Extruder/kraft", msg, strlen(msg)); | 
			
		
	
		
		
			
				
					
					|  |  |  | #endif |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             modbus_io_set_Output(4, 0, TOGGLE); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if(millis() - timer_read_slave > 100){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             timer_read_slave = millis(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             //readInputState(4, 200, 32);
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             modbus_io_read(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             if(modbus_io_read_Input(16, RISING)) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 modbus_io_set_Output(4, 3, ON); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             if(modbus_io_read_Input(17, RISING)) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 modbus_io_set_Output(4, 3, OFF); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //tgl ^= 0x01;
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //modbus_set_Output(4, 0, OFF);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //modbus_set_Output(4, 1, ON);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //modbus_set_Output(4, 2, BLINK);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //modbus_set_Output(4, 3, tgl);
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             //printf("read inputs: 0x%02X 0x%02X 0x%02X 0x%02X\n", inp[3], inp[2], inp[1], inp[0]);
 |  |  |  |             //readInputReg(4, 0, 1);
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |             //uint16_t inp;
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |             //wait_receive(1, &inp, 100);
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if(read_Input(BTN_HEIZEN_AN, RISING)){ |  |  |  |             //printf("read inputs: 0x%X\n", inp);
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             modbus_io_set_Output(4, MOD_OUT_HEIZEN_LED, 1); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if(read_Input(BTN_HEIZEN_AUS, RISING)){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             modbus_io_set_Output(4, MOD_OUT_HEIZEN_LED, 0); |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | #if PLC_MQTT_ENABLED |  |  |  | #if PLC_MQTT_ENABLED | 
			
		
	
	
		
		
			
				
					|  |  | 
 |