int main(int argc, char** argv) { (void) argc; (void) argv; int rc; int listenfd; char smbuffer[10]; // user_context will be pointer to socket scpi_context.user_context = NULL; SCPI_Init(&scpi_context); listenfd = createServer(5025); while (1) { int clifd; struct sockaddr_in cliaddr; socklen_t clilen; clilen = sizeof (cliaddr); clifd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen); if (clifd < 0) continue; printf("Connection established %s\r\n", inet_ntoa(cliaddr.sin_addr)); scpi_context.user_context = &clifd; while (1) { rc = waitServer(clifd); if (rc < 0) { // failed perror(" recv() failed"); break; } if (rc == 0) { // timeout SCPI_Input(&scpi_context, NULL, 0); } if (rc > 0) { // something to read rc = recv(clifd, smbuffer, sizeof (smbuffer), 0); if (rc < 0) { if (errno != EWOULDBLOCK) { perror(" recv() failed"); break; } } else if (rc == 0) { printf("Connection closed\r\n"); break; } else { SCPI_Input(&scpi_context, smbuffer, rc); } } } close(clifd); } return (EXIT_SUCCESS); }
int main(int argc, char** argv) { (void) argc; (void) argv; int result; SCPI_Init(&scpi_context, scpi_commands, &scpi_interface, scpi_units_def, SCPI_IDN1, SCPI_IDN2, SCPI_IDN3, SCPI_IDN4, scpi_input_buffer, SCPI_INPUT_BUFFER_LENGTH, scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE); #define TEST_SCPI_INPUT(cmd) result = SCPI_Input(&scpi_context, cmd, strlen(cmd)) TEST_SCPI_INPUT("*CLS\r\n"); TEST_SCPI_INPUT("*RST\r\n"); TEST_SCPI_INPUT("MEAS:volt:DC? 12,50;*OPC\r\n"); TEST_SCPI_INPUT("*IDN?\r\n"); TEST_SCPI_INPUT("SYST:VERS?"); TEST_SCPI_INPUT("\r\n*ID"); TEST_SCPI_INPUT("N?"); TEST_SCPI_INPUT(""); // emulate command timeout TEST_SCPI_INPUT("*ESE\r\n"); // cause error -109, missing parameter TEST_SCPI_INPUT("*ESE #H20\r\n"); TEST_SCPI_INPUT("*SRE #HFF\r\n"); TEST_SCPI_INPUT("IDN?\r\n"); // cause error -113, undefined header TEST_SCPI_INPUT("SYST:ERR?\r\n"); TEST_SCPI_INPUT("SYST:ERR?\r\n"); TEST_SCPI_INPUT("*STB?\r\n"); TEST_SCPI_INPUT("*ESR?\r\n"); TEST_SCPI_INPUT("*STB?\r\n"); TEST_SCPI_INPUT("meas:volt:dc? 0.01 V, Default\r\n"); TEST_SCPI_INPUT("meas:volt:dc?\r\n"); TEST_SCPI_INPUT("meas:volt:dc? def, 0.00001\r\n"); TEST_SCPI_INPUT("meas:volt:dc? 0.00001\r\n"); TEST_SCPI_INPUT("test:text 'a'\r\n"); TEST_SCPI_INPUT("test:text 'a a'\r\n"); TEST_SCPI_INPUT("test:text 'aa a'\r\n"); TEST_SCPI_INPUT("test:text 'aaa aaaa'\r\n"); //printf("%.*s %s\r\n", 3, "asdadasdasdasdas", "b"); // interactive demo //char smbuffer[10]; //while (1) { // fgets(smbuffer, 10, stdin); // SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); //} return (EXIT_SUCCESS); }
int main(int argc, char** argv) { (void) argc; (void) argv; int rc; user_data_t user_data = { .io_listen = -1, .io = -1, .control_io_listen = -1, .control_io = -1, .fio = NULL, }; // user_context will be pointer to socket scpi_context.user_context = &user_data; SCPI_Init(&scpi_context); user_data.io_listen = createServer(5025); user_data.control_io_listen = createServer(CONTROL_PORT); while(1) { rc = waitServer(&user_data); if (rc < 0) { // failed perror("select failed"); exit(-1); } if (rc == 0) { // timeout SCPI_Input(&scpi_context, NULL, 0); } if ((user_data.io_listen >= 0) && FD_ISSET(user_data.io_listen, &user_data.fds)) { processIoListen(&user_data); } if ((user_data.control_io_listen >= 0) && FD_ISSET(user_data.control_io_listen, &user_data.fds)) { processSrqIoListen(&user_data); } if ((user_data.io >= 0) && FD_ISSET(user_data.io, &user_data.fds)) { processIo(&user_data); } if ((user_data.control_io >= 0) && FD_ISSET(user_data.control_io, &user_data.fds)) { processSrqIo(&user_data); } } return (EXIT_SUCCESS); }
void scpi_task(void* param){ SCPI_Init(&scpi_context, scpi_commands, &scpi_interface, scpi_units_def, SCPI_IDN1, SCPI_IDN2, SCPI_IDN3, SCPI_IDN4, scpi_input_buffer, SCPI_INPUT_BUFFER_LENGTH, scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE ); while(1){ int rec = usb_uart_readline(buff, 50); SCPI_Input(&scpi_context, buff, rec); } }
int main(int argc, char** argv) { (void) argc; (void) argv; int result; SCPI_Init(&scpi_context); #define TEST_SCPI_INPUT(cmd) result = SCPI_Input(&scpi_context, cmd, strlen(cmd)) TEST_SCPI_INPUT("*CLS\r\n"); TEST_SCPI_INPUT("*RST\r\n"); TEST_SCPI_INPUT("MEAS:volt:DC? 12,50;*OPC\r\n"); TEST_SCPI_INPUT("*IDN?\r\n"); TEST_SCPI_INPUT("SYST:VERS?"); TEST_SCPI_INPUT("\r\n*ID"); TEST_SCPI_INPUT("N?"); TEST_SCPI_INPUT(""); // emulate command timeout TEST_SCPI_INPUT("*ESE\r\n"); // cause error -109, missing parameter TEST_SCPI_INPUT("*ESE 0x20\r\n"); TEST_SCPI_INPUT("*SRE 0xFF\r\n"); TEST_SCPI_INPUT("IDN?\r\n"); // cause error -113, undefined header TEST_SCPI_INPUT("SYST:ERR?\r\n"); TEST_SCPI_INPUT("SYST:ERR?\r\n"); TEST_SCPI_INPUT("*STB?\r\n"); TEST_SCPI_INPUT("*ESR?\r\n"); TEST_SCPI_INPUT("*STB?\r\n"); TEST_SCPI_INPUT("meas:volt:dc? 0.01 V, Default\r\n"); TEST_SCPI_INPUT("meas:volt:dc?\r\n"); TEST_SCPI_INPUT("meas:volt:dc? def, 0.00001\r\n"); TEST_SCPI_INPUT("meas:volt:dc? 0.00001\r\n"); //printf("%.*s %s\r\n", 3, "asdadasdasdasdas", "b"); // interactive demo //char smbuffer[10]; //while (1) { // fgets(smbuffer, 10, stdin); // SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); //} return (EXIT_SUCCESS); }
static void scpi_server_thread(void *arg) { int rc; (void)arg; user_data.evtQueue = xQueueCreate(10, sizeof(uint32_t)); // user_context will be pointer to socket scpi_context.user_context = &user_data; SCPI_Init(&scpi_context); user_data.io_listen = createServer(DEVICE_PORT); user_data.control_io_listen = createServer(CONTROL_PORT); while(1) { rc = waitServer(&user_data); if (rc < 0) { // failed iprintf("select failed"); break; } if (rc == 0) { // timeout SCPI_Input(&scpi_context, NULL, 0); } if ((user_data.io_listen != NULL) && (rc == SCPI_MSG_IO_LISTEN)) { processIoListen(&user_data); } if ((user_data.control_io_listen != NULL) && (rc == SCPI_MSG_CONTROL_IO_LISTEN)) { processSrqIoListen(&user_data); } if ((user_data.io != NULL) && (rc == SCPI_MSG_IO)) { processIo(&user_data); } if ((user_data.control_io != NULL) && (rc == SCPI_MSG_CONTROL_IO)) { processSrqIo(&user_data); } } vTaskDelete(NULL); }
int main(int argc, char** argv) { (void) argc; (void) argv; int result; SCPI_Init(&scpi_context); //printf("%.*s %s\r\n", 3, "asdadasdasdasdas", "b"); printf("SCPI Interactive demo\r\n"); char smbuffer[10]; while (1) { fgets(smbuffer, 10, stdin); SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); } return (EXIT_SUCCESS); }
static int init_suite(void) { SCPI_Init(&scpi_context); return 0; }
int main(int argc, char** argv) { (void) argc; (void) argv; int rc; #ifdef __cplusplus user_data_t user_data = { /*.io_listen =*/ -1, /*.io =*/ -1, /*.control_io_listen =*/ -1, /*.control_io =*/ -1, /*.fio =*/ NULL, /*.fds =*/ 0, }; #else user_data_t user_data = { .io_listen = -1, .io = -1, .control_io_listen = -1, .control_io = -1, .fio = NULL, }; #endif /* user_context will be pointer to socket */ SCPI_Init(&scpi_context, scpi_commands, &scpi_interface, scpi_units_def, SCPI_IDN1, SCPI_IDN2, SCPI_IDN3, SCPI_IDN4, scpi_input_buffer, SCPI_INPUT_BUFFER_LENGTH, scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE); scpi_context.user_context = &user_data; user_data.io_listen = createServer(5025); user_data.control_io_listen = createServer(CONTROL_PORT); while (1) { rc = waitServer(&user_data); if (rc < 0) { /* failed */ perror("select failed"); exit(-1); } if (rc == 0) { /* timeout */ SCPI_Input(&scpi_context, NULL, 0); } if ((user_data.io_listen >= 0) && FD_ISSET(user_data.io_listen, &user_data.fds)) { processIoListen(&user_data); } if ((user_data.control_io_listen >= 0) && FD_ISSET(user_data.control_io_listen, &user_data.fds)) { processSrqIoListen(&user_data); } if ((user_data.io >= 0) && FD_ISSET(user_data.io, &user_data.fds)) { processIo(&user_data); } if ((user_data.control_io >= 0) && FD_ISSET(user_data.control_io, &user_data.fds)) { processSrqIo(&user_data); } } return (EXIT_SUCCESS); }