Page 1 of 1

Problem with RP1210_ClientConnect

Posted: Thu 12. May 2016, 11:14
by Alex Stepanov
Hello!

I have a problem when communicating with PCAN-USB adapter which is connected to
J1939 simulator. The device was set to use RP1210 in PCAN Nets utility and I can
view data from it using PcanView.

I am writing a Qt-based program. I successfuly loaded PCANRP32.dll and exported
API functions from this library. A call to RP1210_ReadVersion was succesful. But
when I call RP1210_ClientConnect it returns error 142.

What's wrong with my program?

The program text is below:

Code: Select all

#include <QApplication>
#include <QtCore>
#include <windows.h>
#include <iostream>
#include "PCAN_RP1210.h"


typedef short (__stdcall *tfn_RP1210_ClientConnect) ( HWND, short, char *, long, long, short );
typedef short (__stdcall *tfn_RP1210_ClientDisconnect) ( short );
typedef short (__stdcall *tfn_RP1210_SendMessage) ( short, char*, short, short, short );
typedef short (__stdcall *tfn_RP1210_ReadMessage) ( short, char*, short, short );
typedef short (__stdcall *tfn_RP1210_SendCommand) ( short, short, char*, short );
typedef void  (__stdcall *tfn_RP1210_ReadVersion) ( char*, char*, char*, char* );
typedef short (__stdcall *tfn_RP1210_GetErrorMsg) ( short, char* );
typedef short (__stdcall *tfn_RP1210_GetHardwareStatus) ( short, char*, short, short );


typedef struct 
{
  tfn_RP1210_ClientConnect      RP1210_ClientConnect;
  tfn_RP1210_ClientDisconnect   RP1210_ClientDisconnect;
  tfn_RP1210_SendMessage        RP1210_SendMessage;
  tfn_RP1210_ReadMessage        RP1210_ReadMessage;
  tfn_RP1210_SendCommand        RP1210_SendCommand;
  tfn_RP1210_ReadVersion        RP1210_ReadVersion;
  tfn_RP1210_GetErrorMsg        RP1210_GetErrorMsg;
  tfn_RP1210_GetHardwareStatus  RP1210_GetHardwareStatus;
}
device_api_t;

device_api_t api;


QString getErrorDescription( short errorCode )
{
  QString res;
  char dscr[ 2048 ];

  short code = api.RP1210_GetErrorMsg( errorCode, dscr );
  if( code == NO_ERRORS )
    res = QString( "%1 (%2)" ).arg( QString::fromLatin1( dscr ) ).arg( errorCode );
  else
    std::cout << "Error translation failed:" << code << std::endl;

  return res;
}




int main( int argc, char *argv[] )
{
  QLibrary l( "PCANRP32.dll" );

  api.RP1210_ClientConnect = (tfn_RP1210_ClientConnect)l.resolve( "RP1210_ClientConnect" );
  api.RP1210_ClientDisconnect = (tfn_RP1210_ClientDisconnect)l.resolve( "RP1210_ClientDisconnect" );
  api.RP1210_SendMessage = (tfn_RP1210_SendMessage)l.resolve( "RP1210_SendMessage" );
  api.RP1210_ReadMessage = (tfn_RP1210_ReadMessage)l.resolve( "RP1210_ReadMessage" );
  api.RP1210_SendCommand = (tfn_RP1210_SendCommand)l.resolve( "RP1210_SendCommand" );
  api.RP1210_ReadVersion = (tfn_RP1210_ReadVersion)l.resolve( "RP1210_ReadVersion" );
  api.RP1210_GetErrorMsg = (tfn_RP1210_GetErrorMsg)l.resolve( "RP1210_GetErrorMsg" );
  api.RP1210_GetHardwareStatus = (tfn_RP1210_GetHardwareStatus)l.resolve( "RP1210_GetHardwareStatus" );

  if( !( api.RP1210_ClientConnect
         && api.RP1210_ClientDisconnect
         && api.RP1210_SendMessage
         && api.RP1210_ReadMessage
         && api.RP1210_SendCommand
         && api.RP1210_ReadVersion
         && api.RP1210_GetErrorMsg
         && api.RP1210_GetHardwareStatus )
  )
  {
    std::cout << "Api not resolved" << std::endl;
    return 1;
  }

  char dllMajor[50];
  char dllMinor[50];
  char apiMajor[50];
  char apiMinor[50];

  api.RP1210_ReadVersion( dllMajor, dllMinor, apiMajor, apiMinor );
  std::cout << "DLL version: " << dllMajor << "." << dllMinor << std::endl;
  std::cout << "API version: " << apiMajor << "." << apiMinor << std::endl;

  short cid = api.RP1210_ClientConnect( 0, PCAN_USB, J1939_STRING, 0, 0, 0 );
  if( cid < 128 )
  {
    std::cout << "Connect succesful!" << std::endl;
  }
  else
  {
    std::cout << "Connect error:" << qPrintable( getErrorDescription( cid ) ) << std::endl;
    return 1;
  }

  return 0;
}

Re: Problem with RP1210_ClientConnect

Posted: Thu 12. May 2016, 12:58
by K.Wagner
Hello,

please check that the net you want to use belongs to the PCAN-USB that is connected, and that the RP1210-Channel configured for that net is "0".

Also you can try to disconnect the Net from the other application and try your application first.

Re: Problem with RP1210_ClientConnect

Posted: Thu 12. May 2016, 13:09
by Alex Stepanov
Hello!

Setting channel to "0" in PCAN Nets config helped (initialy it was set to "1")!

Thanks a lot!

Re: Problem with RP1210_ClientConnect

Posted: Wed 1. Jun 2016, 14:52
by Alex Stepanov
Hello,

Now I have problem with reading messages using J1939 protocol.

I called a RP1210_ClientConnect function with nIsAppPacketizingIncomingMsgs parameter set to 0.

When I read a message using RP1210_ReadMessage I receive only an RTS frame with correct source and destination addresses. This means I should answer this frame myself? But what meaning in setting nIsAppPacketizingIncomingMsgs to 0 when connecting? Should the device handle long messages itself?

When I send a large amount of data (1785 bytes) using RP1210_SendMessage this data was sent correctly and the other side successfuly received it.

Re: Problem with RP1210_ClientConnect

Posted: Fri 3. Jun 2016, 10:13
by PEAK-Support
We working on a answer, but the colleauges who take care of the RP1210 implementations are all on a training - we will come back to answer your request soon as possible.

Re: Problem with RP1210_ClientConnect

Posted: Mon 6. Jun 2016, 10:56
by K.Wagner
Hello,

please be sure to have claimed a J1939 address by using the RP1210_SendCommand function. RTS/CTS sessions (peer-to-peer) need a valid protected source (claimed address). Without a claimed address the PCAN-RP1210 will not handshake for large messages reception.