I'm new to the Peak RP1210 API. I'm trying to use Python to call the API DLLs and using the following link as a reference:
However, whenever I try to connect to a client, I get the error code 134 (ERR_INVALID_DEVICE).
Here is my code snippet:
ClientId=NewCon.ClientConnect(2, CANTYPE,0, 0)
I have renamed my Device ID in PEAK-HARDWARE settings in the control panel to 2. (I've also tried a few other IDs, but looks like this is the wrong thing to do).
Can you please help me understand where I'm going wrong?
please note first, that the file you are using for load the API is quate old and is not finished. I nevertheless got the file and gave it a try and I was able to initialize the channel. See picture:
Please make sure you have registered your hardware, and that this is attached to your PC, as specified in the documentation. This is done via PEAK-Hardware apple (control panel, under network section)
Note that the RP1210.py file is always selecting the first RP1210 implementation it finds, so if you have more than one RP1210 implementation in your PC, you may be trying to connect something inexistent.
Thank you for the quick response. Using your suggestion, I fixed my Device Id and it started working. I have a couple of additional questions:
- I am now able to read the CAN data after making a small change in the RP1210 file. However, as I read it, looks like I'm reading the messages from the start of day, instead of just listening to the latest message. E.g., I sent a 100 messages with 1 ID, sent another 100 with another ID, and then I stop sending any messages. When I try to read the messages now, I get the first 100, then I get the next 100 and then I start getting empty buffer. I tried to flush the Rx/Tx queue after every read, but to no effect. Here is my code:
Code: Select all
[readMessage,messageLen]=NewCon.ReadMessage(ClientId, 1) output=NewCon.SendCommand(ClientId, RPCMD_FLUSH_TX_RX_BUFFERS, None, 0)[/i] The output value is NO_ERRORS.
- Can you please point me to any newer files for the RP1210 implementation? I started using these as a guide, and edited them based on the RP1210 documentation.
Reason: Code formatting for better reading
I was able to resolve the issue by using the Set Message Receive Command.
However, I would like to understand why the Flush Tx/Rx buffer command didn't work the same way as the Set Message Receive Command. Just going by the documentation, both are being used to clear the queue.
I think, you need to make a review about CAN. Remember the reception queue is a FIFO, so first in first out. If you has old messages that haven't been read yet, then you get first those.
Please note, we don't provide python headers / wrappers for our RP1210 API. Only a C++ header is part of our RP1210 package. You can try to port this from C++ to Python.
Note that official RP1210 documentation can be acquired by TMC. PEAK doesn't provide this.