I'm working with a RedPitaya Development Board, which runs Linux. The application requires communication between a socket server running on the board and a remote client running on Matlab. The C server code that I'm using has probed to work with a Python client, so, I'm trying to recreate that Python client with my own modifications to make it fit with my needs.
I'm passing four numbers as data, but only one is making it to the server.
The Systems works with numbers in uint32 format, every byte has different meaning to the system, I've tried change the data type that the Matlab clients send, change if the operation is sync or async type, send it as string, but just the first data sent appears to get response form the server
This is the part of the C server that receives the data:
if(bind(sock_server, (struct sockaddr *)&addr, sizeof(addr)) < 0)
{
perror("bind");
return EXIT_FAILURE;
}
listen(sock_server, 1024);
printf("Listening on port serverPort ...\n");
while(1)
{
if((sock_client = accept(sock_server, NULL, NULL)) < 0)
{
perror("accept");
return EXIT_FAILURE;
}
while(1) //MSG_WAITALL
{
//sleep(1);
rx = recv(sock_client, (char *)&command, 4, MSG_DONTWAIT);
if (rx == 0) {
break;
measuring = 0;
}
if(rx > 0) {
value = command & 0xfffffff;
switch(command >> 28)
{
case 1: /* Trigger Delay - Timing */
timing = command & 0xff;
printf("timing: %zu \n",timing);
break;
case 2: /* NSAMPLES */
if ((command & 0xff) < 10)
nsamples = (command & 0xff);
else
nsamples = 10;
printf("samples: %zu \n",nsamples);
break;
case 3: /* NAVERAGES */
naverages = command & 0xff;
printf("averages: %zu \n",naverages);
break;
case 0: /* fire */
// set trigger and NSAMPLES set NAVERAGES and stop measurement
*((int32_t *)(cfg + 0)) = (STOP) + (timing<<8) + (nsamples<<16) + (naverages<<24);
//sleep(0.1); // wait 0.1 second
time_begin = clock();
// start measurement
*((int32_t *)(cfg + 0)) ^= 1;
measuring = 1;
break;
}
}
The Python client sends data in this way:
if self.idle: return
self.socket.write(struct.pack('<I', 1<<28 | self.cbTrigger.currentIndex()))
self.socket.write(struct.pack('<I', 2<<28 | self.cbNOS.currentIndex()))
self.socket.write(struct.pack('<I', 3<<28 | self.cbNOA.currentIndex()))
The matlab client is rather simple:
t=tcpip('RedPitayaIP',serverPort,'NetworkRole','client')
pause(1);
fopen(t);
And I'm sending data in this way:
fwrite(t,variable_trigger_or,'uint32')
fwrite(t,variable_samples_or,'uint32')
fwrite(t,variable_average_or,'uint32')
The Python client send data and the client give this response:
Litening to port serverPort
timing: 16
samples: 10
averages: 0
And the Matlab client only gets this
Listening to port serverPort
timing: 16
So, I'll be glad if anyone could help me understand what's happening, or if I'm missing something, I'm not new at this but also not close to be an expert