Closed MoizesFerreira closed 7 years ago
This code was incorrect to start with.
Presumably you are allocating lista_portas
somewhere as:
struct sp_port **lista_portas;
When you take sizeof(lista_portas)
, you're just taking the size of that pointer. That's a constant determined by the compiler at compile time, not something that changes depending on the result of your sp_list_ports()
call.
So this line:
numero_portas = sizeof(lista_portas)/sizeof(struct sp_port *);
will always set numero_portas = 1
, because all pointers have the same size.
What sp_list_ports(&lista_portas)
does is to update lista_portas to point to a NULL-terminated array of struct sp_port
pointers. If you want to get the number of ports, you need to iterate over that array until you get to the NULL. You can do that in one line like this:
for (int numero_portas = 0; lista_portas[numero_portas] != NULL; numero_portas++);
This may not be the only problem, but I suggest you fix it before debugging further.
You're the first person I know of to try libserialport on Windows 10, so there might be other things that need fixing. That said, libserialport follows the pre-W10 Windows API very strictly and the new OS should be fully backwards compatible.
I'm trying to read and write data from an Arduino microcontroller. My computer runs Windows 10. The code below worked on Windows 7, but no more after the upgrade. As there are many examples of libserialport, I wonder if there are any errors in my code:
uint8_t Arduino :: LocalizarSimulador(){ int vid = 0, pid = 0;
... }
uint8_t Arduino :: Conectar(){ if (uint8_t retorno = LocalizarSimulador() != SIMULATOR_FOUND){ return retorno; }
... }
Although I can locate the Arduino and connect to it, the following code always returns an error:
int retorno = sp_nonblocking_read(porta, &buffer_entrada[posicao_buffer], sizeof(AquisicaoEquipamentos_t) - posicao_buffer); /* always return -1 (SP_ERR_ARG). I'm sure there is no NULL pointer */
I tried to modify the code, using sp_blocking_read with the same results. Is there any error in my code? Thanks