Changes in uspace/app/sportdmp/sportdmp.c [f9b2cb4c:74017ce] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sportdmp/sportdmp.c
rf9b2cb4c r74017ce 27 27 */ 28 28 29 #include <char_dev_iface.h>30 29 #include <errno.h> 31 #include <ipc/serial_ctl.h> 30 #include <io/chardev.h> 31 #include <io/serial.h> 32 32 #include <loc.h> 33 33 #include <stdio.h> 34 #include <stdlib.h> 34 35 35 36 #define BUF_SIZE 1 … … 44 45 sysarg_t baud = 9600; 45 46 service_id_t svc_id; 47 chardev_t *chardev; 48 serial_t *serial; 49 size_t nread; 46 50 47 51 int arg = 1; … … 113 117 async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF, 114 118 IPC_FLAG_BLOCKING); 115 if ( !sess) {119 if (sess == NULL) { 116 120 fprintf(stderr, "Failed connecting to service\n"); 121 return 2; 117 122 } 118 123 119 async_exch_t *exch = async_exchange_begin(sess); 120 rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, baud, 121 SERIAL_NO_PARITY, 8, 1); 122 async_exchange_end(exch); 124 rc = chardev_open(sess, &chardev); 125 if (rc != EOK) { 126 fprintf(stderr, "Failed opening character device\n"); 127 return 2; 128 } 123 129 130 rc = serial_open(sess, &serial); 131 if (rc != EOK) { 132 fprintf(stderr, "Failed opening serial port\n"); 133 return 2; 134 } 135 136 rc = serial_set_comm_props(serial, baud, SERIAL_NO_PARITY, 8, 1); 124 137 if (rc != EOK) { 125 138 fprintf(stderr, "Failed setting serial properties\n"); … … 134 147 135 148 while (true) { 136 ssize_t read = char_dev_read(sess, buf, BUF_SIZE); 137 if (read < 0) { 138 fprintf(stderr, "Failed reading from serial device\n"); 149 rc = chardev_read(chardev, buf, BUF_SIZE, &nread); 150 for (size_t i = 0; i < nread; i++) { 151 printf("%02hhx ", buf[i]); 152 } 153 if (rc != EOK) { 154 fprintf(stderr, "\nFailed reading from serial device\n"); 139 155 break; 140 }141 ssize_t i;142 for (i = 0; i < read; i++) {143 printf("%02hhx ", buf[i]);144 156 } 145 157 fflush(stdout); … … 147 159 148 160 free(buf); 161 serial_close(serial); 162 chardev_close(chardev); 163 async_hangup(sess); 149 164 return 0; 150 165 }
Note:
See TracChangeset
for help on using the changeset viewer.