Hi,
I have an IoT device running automated power tests. It communicates with my power supply and turns it’s own power off and back on after a second if the boot was successful. Logic is connected and cpaturing I2C traffic in a cyclic buffer.
If I detect a fault situation on the device, my code (running on the device) will not power cycle but instead connect to Logic (started with “logic --automation --automationHost 0.0.0.0”) and send the “STOP_CAPTURE” command.
The connection to Logic (running on my PC at 192.168.1.100) is successful, but the STOP_CAPTURE command does not stop the capture (and I’m not getting any response).
My code is as follows:
Log(ZONE_INFO, L"Connecting to Saleae Logic...\r\n");
for (DWORD dwRetry = 0; dwRetry < LOGIC_CONNECT_RETRIES; dwRetry++)
{
if (Connect(LOGIC_IP, LOGIC_PORT))
break;
Wrn(L"Could not connect to Saleae Logic, retrying in %u ms... [%u]\r\n", LOGIC_CONNECT_RETRY_DELAY, dwRetry + 1);
Sleep(LOGIC_CONNECT_RETRY_DELAY);
}
if (LOGIC_CONNECT_RETRIES == dwRetry)
{
dwError = GetLastError();
Err(L"Could not connect to Saleae Logic!\r\n");
break;
}
if (!SendCommand(LOGIC_COMMAND))
{
dwError = GetLastError();
Err(L"Could not send %S command to Saleae Logic, error %d\r\n", LOGIC_COMMAND, dwError);
}
char szResponse[100];
if (!ReadResponse(szResponse, sizeof(szResponse)))
{
dwError = GetLastError();
Err(L"Could not read response from Saleae Logic, error %d\r\n", dwError);
}
LPCSTR pszPtr = strchr(szResponse, 'A');
if (!pszPtr || (0 != strcmp(pszPtr, "ACK")))
{
dwError = GetLastError();
Err(L"No ACK response from Saleae Logic, error %d\r\n", dwError);
}
The connection succeeds, sending the command succeeds, the response is an empty string.
What am I missing?
SendCommand:
// Send a command to the TCP Server
BOOL SendCommand(LPCSTR szCmd)
{
FUNC_ENTRY(L"szCmd=%S", szCmd);
BOOL bRet = FALSE;
// We use a loop for easy break out and error handling
for (;;)
{ // Sanity checks
if (!IsConnected())
{
Err(L"Not connected\r\n");
break;
}
if (!szCmd)
{
Err(L"Invalid parameter\r\n");
break;
}
// Send the entire packet in one go
if (SOCKET_ERROR == send(s_sck, szCmd, strlen(szCmd) + 1, 0))
{
Err(L"Error %d sending data over socket\r\n", WSAGetLastError());
break;
}
bRet = TRUE;
// Always break out of the loop
break;
}
FUNC_EXIT(L"%s", bRet ? L"TRUE" : L"FALSE");
return bRet;
}
ReadResponse:
// Read a response from the TCP Server
BOOL ReadResponse(LPSTR pszResponse, size_t stCount)
{
FUNC_ENTRY(L"pszResponse=%S", pszResponse);
BOOL bRet = FALSE;
// We use a loop for easy break out and error handling
for (;;)
{ // Sanity checks
if (!IsConnected())
{
Err(L"Not connected\r\n");
break;
}
if (!pszResponse || !stCount)
{
Err(L"Invalid parameter\r\n");
break;
}
// Read the entire response in one go
if (SOCKET_ERROR == recv(s_sck, pszResponse, stCount, 0))
{
Err(L"Error %d receiving data over socket\r\n", WSAGetLastError());
break;
}
bRet = TRUE;
// Always break out of the loop
break;
}
FUNC_EXIT(L"%s", bRet ? L"TRUE" : L"FALSE");
return bRet;
}