Tuesday, May 9, 2017

tahap selanjutnya uji modbus

jika sudah selesai upload dan merangkai silahkan di uji

download dulu software modscan

tancapkan usb to rs485 to pc or laptop

run modscan

connection -> connect

pilih connect using : sesuaikan port usb nancap dimana

baudrate 9600
worklenghr 8
parity none
stopbit 1
klik ok

lenght ganti 3
coil status ganti holding register


jika valid response sudah ada angkanya berarti anda sudah berhasil

rangkaian dari upload file modbus


upload sketch modbus RTU RS485

/*
Author  : Fuad Hasan
Created : 9 Mei  2017
        
*/

#include <ModbusSlave.h>

ModbusSlave mbs;

/*register addres modbus*/
enum { 
        MB_40000,            
        MB_40001,          
        MB_40002,       
      
        MB_REGS     //jumlah addres yang dipolling sebanyak 3   
};

int regs[MB_REGS];
unsigned long wdog = 0;         /* watchdog */
unsigned long tprev = 0;         /* previous time*/

void setup()
{
       
/* the Modbus slave configuration parameters */

  const unsigned char SLAVE = 10;      /* slaveId */
  const long BAUD = 9600;             /* baud rate */
  const char PARITY = 'n';             /* n=none; e=even; o=odd */
  const char TXENPIN = 2;              /* output driver enable pin */

  /* Second step MBS: configure */
  mbs.configure(SLAVE, BAUD, PARITY, TXENPIN);
  mbs.update(regs, MB_REGS);
  pinMode(13, OUTPUT);// digital output
  pinMode(12, INPUT);//digital input
 
}
void loop()
{
        /* Third and las step MBS: update in loop*/
        if(mbs.update(regs, MB_REGS))
                wdog = millis();
        if ((millis() - wdog) > 1500); 


 //   DIGITAL INPUT
   regs[MB_40000] = digitalRead(12);
  
  
//   DIGITAL OUTPUT  
   digitalWrite(13, regs[MB_40001]);
   
    //ANALOG INPUT
    regs[MB_40002] = analogRead(A0);
   
        
            
  }
       
  

ruwet with sim800l v2

#include <gprs.h> #include <SoftwareSerial.h> #define TIMEOUT    5000 #define LED_PIN    13 #define ON HIGH #define OFF LOW ...