Sorry, for the title.
My first email was sent back because it was over the word count (because I
added a screenshot), and I was in a hurry to send a second email, so I
forgot to change the title, so sorry about that!
Original email title: [plc4go][issue]Reads of type bool have different
results

洪锦琳 <[email protected]> 於 2022年4月22日 週五 下午4:16寫道:

> Hello everyone!
> First, thanks to Chris for his reply in my PR, so here I am!
>
> Issue:
> 1 When I read 400006:BOOL[1], it will get the last bit of 400006(2bytes).
> Here is the source code:
>
> github.com/apache/plc4x/plc4go/internal/plc4go/modbus/readwrite/model/DataItem.go
>
> case dataType == ModbusDataType_BOOL && numberOfValues == uint16(1): // BOOL
>    // Reserved Field (Just skip the bytes)
>    if _, _err := readBuffer.ReadUint16("reserved", 15); _err != nil {
>       return nil, errors.Wrap(_err, "Error parsing reserved field")
>    }
>
>    // Simple Field (value)
>    value, _valueErr := readBuffer.ReadBit("value")
>    if _valueErr != nil {
>       return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
>    }
>    readBuffer.CloseContext("DataItem")
>    return values.NewPlcBOOL(value), nil
>
>
> 2 When I read 400006:BOOL[2], I get 400006 and 400007, the first two bits
> of a total of 4 bytes.
> Source code:
>
> github.com/apache/plc4x/plc4go/internal/plc4go/modbus/readwrite/model/DataItem.go
>
> case dataType == ModbusDataType_BOOL: // List
>    // Array Field (value)
>    var value []api.PlcValue
>    for i := 0; i < int(numberOfValues); i++ {
>       _item, _itemErr := readBuffer.ReadBit("value")
>       if _itemErr != nil {
>          return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
>       }
>       value = append(value, values.NewPlcBOOL(_item))
>    }
>    readBuffer.CloseContext("DataItem")
>    return values.NewPlcList(value), nil
>
> I thought it was 400006:BOOL[1] to get the 2nd bit of 400006, but the "[1]"
> match in the regular is "quantity". So, I'm not sure how to fix this
> problem correctly. Let's discuss it here.
> github.com/apache/plc4x/plc4go/internal/plc4go/modbus/FieldHandler.go
>
> generalFixedDigitAddressPattern := 
> `(?P<address>\d{4,5})?(:(?P<datatype>[a-zA-Z_]+))?(\[(?P<quantity>\d+)])?$`
>
>

Reply via email to