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

I get a pack not defined error when using i2c API #15

Open
jkroso opened this issue May 9, 2021 · 4 comments
Open

I get a pack not defined error when using i2c API #15

jkroso opened this issue May 9, 2021 · 4 comments

Comments

@jkroso
Copy link

jkroso commented May 9, 2021

No description provided.

@AIxer
Copy link

AIxer commented Sep 11, 2021

me too

@abassign
Copy link

Me too I2c (but I also see Wave) gives the same problem. Observing the code, the pack () function seems to act as a serializer that brings the character "I" and the flag 0 to become a vector which is then scanned by a Pi.jl function
Unfortunately I can not understand anything else, it would be useful to be able to solve the problem as JUlia lends itself very well to build RT systems in Raspberry environments.

@abassign
Copy link

abassign commented Feb 18, 2022

The only library worthy of being used to interface to the Raspberry I / O does not work for the I2C protocol, fundamental protocol, it causes the error, right in the opening of I2C, when I try to open I2C I get this message:

i2 = PiGPIO.i2c_open (pi, 1,0x1e)
ERROR: UndefVarError: pack not defined

I noticed that the program converts the corresponding python code reported in this link.

the corresponding python code can be found here:

def i2c_open(self, i2c_bus, i2c_address, i2c_flags=0):
      """
      Returns a handle (>=0) for the device at the I2C bus address.

          i2c_bus:= >=0.
      i2c_address:= 0-0x7F.
        i2c_flags:= 0, no flags are currently defined.

      Normally you would only use the [*i2c_**] functions if
      you are or will be connecting to the Pi over a network.  If
      you will always run on the local Pi use the standard SMBus
      module instead.

      Physically buses 0 and 1 are available on the Pi.  Higher
      numbered buses will be available if a kernel supported bus
      multiplexor is being used.

      For the SMBus commands the low level transactions are shown
      at the end of the function description.  The following
      abbreviations are used:

      . .
      S     (1 bit) : Start bit
      P     (1 bit) : Stop bit
      Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
      A, NA (1 bit) : Accept and not accept bit. 
      Addr  (7 bits): I2C 7 bit address.
      reg   (8 bits): Command byte, which often selects a register.
      Data  (8 bits): A data byte.
      Count (8 bits): A byte defining the length of a block operation.

      [..]: Data sent by the device.
      . .

      ...
      h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1
      ...
      """
      # I p1 i2c_bus
      # I p2 i2c_addr
      # I p3 4
      ## extension ##
      # I i2c_flags
      extents = [struct.pack("I", i2c_flags)]
      return _u2i(_pigpio_command_ext(
         self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents))

i2c_flags = 0
extents = [struct.pack("I", i2c_flags)]

convert in:
[b'\x00\x00\x00\x00']

The struct-pack is described in this link

function i2c_open(self::Pi, i2c_bus, i2c_address, i2c_flags=0)
    # I p1 i2c_bus
    # I p2 i2c_addr
    # I p3 4
    ## extension ##
    # I i2c_flags
    extents = [pack("I", i2c_flags)]
    return _u2i(_pigpio_command_ext(
        self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents))
end

In python is:

extents = [struct.pack("I", i2c_flags)]
      return _u2i(_pigpio_command_ext(
         self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents))

In julia In Julia there is an equivalent function a struct.pack(,Value)
the name is MsgPack

Now this is the problem, I would be delighted if the authors resolved it to allow the use of the I2C protocol.

@Alexander-Barth
Copy link
Contributor

In the branch i2c, I have replaced the calls to pack("I",...).

master...i2c

Maybe somebody wants to test it. If it does not work, knowing the python message send to the daemon, by adding a
print(ext) to the python code would be tremendously helpful :-)

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

No branches or pull requests

4 participants