Jump to content

CAN V2 Bricklet go API Binding: WriteFrame sends incorrect data


Recommended Posts

The go API Binding Version 2.0.12 for CAN V2 Bricklet does not work correctly.

I set the module in Transceiver Loopback Mode.

I send a frame with 8 bytes.

Only the first byte is correct, all others are zero.

Sending a frame with less than 8 bytes results in all bytes being zero

can.SetTransceiverConfiguration(uint32(*bitrate), 800, can_v2_bricklet.TransceiverModeLoopback)
can.WriteFrame(can_v2_bricklet.FrameTypeStandardData, 1742, []uint8{42, 23, 17, 42, 23, 17, 42, 23})

On bus --> 2A 00 00 00 00 00 00 00

Has anyone seen a similar problem?

Link to comment
Share on other sites

Sure,

As per https://www.tinkerforge.com/en/doc/Software/API_Bindings_Go.html#from-source and https://go.dev/doc/gopath_code

there should be a directory named "go" in your home directory (so /home/[your_username], C:\Users\[your_username], or similar). In the zip there is a github.com directory. Put this directory into .../go/src/ so that afterwards you have .../go/src/github.com/Tinkerforge/...

If is already a github.com directory in ../go/src (as you've already got an older version of the bindings installed), you can either remove .../go/src/github.com/Tinkerforge/ or overwrite all files when extracting the zip.

Link to comment
Share on other sites

Thanks, I did as you told me. but I am using go.mod.

When I try to build, I get

main.go:10:2: no required module provides package github.com/Tinkerforge/go-api-bindings/can_v2_bricklet; to add it:
        go get github.com/Tinkerforge/go-api-bindings/can_v2_bricklet

What do I have to write in go.mod to tell go to use the package in GOPATH?

 

Link to comment
Share on other sites

Okay, the Go bindings are not yet adapted to go.mod, but you can do that yourself for now.

Unpack the ZIP file to somwhere, doesn't matter where. Run "go mod init github.com/Tinkerforge/go-api-bindings" in the github.com/Tinkerforge/go-api-bindings directory from the unpacked ZIP file.

To your go.mod file add a line like this, to tell Go where to find the module locally:

replace github.com/Tinkerforge/go-api-bindings => /path/to/your/github.com/Tinkerforge/go-api-bindings
Link to comment
Share on other sites

Thanks. It works. And the bug seems to be fixed.

When will it be on github?

Another question: I can only send approx 100 CAN frames/s (same with go and python). Is this a limitation of the bricklet?

Link to comment
Share on other sites

Go bindings 2.0.13 published. Those will just work now, without modification. You can also remove the replace line from your go.mod file again.

100 FPS is too low, you should be able to send 500 FPS and receive 1000 FPS.

This example sends about 500 FPS with two CAN Bricklet 2.0 connected to form a CAN bus:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID1 = "Er1" # Change XYZ to the UID of your CAN Bricklet 2.0
UID2 = "Gj8" # Change XYZ to the UID of your CAN Bricklet 2.0

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_can_v2 import BrickletCANV2

# Callback function for frame read callback
def cb_frame_read(frame_type, identifier, data):
    if frame_type == BrickletCANV2.FRAME_TYPE_STANDARD_DATA:
        print("Frame Type: Standard Data")
    elif frame_type == BrickletCANV2.FRAME_TYPE_STANDARD_REMOTE:
        print("Frame Type: Standard Remote")
    elif frame_type == BrickletCANV2.FRAME_TYPE_EXTENDED_DATA:
        print("Frame Type: Extended Data")
    elif frame_type == BrickletCANV2.FRAME_TYPE_EXTENDED_REMOTE:
        print("Frame Type: Extended Remote")

    print("Identifier: " + str(identifier))
    print("Data (Length: " + str(len(data)) + "): " + ", ".join(map(str, data[:min(len(data), 8)])))
    print("")

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    can1 = BrickletCANV2(UID1, ipcon) # Create device object
    can2 = BrickletCANV2(UID2, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Configure transceiver for loopback mode
    can1.set_transceiver_configuration(1000000, 625, can1.TRANSCEIVER_MODE_NORMAL)
    can2.set_transceiver_configuration(1000000, 625, can2.TRANSCEIVER_MODE_NORMAL)

    # Register frame read callback to function cb_frame_read
    #can2.register_callback(can2.CALLBACK_FRAME_READ, cb_frame_read)

    # Enable frame read callback
    can2.set_frame_read_callback_configuration(True)

    # Write standard data frame with identifier 1742 and 3 bytes of data
    import time
    c = 0
    s = time.monotonic()
    f = 0
    
    while True:
        time.sleep(0.0001)

        if not can1.write_frame(can1.FRAME_TYPE_STANDARD_DATA, 1742, [42, 23, 17]):
            f += 1
            
            if f % 100 == 0:
                print('fails', f)
            
            continue

        c += 1

        if c % 100 == 0:
            n = time.monotonic()
            d = n - s 
            #print('c', c, d, d / c, c / d)
            print('fps', c / d)

    input("Press key to exit\n") # Use raw_input() in Python 2

    can2.set_frame_read_callback_configuration(False)

    ipcon.disconnect()

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...