|
|
@@ -237,8 +237,14 @@ static int mb_deinit(cascade_handle_t *cas)
|
|
|
}
|
|
|
static int _mb_scan(cascade_handle_t *cas, int addr)
|
|
|
{
|
|
|
+ int r;
|
|
|
uint16_t tmp;
|
|
|
- return g_modbus_read_x_reg(&cas->m, addr, CASCADE_REG_SCAN, 1, &tmp);
|
|
|
+
|
|
|
+ //g_modbus_set_timeout(&cas->m, 100);
|
|
|
+ r = g_modbus_read_x_reg(&cas->m, addr, CASCADE_REG_SCAN, 1, &tmp);
|
|
|
+ //g_modbus_set_timeout(&cas->m, 1500);
|
|
|
+
|
|
|
+ return r;
|
|
|
}
|
|
|
static int _mb_read(cascade_handle_t *cas, int addr, uint16_t reg, uint16_t *data, int cnt)
|
|
|
{
|
|
|
@@ -481,6 +487,9 @@ static int mb_receive(cascade_handle_t *cas)
|
|
|
}
|
|
|
sendlen = 0;
|
|
|
}
|
|
|
+ else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
switch(cmd->cmd) {
|
|
|
case CASCADE_CMD_OPEN:
|
|
|
@@ -1026,7 +1035,7 @@ static void* cascade_thread(void *arg)
|
|
|
int r;
|
|
|
thread_handle_t *h=(thread_handle_t*)arg;
|
|
|
cascade_handle_t *cas=(cascade_handle_t*)h->arg;
|
|
|
- ModbusInfo_t *info=get_mb();
|
|
|
+ ModbusInfo_t *info=&cas->mInfo;
|
|
|
|
|
|
LOGD("__ cascade %s\n", info->product_modbus_type?"slave":"master");
|
|
|
while(h->quit==0) {
|
|
|
@@ -1046,9 +1055,10 @@ static void* scan_thread(void *arg)
|
|
|
int r;
|
|
|
thread_handle_t *h=(thread_handle_t*)arg;
|
|
|
cascade_handle_t *cas=(cascade_handle_t*)h->arg;
|
|
|
+ ModbusInfo_t *info=&cas->mInfo;
|
|
|
|
|
|
while(h->quit==0) {
|
|
|
- if(get_mb()->product_modbus_type==0) { //master
|
|
|
+ if(info->product_modbus_type==0) { //master
|
|
|
r = master_scan(cas);
|
|
|
}
|
|
|
sleep(1);
|
|
|
@@ -1121,6 +1131,7 @@ static int set_modbus(cascade_handle_t *cas, ModbusInfo_t *info)
|
|
|
mb_deinit(cas);
|
|
|
}
|
|
|
cas->inited = 0;
|
|
|
+ cas->mInfo = *info;
|
|
|
//LOGD("master init modbus: port: %s, type: %d, baud: %d\n", CASCADE_MODBUS_PORT, info->product_modbus_type, info->product_modbus_baud);
|
|
|
|
|
|
r = mb_init(cas, CASCADE_MODBUS_PORT, info->product_modbus_type,
|