| Electronic Components Datasheet Search |
|
CT-N Datasheet(PDF) 4 Page - DIWELL Electronics Co., Ltd. |
|
|
|||||||||||||||||||||||||||||
CT-N Datasheet(HTML) 4 Page - DIWELL Electronics Co., Ltd. |
|
4 / 5 page ![]() CT-N Series Specification Compact Non-contact Infrared Thermometer Page 4 of 5 1.0.1 - Sample Code #include <MsTimer2.h> // Timer library. #include <ModbusRtu.h> // Modbus library. #include "SoftwareSerial.h" // SoftwareSerial library #define DISABLE 0 #define ENABLE 1 #define DE_RE 2 #define USING_SOFTWARESERIAL 4 #define ID 1 int8_t Timer_Flag = 0, Data_Print = DISABLE; uint16_t au16data[2]; int16_t Object, Ambient; SoftwareSerial mySerial(3, 5); // RX 3, TX 5 Modbus master(0,USING_SOFTWARESERIAL,DE_RE); // Modbus Master, 4:Using SoftwareSerial , DE/RE 2 modbus_t telegram; // Master query structure void setup() { Serial.begin(9600); // for Serial Monitor (Ctrl + Shift + M ) master.begin(&mySerial, 19200); // begin the ModBus object. master.setTimeOut( 25 ); // Modbus timeout : 25 ms Serial.println("Waiting for sensor initialization time"); delay(1000); // Wait for sensor initialization time MsTimer2::set(500, timerISR); // Timer interval : 500ms. MsTimer2::start(); // Timer Start } void loop() { if(Timer_Flag) { // Check timer interrupt Timer_Flag = 0; Transfer_Data(ID); // Request data transmission : Timer cycle } if(master.getState() == COM_WAITING) { // Get modbus master state : waiting for answer master.poll(); Data_Print = ENABLE; } if ((master.getState() == COM_IDLE) && (Data_Print == ENABLE)) { // Get modbus master state : idle if(master.getLastError() == 0 ){ // Get the last error in the protocol processor (0: No error) Object = au16data[0]; Ambient = au16data[1]; Serial.print("Object Temp: "); Serial.print(float(Object)/10, 1); // celsius Serial.print(" Ambient Temp: "); Serial.println(float(Ambient)/10, 1); } else if(master.getLastError() == NO_REPLY) { // Time-out Serial.println("No reply."); } Data_Print = DISABLE; } } void timerISR() { Timer_Flag = 1; } // Timer Interrupt Service Routine void Transfer_Data(uint8_t uid) { if( (uid == 0) &&(uid>200) ) { // ID : 1~200 uid = 1; } // Do not change the parameter values below. telegram.u8id = uid; // slave ID telegram.u8fct = 3; // function code = 03 (Read Holding Registers) telegram.u16RegAdd = 40002; // start address in slave telegram.u16CoilsNo = 2; // number of elements to read telegram.au16reg = au16data; // pointer to a memory array in the Arduino master.query( telegram ); // send query } |
|
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |