Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign Modbus slave ID by hardware #37

Open
GoogleCodeExporter opened this issue Oct 13, 2015 · 2 comments
Open

Assign Modbus slave ID by hardware #37

GoogleCodeExporter opened this issue Oct 13, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link
Contributor

Dear all,

Here i am attaching working code & modified code for simple modbus.The 
difference between working code & alter code is assign method of slave ID. If i 
wanted to config the slave ID i need to do individually .i checked the code 
work with change in ID no in working code. but it difficult to keep track if 
there are 255 devices .

For that i used 8:1 multiplexer & 8pin dip . Depend on status output 
multiplexer i calculated the device ID. The function ID_Check() determine 
device ID>.when i debug initially via serial monitor the code seems device ID 
updating as expected. but when i enable slave , i get error msg didnt receive 
any response from slave. if i assign device id directly code start working. 

Let me know how to assign device ID here

Working code:


#include <ModbusRtu.h>
#define Device_ID 1
uint16_t au16data[16] = {
  3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

Modbus slave(Device_ID,10,0); // this is slave @1 and RS-232 or USB-FTDI

void setup() {
  slave.begin( 19200 ); // baud-rate at 19200
}

void loop() {
  slave.poll( au16data, 16 );
}

Now alter code as below


#include <ModbusRtu.h>
int SO_enable=5;
int S1_enable=4;
int S2_enable=3;
int Status_Out[8];
int Output_Read=2;
static int Device_ID;
unsigned long int curr_time;
Modbus *slave=0;


int array[8][3]={
  {    
    0,0,0      }
  ,
  {    
    0,0,1      }
  ,
  {    
    0,1,0      }
  ,  
  {    
    0,1,1      }
  ,
  {    
    1,0,0      }
  ,
  {    
    1,0,1      }
  ,
  {    
    1,1,0      }
  ,
  {    
    1,1,1      }


};

unsigned int ID_Check() {
  unsigned   int ID_value;
  for(int row=0;row<8;row++)
  {
    digitalWrite(SO_enable,array[row][0]);
    digitalWrite(S1_enable,array[row][1]);
    digitalWrite(S2_enable,array[row][2]);
    Status_Out[row]=digitalRead(Output_Read);

  }

  ID_value = 1 * Status_Out[0] + 2 * Status_Out[1] + 4 * Status_Out[2] + 8 * Status_Out[3] + 16 * Status_Out[4] + 32 * Status_Out[5] + 64 * Status_Out[6] + 128 * Status_Out[7];
  return(ID_value);
}


uint16_t au16data[16] = 
{
  3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1
};



void setup() {
  //  Serial.begin(9600);
  pinMode(SO_enable, OUTPUT) ;// pin can enable/disable using digital IO 7 of arduino
  pinMode(S1_enable, OUTPUT) ;// pin can enable/disable using digital IO 6 of arduino
  pinMode(S2_enable, OUTPUT) ;// pin can enable/disable using digital IO 5 of arduino
  pinMode(Output_Read,INPUT);
  unsigned int Device_ID=ID_Check();
  slave=new Modbus(Device_ID,0,0);
  slave->begin(9600);

}

void loop() {
// Modbus_setup();
  delay(1000);
  for(int i = 0; i<8; i++)
  {
    au16data[i];
  }
}











What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 10 Feb 2015 at 8:35

@GoogleCodeExporter
Copy link
Contributor Author

If you altered the library I cant help you with out the source code ;-)

Original comment by [email protected] on 12 Feb 2015 at 4:52

  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Contributor Author

I didn't change any thing.I have all defined in Modbus RTU function.

Original comment by [email protected] on 12 Feb 2015 at 5:35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant