Go Down

Topic: New Modbusmq project: Testers needed! (Read 6 times) previous topic - next topic

chris.moe

Hello,

I just tested the Modbusmq and so far it works fine. But I'm struggling a little with all the pointers.

I already managed to send a modbus command from a PC, which sets different bits to true.

But now I want to switch relais, which are connected to a PCF8574. For this I normally use the command:

PCF8574Write(B11111110);

Now I tried to convert the "mb_mapping->tab_coil_status" to a value which I can send with PCF8574Write. But without success. It is too long ago, that I have done somethink with pointers. I tried the following:

for (n=0;n<8;n++)
         {
           PCFStatus1[n] = byte(*(mb_mapping->tab_coil_status + n));
           
           DEBUG_PRINTLN(n);
           delay(200);
         }

This seems to me not very efficient and it is also not working.

Can someone help?

BR,

Chris

marioquark

PCF8574Write(B11111110);

what command is it? a function from you? from a library?

if you have to copy bytes to/from a vector, use the memcpy() standard C function. reference: http://www.cplusplus.com/reference/clibrary/cstring/memcpy/

maybe
memcpy(PCFStatus1, mb_mapping->tab_coil_status, n);

bye
quark

chris.moe

Sounds very promising!

But I still have some problems. I tried the following:

byte PCFStatus1;
     
memcpy(PCFStatus1, mb_mapping.tab_coil_status, 8);
PCF8574Write(PCFStatus1);


Here the function:
//Write data to PCF8574  
void PCF8574Write(byte _data )
{
 Wire.beginTransmission(PCF8574_ADDR);
 Wire.send(_data);
 Wire.endTransmission();
}


But I get the following error:

error: invalid conversion from 'uint8_t' to 'void*'

I do not understand it, why void*?

Any idea?

chris.moe

Hello,

can you give some explanations for the following (is there already some wiki):

If data are correct received, how to use them in the main loop?

I assume there are the following buffers/memorys:
mb_mapping->nb_coil_status
mb_mapping->nb_input_status
mb_mapping->nb_holding_registers
mb_mapping->nb_input_registers

I have also seen some functions like "get_byte_from_bits".

Is there somewhere a more detailed explanation? Maybe in the libmodbus library?

For my problem to write data to the PCF8574 can I use the  "get_byte_from_bits" function? But how exactly?

Thank you for your help!

chris.moe

Got it running with the following code:

int PCFStatus1;

// Gets the byte value from many input/coil status.
PCFStatus1 = get_byte_from_bits(mb_mapping.tab_coil_status, 0, 8);

PCF8574Write(byte(PCFStatus1));

Go Up