Seems, that example is working. Now I don't understand what's wrong. I try to look the code in more detail. I will let you know.
Aleš
Slave publish callback
Re: Slave publish callback
Hello Marvin,
unfortunately still don't know whats wrong. Can you please tell me? I simplified code, it should be now deeply analyzable.
The output when several message came (received only Bus sleep messages):
OK! Registration of client. success.
OK! Get HWs count success.
OK! Get HW list success.
OK! Connect HW to client success.
OK! Init HW success.
OK! Adding LIN frame success.
OK! Getting connected HWs success.
Connected 1 HWs.
1_HW HANDLE=1
0 0 type=1
OK! Getting received msgs success.
Received 0
Updator finished!
OK! Delete lin channel success.
OK! Delete client success.
ENDED
unfortunately still don't know whats wrong. Can you please tell me? I simplified code, it should be now deeply analyzable.
The output when several message came (received only Bus sleep messages):
OK! Registration of client. success.
OK! Get HWs count success.
OK! Get HW list success.
OK! Connect HW to client success.
OK! Init HW success.
OK! Adding LIN frame success.
OK! Getting connected HWs success.
Connected 1 HWs.
1_HW HANDLE=1
0 0 type=1
OK! Getting received msgs success.
Received 0
Updator finished!
OK! Delete lin channel success.
OK! Delete client success.
ENDED
Code: Select all
int handleRet(DWORD ret, std::string msg) {
if (ret == 0) cout << "OK! " + msg + " success.\n";
else cout << "ERROR! " + msg + " failed (err_code=" + toString(ret) + ").\n";
return ret;
}
std::atomic<int> counter = 1;
std::atomic<bool> quit = false;
std::string getNewData() {
std::string data = toString(counter);
std::string remaining = std::string(4 - data.size(), ' ');
return remaining.append(data);
}
HLINCLIENT cli;
HLINHW hw_pointer;
void simpleUpdator() {
//Check if connected HWs
HLINHW arr[5];
USHORT arr_sz = sizeof(arr) / sizeof(arr[0]);
if (handleRet(LIN_GetClientParam(cli, clpConnectedHardware, arr, arr_sz), "Getting connected HWs") == errOK) {
int hw_count = (int)arr[0];
cout << "Connected " << hw_count << " HWs.\n";
for (int i = 1; i < hw_count + 1; i++) {
cout << i << "_HW HANDLE=" << (int)arr[i] << endl;
}
}
while (quit == false) {
TLINRcvMsg r;
TLINError err = LIN_Read(cli, &r);
if (err == errOK)cout << err << " " << (int)r.FrameId << " type=" << (int)r.Type << endl;
if (err == errOK && r.Type == mstStandard && r.hHw == hw_pointer && r.FrameId == 0x42) {
std::string new_data = stringToCharArrString(getNewData());
BYTE arr[2] = { 0 };
for (size_t i = 0; i < 2; i++)arr[i] = new_data[i];
DWORD ret = LIN_UpdateByteArray(cli, hw_pointer, 0x02, 0, 2, arr);
if (ret != 0) std::cout << "ERROR! Updating field failed, returned=\"" << ret << "\"." << endl;
counter++;
}
Sleep(1);
}
int rec_msgs = 0;
if (handleRet(LIN_GetClientParam(cli, clpReceivedMessages, &rec_msgs, sizeof(rec_msgs)), "Getting received msgs") == errOK) {
cout << "Received " << rec_msgs << endl;
}
cout << "Updator finished!" << endl;
}
int main()
{
LPSTR buff = new CHAR[5]{ 'C','L','I','\n',0 };
handleRet(LIN_RegisterClient(buff, 0, &cli), "Registration of client.");
delete[] buff;
//Connect to channel
HLINHW *li = nullptr;
int list_count = 0;
int ch_count = 0;
TLINError ret = handleRet(LIN_GetAvailableHardware(NULL, 0, &ch_count), "Get HWs count"); //Get connected HWs
if (ret == errOK) {
HLINHW * list = new HLINHW[ch_count];
ret = handleRet(LIN_GetAvailableHardware(list, ch_count * sizeof(HLINHW), &ch_count), "Get HW list");
if (ret == errOK) {
hw_pointer = list[0]; //Channel 1
ret = handleRet(LIN_ConnectClient(cli, hw_pointer), "Connect HW to client");
if (ret == errOK) {
ret = handleRet(LIN_InitializeHardware(cli, hw_pointer, modSlave, 19200), "Init HW");
}
}
delete[] list;
}
//Adding message ID=0x02
std::string doubleHexString = stringToCharArrString(getNewData());
size_t sz = doubleHexString.size();
TLINFrameEntry frame;
frame.FrameId = 0x02;
frame.Length = (BYTE)sz;
frame.Direction = dirPublisher;
for (size_t i = 0; i < sz; i++) frame.InitialData[i] = (int)doubleHexString[i];
frame.ChecksumType = cstEnhanced;
frame.Flags = FRAME_FLAG_RESPONSE_ENABLE;
handleRet(LIN_SetFrameEntry(cli, hw_pointer, &frame), "Adding LIN frame");
//Adding SLAVE thread
std::thread t(simpleUpdator);
getchar();
quit = true;
t.join();
//Delete when SLAVE ends
handleRet(LIN_DisconnectClient(cli, hw_pointer), "Delete lin channel");
handleRet(LIN_RemoveClient(cli), "Delete client");
cout << "ENDED" << endl;
}
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Slave publish callback
Hello Ales,
Because your client-filter is closed.
I don't see the filter being set anywhere, i guess you have forgotten it:
In the example the filter is automatically set to be open,
see the usage of it here:
Set the ClientFilter and see if that resolves it.
Best Regards
Marv
Because your client-filter is closed.
I don't see the filter being set anywhere, i guess you have forgotten it:
In the example the filter is automatically set to be open,
see the usage of it here:
Code: Select all
// Set the client filter with the mask.
m_LastLINErr = m_objPLinApi->SetClientFilter(m_hClient, m_hHw, m_lMask);
Best Regards
Marv
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
Re: Slave publish callback
Ok, thank you Marvin, this was the problem. I didn't know that filter is closed by default (assumed as in CAN, where it is openned by default).
I also saw, that it is possibility to have READ events as in PCAN-Basic API probably getting clpOnReceiveEventHandle param to LIN_GetClientParam function is obtained handle for receive callback, right? What else is it necessary to manage?
Thank you in advance for your answer.
Aleš
I also saw, that it is possibility to have READ events as in PCAN-Basic API probably getting clpOnReceiveEventHandle param to LIN_GetClientParam function is obtained handle for receive callback, right? What else is it necessary to manage?
Thank you in advance for your answer.
Aleš
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Slave publish callback
Hello Ales,
The same approach as in PCANBasic is taken when the ReceiveEvent is used in the PLIN API,
you can check the implementation of it in the PCANBasic examples
as a introduction for it.
Best Regards
Marvin
The same approach as in PCANBasic is taken when the ReceiveEvent is used in the PLIN API,
you can check the implementation of it in the PCANBasic examples
as a introduction for it.
Best Regards
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
Re: Slave publish callback
Ok, now the reading using event is also working. It's all from my side.
Thank you Marvin.
Aleš
Thank you Marvin.
Aleš